tags:

views:

37

answers:

4

I want to make a dll with an exposed C function accessible to applications on the system. Is there a better way to make it available than modifying %PATH%?

Because people don't like adding it to %PATH% here.

A: 

I guess that it would be best to install it into system32 folder and forget about %PATH% modification...

Daniel Mošmondor
+1  A: 

Put it somewhere in your PATH. (C:\Windows\System32\ comes to mind). If it's only needed by one application, just stick it in the same directory.

alpha123
+2  A: 

You have three options if you want to allow implicit linking to the dll :-

  • Create a native Win32 assembly that contains the dll and install it to WinSxS. This requires creating a simple .manifest file, the use of some crypto tools to sign the assembly (being the manifest file and the dll), and creating an MSI installer - or call IAssemblyCache directly to perform the actual install.

  • Install the dll to System32 - with this option you need to ensure the dll has a relativly unique name.

  • Ad the path to the dll to the someplace on the PATH (or modify path to point to the dll).

Other options if implicit linking to the C Function isn't critical:-

  • Create an COM interface that exposes the c-method. Register the path to the dll in the registry and users of the dll use CoCreateInstance to get the interface containing the function.

  • Store the path to the dll in the registry, and expect users of the dll to use that path with LoadLibrary, and GetProcAddress to load the dll.

Chris Becke
A: 

If you call the DLL using an import library, then it looks in the current directory, and then in the PATH.

But, you don't need to call it that way. You can use LoadLibrary() and GetProcAddress() yourself and then do whatever you want. If you call LoadLibrary with just the dll name, it uses the same algorithm as with the import library (current dir + PATH) -- if you pass a full path, it will use it.

COM uses this technique to load a DLL based on a full path to the DLL which is in the registry -- you could do this too without COM.

You could search for it in some other way besides the PATH -- you could call with no path, see if it finds it, and then try the registry, and then look elsewhere (every drive's program files directory, etc).

Basically, if you call LoadLibrary and GetProcAddress yourself, you can do whatever you want.

Lou Franco