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.
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.
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.
发布评论
评论(4)
如果您希望允许隐式链接到 dll,您有三个选择:-
创建包含 dll 的本机 Win32 程序集并将其安装到 WinSxS。这需要创建一个简单的 .manifest 文件,使用一些加密工具对程序集进行签名(即清单文件和 dll),并创建 MSI 安装程序 - 或调用 IAssemblyCache 直接执行实际安装。
将 dll 安装到 System32 - 使用此选项,您需要确保 dll 具有相对唯一的名称。
将dll的路径添加到PATH中的某个位置(或修改路径以指向dll)。
如果隐式链接到 C 函数并不重要,则其他选项:-
创建公开 c 方法的 COM 接口。在注册表中注册 dll 的路径,并且 dll 的用户使用 CoCreateInstance 来获取包含该函数的接口。
将 dll 的路径存储在注册表中,并期望 dll 的用户通过 LoadLibrary 和 GetProcAddress 使用该路径来加载 dll。
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.
将其放在您的路径中的某个位置。 (我想到了 C:\Windows\System32\)。如果只有一个应用程序需要它,只需将其放在同一目录中即可。
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.
如果使用导入库调用 DLL,那么它会先查找当前目录,然后再查找 PATH。
但是,您不需要那样称呼它。您可以自己使用 LoadLibrary() 和 GetProcAddress(),然后做任何您想做的事情。如果您仅使用 dll 名称调用 LoadLibrary,它会使用与导入库相同的算法(当前目录 + 路径)——如果您传递完整路径,它将使用它。
COM 使用此技术根据注册表中 DLL 的完整路径来加载 DLL——您也可以在没有 COM 的情况下执行此操作。
除了 PATH 之外,您还可以通过其他方式搜索它 - 您可以不带路径进行调用,看看是否找到它,然后尝试注册表,然后在其他地方查找(每个驱动器的程序文件目录等)。
基本上,如果你自己调用LoadLibrary和GetProcAddress,你就可以做任何你想做的事情。
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.
我想最好将其安装到 system32 文件夹中并忘记 %PATH% 修改...
I guess that it would be best to install it into system32 folder and forget about %PATH% modification...