From: Fred on

"Giovanni Dicanio" <giovanni.dicanio(a)invalid.it> wrote in message
news:OwfSOleIIHA.5400(a)TK2MSFTNGP04.phx.gbl...
>
> "Fred" <not(a)here.com> ha scritto nel messaggio
> news:dbOdnYf-88rYxq_anZ2dnUVZ8qaqnZ2d(a)pipex.net...
>
>

>
>> Regarding headers. How much overhead would adding ATL add?
>
> It is about zero :)
>
> In fact, ATL are just lean templates. Sometimes, you may see them as a
> kind of advanced and robust evolution of C preprocessor macros...
>
> I would suggest you to really use ATL in your context. At least, the
> robust smart pointers for COM interfaces like CComPtr and CComQIPtr.
> (Note that you can also use these ATL helper classes also in MFC.)
>

I had a quick look last night. I added
#include <atlbase.h>

to stdafx.h and got several "ambiguous" errors

eg

..\SP1.cpp(4450) : error C2668: 'CreatePen' : ambiguous call to overloaded
function

C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Smartphone
SDK\include\ARMV4I\wingdi.h(591): could be 'HPEN
CreatePen(int,int,COLORREF)'

C:\Program Files\Microsoft Visual Studio
8\VC\ce\atlmfc\include\atlosapice.h(750): or 'HPEN
ATL::CreatePen(int,int,COLORREF)'


so I need to sort that out.



>> My program is for windows CE and I want to keep it as tight as possible.
>>
>> (Don't tell anyone here, but I'm trying to avoid using MFC too :) )
>
> I have no idea about embedded development.
> So, in this context of embedded/mobile, is MFC too fat?
> I believe that in normal Windows XP or Vista development, the overhead of
> MFC over ATL or pure Win32 is acceptable, considering modern PCs big
> amount of RAM and CPUs high speed...

Well it is becoming less of a problem obviously as memory goes up in
devices, but I think it is still significant.

Anyway, once again, thanks for your help.


From: Giovanni Dicanio on

"Fred" <not(a)here.com> ha scritto nel messaggio
news:PaadnQN4M5jqc6_anZ2dnUVZ8uadnZ2d(a)pipex.net...

> I had a quick look last night. I added
> #include <atlbase.h>
>
> to stdafx.h and got several "ambiguous" errors
>
> eg
>
> .\SP1.cpp(4450) : error C2668: 'CreatePen' : ambiguous call to overloaded
> function
>
> C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Smartphone
> SDK\include\ARMV4I\wingdi.h(591): could be 'HPEN
> CreatePen(int,int,COLORREF)'
>
> C:\Program Files\Microsoft Visual Studio
> 8\VC\ce\atlmfc\include\atlosapice.h(750): or 'HPEN
> ATL::CreatePen(int,int,COLORREF)'

Hi Fred,

I would like to see some part of your code.

I have never had any problems #including <atlbase.h> ...

And I think that if you want to disambiguate, you should use the "global
namespace" specifier ::
e.g. use ::CreatePen(...) for the Win32 API, and CreatePen inside ATL
context.
But again, without seeing actual code, it is more a kind of guess.

Giovanni



From: Fred on


----- Original Message -----
From: "Giovanni Dicanio" <giovanni.dicanio(a)invalid.it>
Newsgroups: microsoft.public.vc.mfc
Sent: Thursday, November 08, 2007 10:51 PM
Subject: Re: Queryinterface then Release fails


>
> "Fred" <not(a)here.com> ha scritto nel messaggio
> news:PaadnQN4M5jqc6_anZ2dnUVZ8uadnZ2d(a)pipex.net...
>
>> I had a quick look last night. I added
>> #include <atlbase.h>
>>
>> to stdafx.h and got several "ambiguous" errors
>>
>> eg
>>
>> .\SP1.cpp(4450) : error C2668: 'CreatePen' : ambiguous call to overloaded
>> function
>>
>> C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Smartphone
>> SDK\include\ARMV4I\wingdi.h(591): could be 'HPEN
>> CreatePen(int,int,COLORREF)'
>>
>> C:\Program Files\Microsoft Visual Studio
>> 8\VC\ce\atlmfc\include\atlosapice.h(750): or 'HPEN
>> ATL::CreatePen(int,int,COLORREF)'
>
> Hi Fred,
>
> I would like to see some part of your code.
>
> I have never had any problems #including <atlbase.h> ...
>
> And I think that if you want to disambiguate, you should use the "global
> namespace" specifier ::
> e.g. use ::CreatePen(...) for the Win32 API, and CreatePen inside ATL
> context.
> But again, without seeing actual code, it is more a kind of guess.
>
> Giovanni

What part of my code would you like to see? :)

No need your guess was correct.! In my defence it was past midnight and I
just stuck the atlbase.h in to see what would happen and gave up for the day
when I got the errors.

I have spent all today trying to get the Image stuff working. I create the
image in a thread. I return it to the main thread.

I look at the image info

hr=pImage->GetImageInfo(&imageInfo);


