首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于VS2010字符串传入C++dll有关问题

2012-03-27 
关于VS2010字符串传入C++dll问题c++dll中有这样一个方法:C/C++ codeGIS_API bool LT_Open(char* pPath)C#

关于VS2010字符串传入C++dll问题
c++dll中有这样一个方法:

C/C++ code
GIS_API bool LT_Open(char* pPath);

C#调用部分:
C# code
        [DllImport("LTGisEngine.dll", EntryPoint = "LT_Open", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]        private static extern bool LT_Open(string pPath);        public static bool LT_Open(string pPath)        {                bool bOper = false;                bOper = LT_OpenMap(pDataPath);                return bOper;        }


用vs2010编写的测试程序,当C#程序调用XXX.LT_Open(@"D:\data\data\data");c++接收到的字符串为"D"
用vs2008编写的测试程序,当C#程序调用XXX.LT_Open(@"D:\data\data\data");c++接收到的字符串为"D:\data\data\data"

求解为何?2010和2008对字符串的处理有不一样的地方吗?还是我有数据类型搞错了?谢谢各位!

[解决办法]
数据类型用错了,那你就可能会报错,
 我想知道这个函数LT_OpenMap(pDataPath);
[解决办法]
charset ansi
[解决办法]
可能是CharSet = CharSet.Auto,在两个版本中CharSet.Auto含义不同,你应该根据c++程序的字符集显式指定CharSet ,而不要用CharSet.Auto,CharSet.Auto的定义可能会随着版本变化,
[解决办法]
我猜测,你的c++程序应该是多字符编码,如果是这样,应该用CharSet = CharSet.Ansi

热点排行