如题,开发小白,请老师指导!!!谢谢
Marshal.StringToCoTaskMemUni,释放用Marshal.FreeCoTaskMem
Marshal这个空间在C++中怎么引用?
老师,我的意思是这个cellLibName在C++语句中想这样用,现在我想把F:\beam.cel换成cellLibName这个参数,请问怎么操作
std::string 转WString:
std::string str1 = "123"; WString string = WString::WString(str1.c_str());
WString 转 std::string:
WString str = "123";
AString astring;
std::string strText;
BeStringUtilities::WCharToCurrentLocaleChar(astring, str .c_str()); strText = astring.c_str();
请问怎么转成WCharCP,谢谢
WString就有相关转WCharCP的接口呀。 其实 .c_str()也可以。
//! Equivalent to c_str WCharCP GetWCharCP() const {return c_str();}
麻烦给看下,我这样写有什么问题,谢谢
c#代码
[DllImport("BentleyStudyC.dll")]
public static unsafe extern void StringToWPChar(string str);
C++代码
extern "C" DLLEXPORT void StringToWPChar(string str){ WString str1 = WString::WString(str.c_str()); mdlDialog_dmsgsPrint(str1.GetWCharCP());}
c/c++里边这样定义:
extern "C" DLLEXPORT void PrintString(WCharCP argv) { wprintf(argv); }
c#这边这样使用:
[System.Runtime.InteropServices.DllImport("tup.dll", EntryPoint = "PrintString")] public static extern void PrintString(long str); public static void TestFun(string unparsed) { string myStr = "SDfsdfsdf\n"; IntPtr intPtr = Marshal.StringToCoTaskMemUni(myStr); ImportNativeCode.PrintString(intPtr.ToInt64()); Marshal.FreeCoTaskMem(intPtr); return; }
Answer Verified By: 鸣 崔
按照老师方式已经解决,谢谢