c#调用c++编写的dll函数各种参数传递问题

c#调用c++编写的dll函数各种参数传递问题

ID:6669909

大小:28.50 KB

页数:6页

时间:2018-01-21

c#调用c++编写的dll函数各种参数传递问题_第1页
c#调用c++编写的dll函数各种参数传递问题_第2页
c#调用c++编写的dll函数各种参数传递问题_第3页
c#调用c++编写的dll函数各种参数传递问题_第4页
c#调用c++编写的dll函数各种参数传递问题_第5页
资源描述:

《c#调用c++编写的dll函数各种参数传递问题》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、C#调用C++编写的DLL函数各种参数传递问题C#调用C++编写的DLL函数各种参数传递问题  1.不返回值的参数  C++原型:  boolSendNewSms(char*szTel,char*szMessage);  C#引用;  [DllImport("CdmaCard.dll",EntryPoint="SendNewSms")]  publicstaticexternboolSendNewSms(stringphone,stringmsg);  2.带返回值(char*)  C++原型:  BOO

2、LGetCardErrorMessage(char*szErrorMessage,interrorCode);  C#引用  [DllImport("CdmaCard.dll",EntryPoint="GetCardErrorMessage")]  publicstaticexternintGetCardErrorMessage(StringBuildermsg,interrorCode);  StringBuilderbuf=newStringBuilder(1024);//指定的Buf大小必须大于可能

3、的最大长度  GetCardErrorMessage(buf,1);  3.带返回值(其他类型)  C++原型:  BOOLGetSmsSaveStation(int*nSmsStation);  C#引用  [DllImport("CdmaCard.dll",EntryPoint="GetSmsSaveStation")]  publicstaticexternboolGetSmsSaveStation(refintnStation);  4.传递结构体指针(C++填充)  C++原型:  struct

4、NET_INFO_STRUCT  {  DWORDnDurationTime;//持续时间  doublenReceiveByte;//接收字节  doublenSendByte;//发送字节  };  BOOLNetGetConnectDetail(NET_INFO_STRUCT*lpNetInfo);  C#引用  publicstructNET_INFO_STRUCT  {  publicuintnDurationTime;//持续时间  publicdoublenReceiveByte;//接收字

5、节  publicdoublenSendByte;//发送字节  }  [DllImport("CdmaCard.dll",EntryPoint="NetGetConnectDetail")]  publicstaticexternintNetGetConnectDetail(refNET_INFO_STRUCTpNetInfo);  NET_INFO_STRUCTnetInfo=newNET_INFO_STRUCT();  NetGetConnectDetail(refnetInfo);  5.传递结构

6、体数组(C++来填充)  C++原型:  structUIM_BOOK_STRUCT  {  intUimIndex;  charszName[15];  charszPhone[21];  };  intReadUimAllBook(UIM_BOOK_STRUCTlpUimBookItem[],intnMaxArraySize);  C#引用  [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]//可以指定编码类型  publicstru

7、ctUIM_BOOK_STRUCT  {  publicintUimIndex;  [MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]  publicstringszName;  [MarshalAs(UnmanagedType.ByValTStr,SizeConst=21)]  publicstringszPhone;  };  [DllImport("CdmaCard.dll",EntryPoint="ReadUimAllBook")]  publics

8、taticexternintReadUimAllBook([Out]UIM_BOOK_STRUCT[]lpUimBookItem,intnMaxArraySize);  UIM_BOOK_STRUCT[]p=newUIM_BOOK_STRUCT[20];  intret=ReadUimAllBook(p,p.Length);  6.注意问题  类型不一致,会导致调用失败,  (1)long类型,在C++中是4字节的整数,在C#

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。