Hello:

Sorry for the long post.

We have a COM component, which uses MFC (for the UI side of things) and
ATL (for the COM side of things). This is loaded/instantiated from an
EXE which does not use MFC. If the device is already running (i.e
booted up), and we try and run the EXE, the DLL seems to load fine. And
run fine. (i.e we are able to get to the classes and interfaces that we
need).

However, we also have a CE Service - which does not use MFC - spawning
off the above EXE on device startup. In this scenario however, when the
EXE tries to load this DLL (using either LoadLibrary() or
CoCreateInstance()), the device never boots up. It freezes, and the
only solution to fix the problem is to hard reset the device. We found
that the CoCreateInstance or the LoadLibrary() never returns.

We tried creating a dummy dll using ATL (for COM), but no MFC, and that
seems to be loaded fine on device startup. When MFC is added to this
same DLL, the problem starts happening. i.e the DLL cannot be loaded.

However, this problem vanishes on Windows Mobile 5.0 (device being a
Qtek 9100); the DLL that uses MFC is loaded perfectly fine, and works
like clockwork. However, we need to get this darn thing working on
Pocket PC 2003.

Has anyone seen this problem before or some similar problem before? Any
help would be greatly appreciated.

Here are some data points:

- The DLL uses both MFC and ATL. Statically links to both.
- OS is Pocket PC 2003.
- Device is O2 Xda II.
- DLL is compiled with Visual Studio 2005
- EXE is compiled in EVC++4, SP2.
- EXE does not use MFC

Apologies if I have missed anything. Feel free to badger.

Cheers!
Narayan

Re: DLL using MFC has trouble getting loaded on startup. by r_z_aret

r_z_aret
Tue Apr 25 17:32:16 CDT 2006

On 25 Apr 2006 12:08:16 -0700, narayan_k@hotmail.com wrote:

>Hello:
>
>Sorry for the long post.
>
>We have a COM component, which uses MFC (for the UI side of things) and
>ATL (for the COM side of things). This is loaded/instantiated from an
>EXE which does not use MFC. If the device is already running (i.e
>booted up), and we try and run the EXE, the DLL seems to load fine. And
>run fine. (i.e we are able to get to the classes and interfaces that we
>need).
>
>However, we also have a CE Service - which does not use MFC - spawning
>off the above EXE on device startup. In this scenario however, when the
>EXE tries to load this DLL (using either LoadLibrary() or
>CoCreateInstance()), the device never boots up. It freezes, and the
>only solution to fix the problem is to hard reset the device. We found
>that the CoCreateInstance or the LoadLibrary() never returns.

This might be relevant:


#ifdef UNDER_CE
// 24 Mar 05 (1.0.0.1)
// #ifdef FOR_HPC
#if 1
// PFMWaitForAPI
// Adapted from 15 Jul 2004 contribution by JayP to a thread called
// "When is it safe to read from file system?" in
microsoft.public.pocketpc.developer:
static BOOL PFMWaitForAPI( void )
{
typedef BOOL (*PFNAPIREADYPROC)(DWORD);

LPCTSTR sLibName = L"coredll.dll",
sFuncName1 = L"IsAPIReady",
sFuncName2 = L"_IsAPIReady"; // 14 Jun 05
(0.0.1.2)
#if 0
// TODO: Why does compiler issue error C2589 (illegal token on
right side of ::) (24 Mar 05)?
HMODULE hMod = ::GetModuleHandle( sLibName );
#else
HMODULE hMod = GetModuleHandle( sLibName );
#endif
HINSTANCE hInst = reinterpret_cast<HINSTANCE>(hMod);
PFNAPIREADYPROC pIsAPIReady =
reinterpret_cast<PFNAPIREADYPROC>(::GetProcAddress(
hInst, sFuncName1 ));

#if 1
// 14 Jun 05 (0.0.1.2)
if (hMod == NULL)
return TRUE; // Library doesn't exist, so we can't test

if (pIsAPIReady == NULL)
pIsAPIReady =
reinterpret_cast<PFNAPIREADYPROC>(::GetProcAddress( hInst, sFuncName2
));
#endif
TEST_VALID( pIsAPIReady != NULL );

for (int i = 0; i < 10; i++)
{
if (pIsAPIReady(SH_SHELL))
return TRUE;
}

return FALSE;

} // PFMWaitForAPI
#else
// 25 Mar 05 (1.0.0.1)
// According to MSDN article (see 24 Mar 05 contribution from
Bruce Eitman to thread
// called "\Windows\StartUp question" in
microsoft.public.pocketpc.developer),
// IsAPIReady function is available starting with CE 2.10, but is
not in headers.
// Function should be declared in WinDev.h; actual function
should be in Coredll.dll
BOOL IsAPIReady( DWORD hAPI );
static BOOL PFMWaitForAPI( void )
{
for (int i = 0; i < 10; i++)
{
if (::IsAPIReady(SH_SHELL))
return TRUE;
}

return FALSE;

} // PFMWaitForAPI
#endif
#endif

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com