zoukankan      html  css  js  c++  java
  • C# 调用C++ dll

            [DllImport("kernel32.dll", EntryPoint = "LoadLibrary", CallingConvention = CallingConvention.StdCall)]
            public static extern int LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpLibFileName);

            [DllImport("kernel32.dll", EntryPoint = "GetProcAddress", CallingConvention = CallingConvention.StdCall)]
            public static extern IntPtr GetProcAddress(int hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName);

            [DllImport("kernel32.dll", EntryPoint = "FreeLibrary", CallingConvention = CallingConvention.StdCall)]
            public static extern bool FreeLibrary(int hModule);

            /// <summary>
            /// 根据dll地址获取委托
            /// </summary>
            /// <param name="dllModule">调用 LoadLibrary后得到的int 值</param>
            /// <param name="functionName">在dll中约定的函数名称</param>
            /// <param name="t">接收dll约定函数的委托</param>
            /// <returns></returns>
            public static Delegate GetDelegateFromAddress(int dllModule, string functionName, Type t)
            {
                IntPtr address = GetProcAddress(dllModule, functionName);

                if (address == IntPtr.Zero)
                    return null;

                return Marshal.GetDelegateForFunctionPointer(address, t);
            }

            /// <summary>
            /// 根据指针获取委托
            /// </summary>
            /// <param name="address"></param>
            /// <param name="t"></param>
            /// <returns></returns>
            public static Delegate GetDelegateFromIntPtr(IntPtr address, Type t)
            {
                if (address == IntPtr.Zero)
                    return null;

                return Marshal.GetDelegateForFunctionPointer(address, t);
            }

  • 相关阅读:
    Single Image Haze Removal Using Dark Channel Prior翻译
    android的单元测试
    HTML&JS笔记(1)
    动手学Javascript(1)——PopStar
    Cocos2d-x教程第(11)讲-利用遮罩(蒙版)CCLayerColor制作新手引导界面(上)
    硬币翻转倍数递增试算
    java泛型接口详解
    1352
    大话设计模式之——简单工厂模式
    iOS自适应行高方法及问题
  • 原文地址:https://www.cnblogs.com/SLchuck/p/3068548.html
Copyright © 2011-2022 走看看