VC写得dll在C#中如何调用,如何转化成C#代码

//---------------------------------------------------------------------------------ex... //---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall SS_Open_Com(const int addr,const int com,const int baud,const int delay);
功能:
打开串行口
参数
addr 显示屏地址 1~255,其中255为广播地址
com 串口号
baud 波特率 0~7 {1200,2400,4800,9600,19200,38400,57600,115200}
delay 超时时间

返回 成功 0
失败返回错误码代码(见附注2)
//---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall SS_Open_Tcp(const char *sIP,const int port,const int delay);
功能:
连接远程IP,TCP连接
参数
IP 显示屏IP地址
port 连接端口号 1024~65535
delay 超时时间

返回 成功 0
失败返回错误码代码(见附注2)
//---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall SS_Open_Udp(const char *sIP,const int port,const int delay);
功能:
连接远程IP,UDP连接
参数
IP 显示屏IP地址
port 连接端口号 1024~65535
delay 超时时间

返回 成功 0
失败返回错误码代码(见附注2)
//---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) char * __stdcall SS_Get_Window_List(void);
功能:
读取显示屏中实时通道名称列表。
参数


返回 成功: 列表字符串,以回车换行符分隔各通道。
失败: NULL
//---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall SS_Send_File(int W_index,TFileParam *param,const char *ListFile,bool IsSave);
功能:
发送实时数据
参数
W_index 实时数据窗口的序号
param 结构指针,数据的显示功能、速度、停留等参数(功能定义见如下)
ListFile 数据文件列表(列表以回车换行符分隔)
IsSave 数据是否保存

返回 成功 0
失败返回错误码代码(见附注2)
//---------------------------------------------------------------------------------
extern "C" __declspec(dllexport) int __stdcall SS_Send_Buffer(int W_index,TFileParam *param,const char *Buffer,bool IsSave);
功能:
发送实时数据
参数
W_index 实时数据窗口的序号
param 结构指针,数据的显示功能、速度、停留等参数(功能定义见如下)
Buffer 字符串数据
IsSave 数据是否保存

返回 成功 0 失败返回错误码代码(见附注2)

// TFileParam
typedef struct
{
unsigned char Effect; //播放方式 0~16(见附注1)
unsigned char Level; //速度级别 0~7 (0最慢/7最快)
unsigned char Speed; //播放速度 0~31(0最快/31最慢)
unsigned char Delay; //停留时间 0~99
//以下参数仅对文本文件有效,图形文件可为任意值
unsigned char Font; //字体大小 16或24
unsigned char ShowTitle; //是否显示标题 0不显/1显示
unsigned char TitleColor; //标题颜色 0红/1绿/2黄
unsigned char WordColor; //内容颜色 0红/1绿/2黄
} TFileParam;
展开
 我来答
空雪梦见
2013-04-16 · TA获得超过5596个赞
知道大有可为答主
回答量:2522
采纳率:75%
帮助的人:1143万
展开全部
class Program
{
[StructLayout(LayoutKind.Sequential)]
struct TFileParam
{
byte Effect;
byte Level;
byte Speed;
byte Delay;
byte Font;
byte ShowTitle;
byte TitleColor;
byte WordColor;
} ;

[DllImport("xxx.dll", EntryPoint="SS_Open_Com", CallingConvention=CallingConvention.StdCall)]
extern static int SS_Open_Com(int addr, int com, int baud, int delay);

[DllImport("xxx.dll", EntryPoint = "SS_Open_Tcp", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SS_Open_Tcp(string sIP, int port, int delay);

[DllImport("xxx.dll", EntryPoint = "SS_Open_Udp", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SS_Open_Udp(string sIP, int port, int delay);

[DllImport("xxx.dll", EntryPoint = "SS_Get_Window_List", CallingConvention = CallingConvention.StdCall)]
extern static unsafe byte* SS_Get_Window_List();

[DllImport("xxx.dll", EntryPoint = "SS_Send_File", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SS_Send_File(int W_index, ref TFileParam param, string ListFile, int IsSave);

[DllImport("xxx.dll", EntryPoint = "SS_Send_Buffer", CallingConvention = CallingConvention.StdCall)]
extern static int SS_Send_Buffer(int W_index, ref TFileParam param, byte[] Buffer, int IsSave);
}

具体情况我没办法测试。只能写到这里了。
如果有需要自己加上public
记得要using System.Runtime.InteropServices;
工程编译的时候属性的“生成”里面要“允许不安全的代码”,不然不能用指针
追问
public static extern unsafe byte* SS_Get_Window_List();
这个运行报错
错误 1 不安全代码只会在使用 /unsafe 编译的情况下出
还有就是extern "C" __declspec(dllexport) void __stdcall SS_Close(void);
extern "C" __declspec(dllexport) int __stdcall SS_Send_Time(void);
extern "C" __declspec(dllexport) int __stdcall SS_Send_Reset(void);这几个用C#如何调用
追答
所以我刚刚都说让你在工程属性的“生成”页面勾选“允许不安全的代码”了
不然C#里不让你用指针的。

那三个:
[DllImport("xxx.dll", EntryPoint = "SS_Close", CallingConvention = CallingConvention.StdCall)]extern static void SS_Close();
[DllImport("xxx.dll", EntryPoint = "SS_Send_Time", CallingConvention = CallingConvention.StdCall)]extern static int SS_Send_Time();
[DllImport("xxx.dll", EntryPoint = "SS_Send_Reset", CallingConvention = CallingConvention.StdCall)]extern static int SS_Send_Reset();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式