0

I have a funny problem:

A program I've written uses a DLL. When installed, both the program exe and the DLL are under c:\Program Files (x86)\MyProduct

Normally the loaded DLL is a 3rd party driver. For testing purposes I replaced it with my own implementation. When I overwrite the 3rd party DLL with my own in the program files folder my program EXE cannot start the DLL, LoadLibraray returns 0 and GetLastError returns -529697949. Now when I copy the whole MyProduct folder to, let's say c:\temp and start the program EXE the DLL can be loaded.

So I guess my problem is related to Windows security. Both the programm and my version of the DLL are written in C++. My user accoount has Administrator access and it does not seem to matter if I execute the program as Administrator or not. Does anybody know if there is a windows protection mechanism that might prevent that the DLL is loaded?

Thank you

Update

I think the problem is related to the fact that my DLL tries to write to the execution directory in the DLL init function. When executing in Program Files directory windows does not allow this.

anhoppe
  • 4,287
  • 3
  • 46
  • 58
  • -529697949 is 0xE06D7363, the exception code for a C++ exception. You'll need source code and a debugger to figure out why that exception was thrown. – Hans Passant Jul 03 '14 at 15:23
  • Yeah I already read about that so I figured that ym DLL main throws an uncaught exception, but that does not seem to be the case. Since the DLL is loaded at program start I thought it would be difficult to attach the debugger to the program before the DLL is loaded. Because of the wired behaviour when I copy the folder outside program files I guessed my problem is a windows security feature. – anhoppe Jul 03 '14 at 15:29
  • No, that exception code is *highly* specific to a C++ exception. Windows doesn't generate a value like that. There's a programmer somewhere that can help you with this, the odds that you will find him here are zero. Pick up the phone and give him a call. – Hans Passant Jul 03 '14 at 15:33
  • ;-) so I guess I have to attach the debugger. The thing is that I testwise implemented an empty DllMain and still received the same result. Together with the fact that the DLL actually runs when it is not located under Program Files let me think of a security feature. But I'll give the debugger a chance... – anhoppe Jul 03 '14 at 15:39
  • @HansPassant: he's likely to get a busy signal. – Cheers and hth. - Alf Jul 03 '14 at 16:03

1 Answers1

0

Yes, I finally got it running. The problem is that my DLL tried to write to the exe folder during DLL initialization. Windows seems to detect this and the LoadLibrary call fails.

anhoppe
  • 4,287
  • 3
  • 46
  • 58
  • What's probably happening is that your code throws an exception when it cannot write to the file. It is that exception that is preventing the DLL from loading. – Raymond Chen Dec 22 '15 at 16:50