This topic is now archived and is closed to further replies.


Where to put DLL so that web service can load it

Recommended Posts

Jell    122
I have created a web service. This web service should load a c++ dll at Load time. For this, i have copied my DLL in the Project folder(where my remaining web service code is). but my web service is not able to load this dll. Reason :: I have not put the DLL in the right path (or directory). But until now i have not figured out where should the DLL be put so that the web service is able to load it. If anybody can give some feedback on this, it will mean great help.

Share this post

Link to post
Share on other sites
m1o1d1    138
Windows seems to like it if DLLs are located in the System32 folder. You could try putting a copy there.

if i am not mistaken, windows usually looks in these places (in this order, i think):

-The folder itself (normally it searches in the folder the Exe is located in too, wierd that it doesn''t)
-I read somewhere, that after all has failed, windows searches everywhere? But i doubt this.

Coding is a lifestyle,
Gaming an obsession

Share this post

Link to post
Share on other sites
BriTeg    168
Besides moving the .dll to the windows/system32 folder, there are a few ways you can keep it in the original folder instead if you want. Here are two off the top of my head:

- at install time, the installer can write to the registry (in HKEY_LOCAL_MACHINE\Software\(your company)\(your app) would be good) the location (full path) of the .dll. Then your service, when it wants to load the .dll, looks up the info in the registry and loads the .dll using the full path.

- if the .dll is in the same folder as your service executable: at run time, call GetModuleFileName to get the full path of the service executable. Strip of the everything after the last slash, and tack on the name of your .dll, giving you the full path to your .dll, which you can then load. Code:

char dllpath[_MAX_PATH];
GetModuleFileName(NULL, dllpath, _MAX_PATH); // get full path of currently running executable
char *cp = strrchr(dllpath, '\\'); // find the last slash
*cp = '\0'; // and trim it
strcat(dllpath, "\\mydll.dll"); // append the name of your .dll
HMODULE hDll = LoadLibrary(dllpath);

[edited by - BriTeg on March 30, 2004 11:36:38 AM]

Share this post

Link to post
Share on other sites