C#调用DLL方案收集

来源:互联网 发布:二维数组定义 编辑:程序博客网 时间:2024/06/04 18:20


c#调用User32.dll方法  http://blog.csdn.net/wanbinwb2012/article/details/11640541


c#(winform)环境下使用动态链接库dll的详解  http://blog.csdn.net/qq_31454137/article/details/51404460


vlc在C#的使用方法  http://blog.csdn.net/io437/article/details/51188045


C#直接使用DllImport外部Dll的方法  http://blog.csdn.net/u011981242/article/details/52622923


1.引入命名空间
using System.Runtime.InteropServices
2.写调用的方法
 [DllImport("READCARD.DLL", EntryPoint = "STK_DownLoadList")]
        private static extern int STK_DownLoadList(参数);
就这样OK啊!


Sample:  C风格DLL

using System.Runtime.InteropServices; //支持DllImport[DllImport("Play.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Zs_Ini")]public static extern void Zs_Ini(); //环境初始化[DllImport("Play.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Zs_Quit")]public static extern void Zs_Quit(); //环境退出[DllImport("Play.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Zs_StartPlay")]public static extern IntPtr Zs_StartPlay(IntPtr hwnd, string rtsp, string userNmae, string passWord);//开始播放[DllImport("Play.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Zs_StopPlay")]public static extern void Zs_StopPlay(IntPtr hVideoZS);//停止播放[DllImport("Play.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Zs_IsPlaying")] public static extern bool Zs_IsPlaying(IntPtr hVideoZS);//是否在播放中


Sample : 调试输出

using System.Diagnostics;  //支持DebugDebug.WriteLine("Ini");



#1
遇到的BUG: C#调用C的dll出现 This is usually a result of calling a function declared with one calling convent

解决:这个应该是C dll中的导出函数的调用约定和C#里面声明的调用约定不一样,一般C#中是stdcall,c中默认的导出是csdecl
这个你可以检查一下,C#可以用DllImport这个attribute来调整调用约定.   相应的回调函数也是需要修改的。




原创粉丝点击