C ++ LPCTSTR to char * [英] C++ LPCTSTR to char*

查看:219
本文介绍了C ++ LPCTSTR to char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用visual studio 2010 MFC构建一个C ++程序。我的程序调用一个不是项目的DLL,它接受一个char *。我有一个函数,以LPCTSTR的格式获取一个字符串。我现在在谷歌上大约两个小时,没有找到解决方案。如何将窗体MFC LPCTSTR转换为char *。

I am using visual studio 2010 MFC to build a C++ program. My program calls a DLL that is not apart of the project and it accepts a char*. I have a function that gets a string in a format of LPCTSTR. I have been on google for about two hours now, and no solution found. How do I convert form a MFC LPCTSTR to a char*. Everything I have found either does not work, or just does not compile.

推荐答案

在MFC中,最简单的方法是通过 CStringA (前提是生成的缓冲区将是只读参数):

In MFC the easiest is to convert through CStringA (provided that resulting buffer will be a read-only argument):

LPCTSTR pszA = ...
CStringA sB(pszA);
const char* pszC = sB;
char* pszD = const_cast<char*>(pszC);

还有其他选项可供讨论:

Other options are available and were discussed:

  • c++ convert from LPCTSTR to const char *
  • How to convert from LPCTSTR to LPSTR?
  • WideCharToMultiByte, T2A macros etc.

这篇关于C ++ LPCTSTR to char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