大号preFIX在C ++字符串 [英] L prefix for strings in C++
问题描述
我有一个静态库。这个库已经定义了下面的函数
INT WriteData(LPTSTR S)
要调用的函数的样品
LPTSTR S =(LPTSTR)L测试数据;
INT N = WriteData(S);
WriteData返回0成功-1失败。
我写一个动态的DLL导出此功能。
INT TestFun(LPTSTR的lpData)
{
返回WriteData(lpData所);
}
一个C ++应用程序的测试结果。
LPTSTR S =(LPTSTR)L测试数据;
TestFun(多个); // OK返回0
LPTSTR S =(LPTSTR)测试数据;
TestFun(多个); //失败返回-1
我必须从C#应用程序调用它。我想我的DLL导入签名是:
[的DllImport(Test.dll的)
私人静态外部INT TestFun(String s)将;
我的问题很简单,我怎样才能从.net打电话了吗? 正如你所看到的,我有过
控制 TestFun(LPTSTR的lpData)
但在
没有控制 WriteData(LPTSTR S)
谢谢大家征求他们的意见。到目前为止,我被困在铸造。我想我的问题将得到解决时,竟被我能够接受输入从用户和写入2线现浇下面一行。
LPTSTR S =(LPTSTR)L测试数据); //< =如何能够从第二用户采取投入和
TestFun(多个); // OK返回0
第l preFIX使得字符串wchar_t的字符串。
您可以使用Windows API函数的MultiByteToWideChar
为ANSI字符串转换为wchar_t的字符串。
I have a static library. This library have the following function defined
int WriteData(LPTSTR s)
The sample to call the function is
LPTSTR s = (LPTSTR) L"Test Data";
int n = WriteData(s);
WriteData return 0 on success and -1 on failure.
I am writing a dynamic DLL to export this function.
int TestFun(LPTSTR lpData)
{
return WriteData(lpData);
}
A C++ test application result
LPTSTR s = (LPTSTR) L"Test Data";
TestFun(s); //OK return 0
LPTSTR s = (LPTSTR) "Test Data";
TestFun(s); //Fail return -1
I have to call it from a c# application. I assume my DLL-Import signature would be:
[DllImport("Test.dll")]
private static extern int TestFun(String s);
My question is very simple How can i call it from .Net? As you can see i have control over
TestFun(LPTSTR lpData)
but no control over
WriteData(LPTSTR s)
Thanks everybody for their input. So far i am stuck on casting. I think my problem would be solved when i woul be able take input from user and write 2 line for casting in place of following line.
LPTSTR s = (LPTSTR) L"Test Data"); //<= How can ii take input from user and
TestFun(s); //OK return 0
The L prefix makes the string a wchar_t string.
You can use the Windows API function MultiByteToWideChar
to convert an ANSI string to a wchar_t string.
这篇关于大号preFIX在C ++字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!