将 c# 中的 String^ 转换为 c++/CLI 中的 CString

4

本文介绍了将 c# 中的 String^ 转换为 c++/CLI 中的 CString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要帮助解决在 MFC 中编写应用程序时遇到的一个问题.

I need a help on one question where I stuck while coding my app in MFC.

我在我的应用程序中使用 CLRCommon Language Runtime 来集成 c# API.但现在我坚持将 System::String^ 转换为 CString.我做不到.

I am using CLR i.e Common Language Runtime in my application to integrate c# APIs. but now I stuck on converting System::String^ to CString. I am not able to do that.

我正在使用以下代码.

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 ] );
}

现在我想将 csPass 转换为 CString.谁可以帮我这个事.提前谢谢你.

now I want to convert csPass to CString. Can any one help me on this. Thank you in advance.

推荐答案

考虑阅读 this MSDN thread 关于字符串转换.此外,以下讨论可能对您有用:

Consider reading this MSDN thread about string conversions. Also, following discussions may be useful for you:

  • 将 CString 转换为 std::wstring
  • 问题:如何将CString转换成C++ MFC 中的 const char *
  • 在c++中将字符串转换为Cstring
  • CString 到 LPCTSTR 的转换
  • CString到char的转换
  • 如何将_bstr_t转换为CString

使用此材料,您可以了解如何操作,甚至可以发布自己的解决方案作为答案

With this material you can find out how to do it and even post own solution as an answer

这篇关于将 c# 中的 String^ 转换为 c++/CLI 中的 CString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14