Search code examples
c#c++boostclr

Windows 7 Access Violation


I am writing a C# application that contains a set of GUIs and uses a C++ CLR wrapper dll. The structure is like this:

C# APP -> C++/CLR DLL -> C++ Native Code static library

I can run the app on my development machine (Windows server 2012) and also on a Windows 10 machine. However on Windows 7 when the application tries to load the DLL it crashes with an access violation exception. I can't figure out what in my DLL is causing the crash and why it's only on windows 7. Everything is compiled in 64 bit. Also I believe it might have to do with the boost libraries I use in my C++ static library but I'm not sure why it would only throw an exception in windows 7.

Edit:

So I have been doing more debugging and the issue happens at LoadLibrary("myDll.dll") and not at any initialization. It still is only happening on windows 7 and not windows 10.


Solution

  • The problem was with boost threads. My static lib uses boost libraries that internally use boost threads. To fix the issue I added a command line define /DBOOST_THREAD_DYN_LINK to both my static library and C++/cli wrapper dll. This means that I had to include the dll files for boost thread, chrono, and system along with my own dll. Why this only happens on Windows 7 and not 10 I am not sure, but I would guess it has to do with the kernel on Windows 7 and how it handles the way boost threads work.