How to get the path of the calling exe in a dll?

I am writing a DLL for a program I'm making, and I want to make sure other programs can't use the DLL. I was thinking, maybe I could calculate the MD5 checksum of the calling exe to check if it is my program. I know how to calculate an MD5 checksum, but I don't know how to get the path of the calling exe. Is there any way to read argv[0] (the path of the exe) in a dll? Or is there another way to do this?
Why not just force an initialization check? That is, make the DLL unresponsive until a specific function is called with a correct key.

Before your program tries to use the DLL, just call the unlock function.


If you really want to find the caller's path, use GetCurrentProcess() and GetModuleFileName().

Good luck!
I am using this code right now:

1
2
char modulename[MAX_PATH];
GetModuleFileName(NULL,modulename,MAX_PATH);


This seems to work correctly.

Using an unlock function will not work, the program I use to call the DLL is not very safe. Users can view the source code and get the key.
Topic archived. No new replies allowed.