简体   繁体   中英

Cannot execute my DLL when copied to Program Files (x86)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM