title: load an OCX dynamically and get the handle of loaded module in C#
body: <p>I am going to load an OCX in runtime and pass the handle of loaded ocx to another function which is a patch ,
  I have the delphi code and it works fine , I want to convert it to c# but I don't know how</p>
  
  <pre><code>Type    
    TDLLFunc = procedure(param1: dword);
  VAR
    DLLFunc      : TDLLFunc;
    OcxDllHndle  : LongInt;
    DllHandle    : LongInt;
  
  begin
    OcxDllHndle := LoadLibrary('SampleOcx.Dll');
    DllHandle   := LoadLibrary('Patch.dll');
    @DLLFunc    := GetProcAddress(DllHandle, 'DoPatch');
    DLLFunc(OcxDllHndle);
  end;
  </code></pre>
  
  <p>here is the c# code but it doesnt work (I made AxInterop version of OCX ) :</p>
  
  <pre><code>AppDomain Domain = AppDomain.CreateDomain("TestApp", null, null);
  var assemblyName = AssemblyName.GetAssemblyName(@".\AxInterop.SampleOcx.dll");
  Assembly Ocx = Assembly.Load(assemblyName);
  IntPtr DLLHandle = LoadLibrary(Application.StartupPath + @"\Patch.dll");
  IntPtr funcaddr = GetProcAddress(DLLHandle, "DoPatch");
  
  [UnmanagedFunctionPointer(CallingConvention.StdCall)]
  delegate void MyFunc(int Handle);
  
  MyFunc DLLFunc = Marshal.GetDelegateForFunctionPointer(funcaddr, typeof(MyFunc)) as    MyFunc;
  IntPtr OCXHandle = Marshal.GetHINSTANCE(Ocx.GetType().Module);
  DLLFunc(OCXHandle.ToInt32());
  </code></pre>
  
  <p>Please help </p>