The following code
Private IntPtr GetHwnd ()
{
IntPtr handle=0 (IntPtr);
Type obj=the GetTypeFromProgID (" CSharpDll. StartClass ");
The object ins=the Activator. CreateInstance (obj);
Try
{
The object result=obj. InvokeMember (" GetHwnd, "BindingFlags InvokeMethod, null, ins, new object [] {" DLL returned form", "000", ""});
Handle=(IntPtr) result;
}
The catch (Exception ex)
{
MessageBox. Show (" LoadDll () : "+ ex. Message);
}
Return (IntPtr) handle;
}
CodePudding user response:
The general method is unable to uninstall, and then delete the DLLOnly the AppDomain can be uninstalled
In which need to create a new AppDomain and then load the DLL, unloading, after using it to delete the DLL
CodePudding user response:
AppDomain. The CreateDomain create domainLoad the DLL
AppDomain. Unload discharge domain
CodePudding user response:
On the application domain loading and unloading application domain is still unable to delete, don't know that I write if you have any questions?class ProxyObject: MarshalByRefObject
{
Int Handel=1;
Public void Loaddll ()
{
Type obj=the GetTypeFromProgID (" CSharpDll. StartClass ");
The object ins=the Activator. CreateInstance (obj);
Try
{
The object result=obj. InvokeMember (" GetHwnd, "BindingFlags InvokeMethod, null, ins, new object [] {" DLL returned form", "000", ""});
Handel=(Int32) result;
}
The catch (Exception ex)
{
MessageBox. Show (" LoadDll () : "+ ex. Message);
}
+ Handel MessageBox. Show (" ");
}
}
The following is called:
AD=AppDomain. The CreateDomain (" DLL Unload test ");
Obj=(ProxyObject) AD. CreateInstanceFromAndUnwrap (@ "WinFormDemo. Exe", "WinFormDemo. DllInvoke. ProxyObject");
Obj. Loaddll ();
AppDomain. Unload (AD);
Obj=null;
CodePudding user response: