请问:
怎样将char*字符串转换成ushort*?采用MultiByteToWideChar只能转换英文,请求转换中文的方法?

解决方案 »

  1.   

    MultiByteToWideChar 不论英文还是中文都能转换的。
    另一种选择是 
    A2W()
      

  2.   

    #define A2W(lpa) (  ((_lpa = lpa) == NULL) ? NULL : (  _convert = (lstrlenA(_lpa)+1),  ATLA2WHELPER((LPWSTR) alloca(_convert*2), _lpa, _convert, _acp)))
      

  3.   

    String Conversion Macros
    The string conversion macros discussed here are valid for both ATL and MFC. For more information on MFC string conversion, see TN059: Using MFC MBCS/Unicode Conversion Macros and MFC Macros and Globals.The syntax of the string-conversion macros is:MACRONAME( string_address )For example:A2W(lpa)In the macro names, the source string type is on the left (for example, A) and the destination string type is on the right (for example, W). A stands for LPSTR, OLE stands for LPOLESTR, T stands for LPTSTR, and W stands for LPWSTR.Thus, A2W converts an LPSTR to an LPWSTR, OLE2T converts an LPOLESTR to an LPTSTR, and so on.The destination string is created using _alloca, except when the destination type is BSTR. Using _alloca allocates memory off the stack, so that when your function returns, it is automatically cleaned up.If there is a C in the macro name, the macro converts to a const string. For example, W2CA converts an LPWSTR to an LPCSTR.Note   When using an ATL string conversion macro, specify the USES_CONVERSION macro at the beginning of your function in order to avoid compiler errors. For example:void func( LPSTR lpsz )
    {
       USES_CONVERSION;
       ...
       LPWSTR x = A2W(lpsz)
       // Do something with x
       ...
    }The behavior of the ATL string conversion macros depends on the compiler directive in effect, if any. If the source and destination types are the same, no conversion takes place. Compiler directives change T and OLE as follows:Compiler directive in effect T becomes OLE becomes 
    none A W 
    _UNICODE W W 
    OLE2ANSI A A 
    _UNICODE and OLE2ANSI W A 
    The following table lists the ATL string conversion macros.ATL String Conversion MacrosA2BSTR OLE2A T2A W2A 
    A2COLE OLE2BSTR T2BSTR W2BSTR 
    A2CT OLE2CA T2CA W2CA 
    A2CW OLE2CT T2COLE W2COLE 
    A2OLE OLE2CW T2CW W2CT 
    A2T OLE2T T2OLE W2OLE 
    A2W OLE2W T2W W2T 
    ATL Macros and Global FunctionsSee AlsoDEVMODE and TEXTMETRIC String Conversion Macros
      

  4.   

    MultiByteToWideChar是可以的..你的參數設置.可能有問題..
    你把你的代碼貼出來.
      

  5.   

    不就是转为BSTR么:
    char *str="aggggggg";
    BSTR temp;
    USES_CONVERSION;
    temp=::SysAllocString(A2W(str));
      

  6.   

    代码应该没问题:
    char *pmbc"问题"
    USHORT Format1[40];
    MultiByteToWideChar(CP_ACP,0,pmbc,strlen(pmbc),Format1,sizeof(Format1)-1);在Delphi中,是可以实现的,在VC中不行。
      

  7.   

    MultiByteToWideChar 应该没有问题的。我作过的项目(日文系统下的)用过好多次了。日文汉字都可以,中文不可能不行吧。一定可以。一定是你把参数弄错了。