<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title=" [推荐] C#调用dll(C++(Win32))时的类型转换总结" id="card1">
<p> 游客</p><p>
标题: [推荐] C#调用dll(C++(Win32))时的类型转换总结<br/>
正文:<br/>
 C++(Win 32)C#char**作为输入参数转为char[]，通过Encoding类对这个string[]进行编码后得到的一个char[]作为输出参数转为byte[]，通过Encoding类对这个byte[]进行解码，得到字符串C++ Dll接口：void CplusplusToCsharp(in char** AgentID, out char** AgentIP);C#中的声明：[DllImport(&amp;quot;Example.dll&amp;quot;)]public static extern void CplusplusToCsharp(char[] AgentID, byte[] AgentIP);C#中的调用：Encoding encode = Encoding.Default;byte[] tAgentID;byte[] tAgentIP;string[] AgentIP;tAgentID = new byte[100];tAgentIP = new byte[100];CplusplusToCsharp(encode.GetChars(tAgentID), tAgentIP);AgentIP[i] = encode.GetString(tAgentIP,i*Length,Length);HandleIntPtrHwndIntPtrint*ref intint&amp;amp;ref intvoid*IntPtrunsigned char*ref byteBOOLboolDWORDint 或 uint（int 更常用一些）枚举类型Win32：BOOL MessageBeep(UINT uType // 声音类型); 其中的声音类型为枚举类型中的某一值。C#：用户需要自己定义一个枚举类型：public enum BeepType{　 SimpleBeep = -1,　 IconAsterisk = 0x00000040,　 IconExclamation = 0x00000030,　 IconHand = 0x00000010,　 IconQuestion = 0x00000020,　 Ok = 0x00000000,}C#中导入该函数：[D<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=257&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=257&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=257&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=257&amp;Page=3">[3]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=257&amp;Page=6">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=257">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=257">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>