Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The start reason is that I want to change a WTL exe project to dll project so that I could use it as plugin in another project. Those code worked well in the exe, but got exception in the DLL. I tracked it down, initialization is fine, when it goes to the

CWindowImpl::create->
T::GetWndClassInfo().Register(&m_pfnSuperWindowProc)->
... if (FAILED(lock.Lock())) then
C++
inline HRESULT CComCritSecLock< TLock >::Lock() throw() 
{ HRESULT hr; 
ATLASSERT( !m_bLocked ); 
hr = m_cs.Lock();//exception caught 
if( FAILED( hr ) ) 
{ return( hr ); } 
m_bLocked = true; 
return( S_OK ); } code
Posted

1 solution

This problem has been solved, the reason is No call to InitializeCriticalSection(...);for I used the loadlibrary(*.dll),which leave the global variables(_AtlWinModule,_AtlBaseModule,_AtlComModule which is used by ATL components later) uninitialized. So in this situation, Adding _CRT_INIT to the DLLMain could overcome the access vialation, the crt_INIT function could help initialize the related global varible. like :

add _CRT_INIT in the:
C++
DLLMain(ul_reason_for_call)
 {
 case DLL_PROCESS_ATTACH:
  {
   _CRT_INIT(hModule,ul_reason_for_call,lpReserved);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900