예제 #1
0
        public static ModuleImplementation Import(string path, CompilerOptions options)
        {
            Dictionary <string, FunctionImplementation> functions = new Dictionary <string, FunctionImplementation>();

            // Load the module in to the current process
            IntPtr hModule = NativeMethods.LoadLibrary(path);

            if (hModule == IntPtr.Zero)
            {
                throw new AzureKinectStubGeneratorException("Unable to load implementation module");
            }


            IntPtr Stub_SetErrorFunction = NativeMethods.GetProcAddress(hModule, "Stub_SetErrorFunction");

            if (Stub_SetErrorFunction == IntPtr.Zero)
            {
                throw new AzureKinectStubGeneratorException("No Error function");
            }

            NativeMethods.Stub_SetErrorFunction setError = System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer <NativeMethods.Stub_SetErrorFunction>(Stub_SetErrorFunction);

            setError(new NativeMethods.RaiseError(ModuleError));

            try
            {
                ModuleImplementation module = new ModuleImplementation(path, hModule, functions);

                // Inspect the module for its exports and get the function addresses
                ModuleInfo moduleInfo = ModuleInfo.Analyze(path, options);
                foreach (string export in moduleInfo.Exports)
                {
                    IntPtr functionAddress   = NativeMethods.GetProcAddress(hModule, export);
                    FunctionImplementation f = new FunctionImplementation(export, module, functionAddress);
                    functions.Add(export, f);
                }

                return(new ModuleImplementation(path, hModule, functions));
            }
            catch
            {
                NativeMethods.FreeLibrary(hModule);
                throw;
            }
        }
 public void SetImplementation(string function, FunctionImplementation implementation)
 {
     this.currentFunctionImplementations[function] = implementation;
     NativeMethods.Stub_RegisterRedirect(function, implementation.Address);
 }