C++ LPCTSTR to char*

前端 未结 3 1209
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 14:56

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

3条回答
  •  情书的邮戳
    2021-01-25 15:36

    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(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.

提交回复
热议问题