I create a bitmap

if (SUCCEEDED(pImageFactory->CreateBitmapFromImage(
pImage, imageInfo.Width, imageInfo.Height,
PixelFormatDontCare, InterpolationHintDefault,
&pBitmapImage)))


then I look at the imageInfo (for fun :) ) and it fails!!!!

hr=pImage->GetImageInfo(&imageInfo);


The same code works if I do it in the thread repeatedly - but fails in the
main thread.

I have CoInitializeEx(0, COINIT_MULTITHREADED);
once in the main thread. I spent all day and couldn't understand why it
wasn't working - it needed to work as I create bitmaps of several sizes from
the one image. so I ended up returning the raw data and creating the image
in the main thread from that.

Humpphhh !!!!














From: Giovanni Dicanio on

"Fred" <not(a)here.com> ha scritto nel messaggio
news:zOKdnWz7_a43J67anZ2dneKdnZydnZ2d(a)pipex.net...

> What part of my code would you like to see? :)
>
> No need your guess was correct.!

I'm glad.


> then I look at the imageInfo (for fun :) ) and it fails!!!!
>
> hr=pImage->GetImageInfo(&imageInfo);

What value of HRESUL do you get?

IImage::GetImageInfo

http://msdn2.microsoft.com/en-us/library/aa452166.aspx


> The same code works if I do it in the thread repeatedly - but fails in the
> main thread.
>
> I have CoInitializeEx(0, COINIT_MULTITHREADED);
> once in the main thread.

Have you tried COINIT_APARTMENTTHREADED ?
i.e.

CoInitializeEx(
NULL,
COINIT_APARTMENTTHREADED
);

You may have some problems of concurrency with the multi-threaded model of
COINIT_MULTITHREADED; if you use multi-threaded model, you should provide
your own synchronization mechanisms e.g. typically using Win32 primitives
like critical sections, semaphores, etc.
Instead, if you use the apartment-threaded model (COINIT_APARTMENTTHREADED)
you can still have multi-threading, but COM offers its own synchronization
(serializing calls to methods of objects).

Giovanni


From: Fred on

"Giovanni Dicanio" <giovanni.dicanio(a)invalid.it> wrote in message
news:%23$8qpjrIIHA.1168(a)TK2MSFTNGP02.phx.gbl...
>
> "Fred" <not(a)here.com> ha scritto nel messaggio
> news:zOKdnWz7_a43J67anZ2dneKdnZydnZ2d(a)pipex.net...
>
>> What part of my code would you like to see? :)
>>
>> No need your guess was correct.!
>
> I'm glad.
>
>
>> then I look at the imageInfo (for fun :) ) and it fails!!!!
>>
>> hr=pImage->GetImageInfo(&imageInfo);
>
> What value of HRESUL do you get?
>
> IImage::GetImageInfo
>
> http://msdn2.microsoft.com/en-us/library/aa452166.aspx
>
>
>> The same code works if I do it in the thread repeatedly - but fails in
>> the main thread.
>>
>> I have CoInitializeEx(0, COINIT_MULTITHREADED);
>> once in the main thread.
>
> Have you tried COINIT_APARTMENTTHREADED ?
> i.e.
>
> CoInitializeEx(
> NULL,
> COINIT_APARTMENTTHREADED
> );
>
> You may have some problems of concurrency with the multi-threaded model of
> COINIT_MULTITHREADED; if you use multi-threaded model, you should provide
> your own synchronization mechanisms e.g. typically using Win32 primitives
> like critical sections, semaphores, etc.
> Instead, if you use the apartment-threaded model
> (COINIT_APARTMENTTHREADED) you can still have multi-threading, but COM
> offers its own synchronization (serializing calls to methods of objects).
>

Hmm - NO SDK examples have COINIT_APARTMENTTHREADED and when I tried to use
it I got E_FAIL returned from CoInitializeEx.

But hunting around I found this text in an SDK Imaging demo

// Normally you would only call CoInitialize/CoUninitialize
// once per thread. This sample calls CoInitialize in this
// draw function simply to illustrate that you must call
// CoInitialize before calling CoCreateInstance.

CoInitializeEx(NULL, COINIT_MULTITHREADED);

// Create the imaging factory.

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory)))
{...


So I do just that creating it once per thread. And.......


It still fails, so I put a

CoInitializeEx(NULL, COINIT_MULTITHREADED);

CoUninitialize ();

pair around everywhere I CoCreateInstance (CLSID_ImagingFactory

And.......


It sometimes works sometimes doesn't.
so I imagine it *is* something to do with the threading. But......

The hr is
hr -2147467259 {E_FAIL}
The debuuger error I get back when it fails is:

GetImageInfo fails//my text

RaiseException: Thread=9665e4c0 Proc=815875b0 'SP1.exe'

AKY=00200001 PC=03f785b4(coredll.dll+0x000185b4)
RA=800773f4(NK.EXE+0x000073f4) BVA=00000000 FSR=00000000

Hummpphh!!!