码迷,mamicode.com
首页 > 编程语言 > 详细

C# 中调用 C++ const char*

时间:2017-04-12 09:33:56      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:oba   示例   sharp   blog   txt   ansi   nbsp   save   const   

因为 C++ string 与 C# 中的 string 并不兼容,只能用最 C++ 中的 char* 与 C# 中的 sbyte* 进行数据的传递,

示例代码如下:

            string s = "Hello World.txt";
            IntPtr ptr = Marshal.StringToHGlobalAnsi(s);

            unsafe
            {
                sbyte* b = (sbyte*)ptr;
                ocr.LoadParameter(b);
                ocr.SaveParameter(b);
            }

 

C# 中调用 C++ const char*

标签:oba   示例   sharp   blog   txt   ansi   nbsp   save   const   

原文地址:http://www.cnblogs.com/lingtianyulong/p/6697503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!