This is just a short description of a recent debugging spree, maybe it helps somebody else: we tried to load a CVI-DLL on a Siemens soft-SPS system (TIA Portal). It crashed every time, very early in the initialization. In fact the DllMain of our DLL wasn't even called, it crashed in the initialization of the CVI runtime. Specifically it tried to initialize the runtime (DLL_PROCESS_ATTACH), fails and then Windows calls again with DLL_PROCESS_DETACH, causing a crash because the DLL wasn't properly initialized and is now trying to use uninitialized memory, taking the whole process with it.
Curiously any manually started CVI binary worked fine, just when called from the SPS software it crashed. Well, long story short, when the SPS software starts the TMP environment variable is set to %SYSTEMROOT%\Temp, which on this system was not writable for normal users. The CVI runtime recognizes this, but instead of using any sensible path in the user's documents it defaults to the path of the calling .EXE file, which is in "C:\Program Files" and thus also not writable! It then throws its hands in the air and cancels the runtime initialization.
For manually started binaries the system's TMP variable was superseded with the user's TMP variable, which was the usual C:\Users\...\AppData\Local\Temp and thus perfectly writable and everything worked as expected.
TL;DR: make sure your TMP environment variable path is writable or you will get the weirdest effects.
HTH, Marcel Kilgus