public ActiveXControl(string libFileName) { moduleHandle = LoadLibrary(libFileName); if (moduleHandle == IntPtr.Zero) { throw new DllNotFoundException("The library " + libFileName + " could not be found."); } IntPtr dllRegisterServerProcAddress = IntPtr.Zero; dllRegisterServerProcAddress = GetProcAddress(moduleHandle, "DllRegisterServer"); if (dllRegisterServerProcAddress == IntPtr.Zero) { throw new InvalidActiveXControlException("The library does not have a DllRegisterServer export."); } IntPtr dllUnregisterServerProcAddress = IntPtr.Zero; dllUnregisterServerProcAddress = GetProcAddress(moduleHandle, "DllUnregisterServer"); if (dllUnregisterServerProcAddress == IntPtr.Zero) { throw new InvalidActiveXControlException("The library does not have a DllUnregisterServer export."); } DllRegisterServer = Marshal.GetDelegateForFunctionPointer(dllRegisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate; DllUnregisterServer = Marshal.GetDelegateForFunctionPointer(dllUnregisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate; }
private void RegisterServer(DllRegisterServerDelegate DllRegisterServer) { uint errorCode = DllRegisterServer(); if (errorCode != 0) { throw new Win32Exception("Failed to register the DLL Server (" + errorCode + ")."); } }
public bool UnregisterDLL(string FileName) { if (!File.Exists(FileName)) { this.LastError = string.Format("Unable to find {0} in application dir.", FileName); return(false); } _unregister = (DllRegisterServerDelegate)FunctionLoader.LoadFunction <DllRegisterServerDelegate>(FileName, "DllUnregisterServer"); int i = _unregister(); if (i > 0) { return(true); } else { return(false); } }