C#调用DLL方案收集


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;  //支持Debug

Debug.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来调整调用约定.   相应的回调函数也是需要修改的。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值