static void Main(string[] args)
    {
        IntPtr pDll = NativeMethods.LoadLibrary(@"PathToYourDll.DLL");
        //oh dear, error handling here
        //if (pDll == IntPtr.Zero)
        IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "MultiplyByTen");
        //oh dear, error handling here
        //if(pAddressOfFunctionToCall == IntPtr.Zero)
        MultiplyByTen multiplyByTen = (MultiplyByTen)Marshal.GetDelegateForFunctionPointer(
            pAddressOfFunctionToCall,
            typeof(MultiplyByTen));
        int  theResult = multiplyByTen(10);
        bool result    = NativeMethods.FreeLibrary(pDll);

        //remaining code here
        Console.WriteLine(theResult);
    }
示例#2
0
        public KalynaKernel()
        {
            IntPtr pDll = NativeMethods.LoadLibrary(Directory.GetCurrentDirectory() + "\\x64\\Release\\KalynaByC.dll");

            if (pDll == IntPtr.Zero)
            {
                throw new ApplicationException();
            }

            IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "MultiplyByTen");

            if (pAddressOfFunctionToCall == IntPtr.Zero)
            {
                throw new ApplicationException();
            }

            MultiplyByTen multiplyByTen = (MultiplyByTen)Marshal.GetDelegateForFunctionPointer(
                pAddressOfFunctionToCall,
                typeof(MultiplyByTen));
        }