A B*_*A B 10 .net c# string mfc c-strings
我需要帮助解决我在编写应用程序时遇到的问题MFC.
我在我的应用程序中使用CLRie Common Language Runtime来集成c#API.但现在我坚持转换System::String^为CString.我无法做到这一点.
我正在使用以下代码.
String^ csPass = gcnew String(strPassword.GetBuffer());
array<Byte>^ Value = Encoding::UTF8->GetBytes(csPass);
for (int i = 0; i < Value->Length; i++ )
{
csPass += String::Format( "{0:X2}", Value[ i ] );
}
Run Code Online (Sandbox Code Playgroud)
现在我想转换csPass为CString.谁可以帮我这个事.先感谢您.
考虑阅读有关字符串转换的MSDN 线程。此外,以下讨论可能对您有用:
使用此材料,您可以了解如何操作,甚至可以发布自己的解决方案作为答案
得到了我的答案。感谢您的支持@Elliot Tereschuk。
我已经看过一些参考资料,例如
和
包括头文件
#include <msclr/marshal_windows.h>
#include <msclr/marshal.h>
Run Code Online (Sandbox Code Playgroud)
使用图书馆
using namespace msclr::interop;
最后,我的源代码是。
String^ csPass = gcnew String(strPassword.GetBuffer());
array<Byte>^ Value = Encoding::UTF8->GetBytes(csPass);
for (int i = 0; i < Value->Length; i++ )
{
csPass += String::Format( "{0:X2}", Value[ i ] );
}
marshal_context^ context = gcnew marshal_context();
const char* str = context->marshal_as<const char*>(csPass);
csMyPass.Format(str);
Run Code Online (Sandbox Code Playgroud)
csMypass是CString类型变量。谢谢你的支持。
| 归档时间: |
|
| 查看次数: |
6526 次 |
| 最近记录: |