Search code examples
dllaccess-violationclass-constructors

Access violation on first variable construction from dll


I have created a dll containing my own math library. The library allows me to use its classes and a few interpolation methods. But when my program creates a class from this dll for the first time it generates a first chance exception - access violation. After that it is fine with all classes and their methods and the program runs and shutsdown fine. This is the only error my code generates and evidently stops it from running in release.

Is there something i am missing in the property pages? Or do i need to declare the classes methods virtual METHOD() = 0? (i am asking this as there is alot to add in one class to test this).

I have ran with /VERBOSE to check the linker stage and all is well, the dll is generated with no issues. Im very stumped by this issue, and i seems strange that it creates this issue upon first class creating but is fine with it afterwards.

Any hints would be most helpful, i've wasted hours with this error now.

Thanks.


Solution

  • SOLVED! Missing the dllmain.cpp which is generated by VS2010, when compiling the dll. Incase anyone elses VS didnt generate this file: #include "stdafx.h" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }