2014-04-08 6 views
0

이전 코드를 VS ​​2010으로 변환하려고합니다. 변환하려고하는 코드는 아래에 나와 있습니다. 함수 addCommand는 다음과 같이 정의됩니다.char to ACHAR + objectARX

addCommand(const ACHAR * cmdGroupName, const ACHAR * cmdGlobalName, const ACHAR * cmdLocalName, Adesk::Int32 commandFlags, AcRxFunctionPtr FunctionAddr,AcEdUIContext *UIContext=NULL, int fcode=-1, HINSTANCE hResourceHandle=NULL, AcEdCommand** cmdPtrRet=NULL) 

세 번째 필수 인수는 ACHAR 유형입니다. 이 함수는 다음과 같은 방식으로 호출됩니다.

char cmdLocRes[65]; 

// If idLocal is not -1, it's treated as an ID for 
// a string stored in the resources. 
if (idLocal != -1) { 

    // Load strings from the string table and register the command. 
    ::LoadString(_hdllInstance, idLocal, cmdLocRes, 64); 
    acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc); 

내 문제는 변수 cmdLocRes는 char 유형이지만 인수는 ACHAR 유형이어야한다는 것입니다.

어떻게 변환 할 수 있습니까?

답변

0
  1. ACHAR은 wchar_t의 typedef (Autodesk에서 파일 AdAChar.h로 작성)입니다. 그래서 문제는 char를 wchar_t로 변환하는 방법입니다.
  2. 이 문제는 넓은 의미에서 유니 코드가 존재하기 때문에 발생합니다. Linux와 Windows 프로그래머는 일반적으로 서로를 이해하지 않고 토론합니다. 나는 그것을 이해하지 못하기 때문에 그것을 설명 할 수 없다. 열망하는 비버를위한 실이 있습니다 : What's "wrong" with C++ wchar_t and wstrings? What are some alternatives to wide characters?
  3. 포울 링은 변환 방법을 알려줍니다.
    // Convert char to wchar_t

    char cmdLocRes [65];

    // 참고 : cmdLocRes에 요소가 포함되어 있는지 확인하십시오!

    cmdLocRes [0] = 'A';

    cmdLocRes [1] = '\ 0';

    // wstringstream에게

    표준 : wstringstream의 STR을 얻으십시오;

    // wstringstream

    STR < < cmdLocRes에 문자 배열을 작성;

    //)합니다 (wstringstream

    표준 : : wstring의 WSTR = str.str에서 형식 wstring을 얻으십시오;

    // 형식 wstring에서 wchar_t를 얻기

    CONST wchar_t를 chr1 * = wstr.c_str();

    const ACHAR * chr2 = wstr.c_str(); // 우리는 wchar_t == ACHAR를 본다!

  4. char cmdLocRes [65] 대신 wchar_t cmdLocRes [65]를 사용하는 것이 더 좋습니다!

  5. 코드 스타일은 유감이지만이 텍스트 필드는 사용하지 않는 방법에 대한 또 다른 훌륭한 예입니다. 코드 블록을 포맷하려고 시도하는 데 더 오래 걸렸습니다. (그리고 그것을보십시오 !!!) 대답을 쓰는 것보다. 예수!!!