说明了供应商的 DLL。需要 "instantiate" DllImport'ed 方法
Supplier's DLL is is stated. Need to "instantiate" DllImport'ed methods
我在我的软件中使用来自供应商的 DLL 文件,使用 DllImport
例如:
[DllImport("Supplier.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle(out uint handle, string connectionDetails);
[DllImport("Supplier.dll", EntryPoint = "DeallocateHandle")]
private static extern bool DeallocateHandle(uint handle);
...
使用 AllocateHandle
方法,我可以通过提供连接详细信息来检索句柄。然后我可以使用该句柄来调用我所连接的远程机器上的方法。 DeallocateHandle
取消分配此句柄。供应商说这是必需品。
我们发现可以使用相同的连接详细信息检索多个句柄。 (例如 AllocateHandle("10.1.1.1"); AllocateHandle("10.1.1.1");
)行得通。只是,如果句柄已经存在,我们将无法检索具有不同连接详细信息的句柄。 (例如 AllocHandle("10.1.1.1"); AllocateHandle("10.1.1.2");
)。
但是,当我这样做时,它起作用了:
[DllImport("Supplier.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle(out uint handle, string connectionDetails);
[DllImport("Supplier2.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle2(out uint handle, string connectionDetails);
AllocateHandle("10.1.1.1"); AllocateHandle2("10.1.1.2");
但是当我们需要更多连接时,我们将不得不重新编译。
有没有无需复制 DLL 文件即可实现的方法?
您可以将同一个非托管库的多个实例加载到一个进程中,但它们必须使用不同的文件名加载。在您的场景中,这可能意味着每次您需要一个新实例时都使用临时文件名制作 DLL 的副本。
我在我的软件中使用来自供应商的 DLL 文件,使用 DllImport
例如:
[DllImport("Supplier.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle(out uint handle, string connectionDetails);
[DllImport("Supplier.dll", EntryPoint = "DeallocateHandle")]
private static extern bool DeallocateHandle(uint handle);
...
使用 AllocateHandle
方法,我可以通过提供连接详细信息来检索句柄。然后我可以使用该句柄来调用我所连接的远程机器上的方法。 DeallocateHandle
取消分配此句柄。供应商说这是必需品。
我们发现可以使用相同的连接详细信息检索多个句柄。 (例如 AllocateHandle("10.1.1.1"); AllocateHandle("10.1.1.1");
)行得通。只是,如果句柄已经存在,我们将无法检索具有不同连接详细信息的句柄。 (例如 AllocHandle("10.1.1.1"); AllocateHandle("10.1.1.2");
)。
但是,当我这样做时,它起作用了:
[DllImport("Supplier.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle(out uint handle, string connectionDetails);
[DllImport("Supplier2.dll", EntryPoint = "AllocateHandle")]
private static extern bool AllocateHandle2(out uint handle, string connectionDetails);
AllocateHandle("10.1.1.1"); AllocateHandle2("10.1.1.2");
但是当我们需要更多连接时,我们将不得不重新编译。
有没有无需复制 DLL 文件即可实现的方法?
您可以将同一个非托管库的多个实例加载到一个进程中,但它们必须使用不同的文件名加载。在您的场景中,这可能意味着每次您需要一个新实例时都使用临时文件名制作 DLL 的副本。