我在我的軟件中使用供應商提供的 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 文件即可實現此目的?
1 回答

收到一只叮咚
TA貢獻1821條經驗 獲得超5個贊
您可以將同一非托管庫的多個實例加載到進程中,但必須使用不同的文件名加載它們。在您的場景中,這可能意味著每次需要新實例時都使用臨時文件名制作 DLL 的副本。
- 1 回答
- 0 關注
- 143 瀏覽
添加回答
舉報
0/150
提交
取消