Beispiel #1
0
 public StubReference(string dllPath)
 {
     // according to MSDN, LoadLibrary requires "\"
     dllPath      = dllPath.Replace("/", @"\");
     this.library = Unmanaged.LoadLibrary(dllPath);
     if (this.library == IntPtr.Zero)
     {
         throw new Exception(
                   String.Format("Could not load library '{0}' . Error code:{1}", dllPath, Unmanaged.GetLastError()));
     }
 }
Beispiel #2
0
        Load(string path)
        {
            // the ActCtx stuff allows us to import .pyds which link to msvcr90 but don't have manifests
            // implementation explained in stub/ic_msvcr90.c
            IntPtr cookie = Unmanaged._Py_ActivateActCtx();
            IntPtr l      = Unmanaged.LoadLibrary(path);

            Unmanaged._Py_DeactivateActCtx(cookie);

            if (l == IntPtr.Zero)
            {
                throw new Exception(
                          String.Format("Could not load library '{0}' . Error code:{1}", path, Unmanaged.GetLastError()));
            }

            this.handles.Add(l);
            string funcName = "init" + Path.GetFileNameWithoutExtension(path);
            IntPtr funcPtr  = Unmanaged.GetProcAddress(l, funcName);

            if (funcPtr == IntPtr.Zero)
            {
                throw new Exception(
                          String.Format("Could not find module init function {0} in dll {1}", funcName, path));
            }

            PydInit_Delegate initmodule = (PydInit_Delegate)Marshal.GetDelegateForFunctionPointer(
                funcPtr, typeof(PydInit_Delegate));

            initmodule();
        }