So I have this DLL and I call it from my main application using AfxLoadLibrary. It all works fine letting me load it and call functions.
The strange bit is this.
If my application is launched from another application first using
::CreateProcess( File, CmdLine, 0, 0, FALSE, DETACHED_PROCESS, 0, 0, &StartupInfo, &ProcInfo )
then the launched application can’t load the dll anymore.
Little diagram so as not to confuse anyone.
MainApplication -> Dll (all Fine)
Launcher -> MainApplication -> DLL (AfxLoadLibrary fails with ERROR_NOACCESS)
Both the applications and the dll are in the same directory.
Edit:
Little more information I managed to get. It’s actually this bit of code in the dll that fails at ParseCommandLine.
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
Without this the dll doesn’t load up at all so can anyone say what’s changed once the launcher application gets involved.
Turns out the problem was with this line and not in the dll
The CmdLine Variable could potentially have a space in it and wasn’t being wrapped in ” “.
That caused the Command Line not being passed through properly in the chain breaking
and by chance worked on the launched exe.
Edit:
What this doesn’t solve though is if the exe with the dll is launched using CoCreateInstance the same problem in ParseCommandLine returns.