程序改成Unicode编码后,有个函数的参数报了这么一个错:error C2664: 'ConvertToJString' : cannot convert parameter 2 from 'class CString' to 'const char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called函数声明:
static jstring ConvertToJString(JNIEnv* env,const char *str) 
PS:JNIEnv为结构体原来的代码:
jstring jidtype = CUtility::ConvertToJString(m_JNIEnv, id_type);改后:
const char * aaa = (const char *)id_type.GetBuffer(id_type.GetLength());
jstring jidtype = CUtility::ConvertToJString(m_JNIEnv, aaa);报错是解决了,但是我怕这样转换过去会有什么隐患?
请问大家这样改是否妥当!!!

解决方案 »

  1.   

    jstring jidtype = CUtility::ConvertToJString(m_JNIEnv, CStringA(id_type));
      

  2.   

    将CString转成char*
    WideCharToMultiByte()或者
    T2A();
      

  3.   


    T2A这个 挺好用啊,谢了改好后出现下面的连接错误…………这该往哪方面考虑啊
     error LNK2001: unresolved external symbol "int __stdcall BIPSaveImageToFile(void *,unsigned short const *,struct FILE_INFO &)" (?BIPSaveImageToFile@@YGHPAXPBGAAUFILE_INFO@@@Z)
      

  4.   

    BIPSaveImageToFile
    这个函数哪来的
    如果是库函数就是lib没有连上
    如果是自定义函数就是没有实现函数体或cpp文件没有导入工程
      

  5.   


    lib库导入了啊,程序原先不是宽字节的编码,我把他改成宽字节后,就出现这个问题了
      

  6.   

    那可能是lib库不支持款字节吧
    改回来吧
      

  7.   


    大哥,因为多字节的程序会有一个汉字显示成?,我才想把程序改成宽字节的,有办法能不改LIB库,然后又能解决这样的问题吗?
      

  8.   

    改成多字节调用LIB,再改成宽字节显示。即按以下流程:
    Unicode编码
    ...
    ...
    改成Ansi编码
    调用Lib库
    改成Unicode编码
    ...
    ...
      

  9.   


    我是在设置里的C/C++下把_MBCS改成了_UNICODE,UNICODE然后把LINK下的OUTPUT添上了wWinMainCRTStartup,
    才改成Unicode编码的,在代码里应该怎么改变编码呢?
      

  10.   


    用的字符串和相关函数改成Ansi即可。
      

  11.   


    有例子吗?
    我用A2T宏把字符串改成Ansi会报error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)我用GetBuff把值赋给const char * 会报error C2664: 'BIPSaveImageToFile' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast我在把const char * 强制转换成const unsigned short * 就报原来的连接错误:error LNK2001: unresolved external symbol "int __stdcall BIPSaveImageToFile(void *,unsigned short const *,struct FILE_INFO &)" (?BIPSaveImageToFile@@YGHPAXPBGAAUFILE_INFO@@@Z)
    我晕了………………
      

  12.   


    有例子吗?
    我用A2T宏把字符串改成Ansi会报error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)我用GetBuff把值赋给const char * 会报error C2664: 'BIPSaveImageToFile' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast我在把const char * 强制转换成const unsigned short * 就报原来的连接错误:error LNK2001: unresolved external symbol "int __stdcall BIPSaveImageToFile(void *,unsigned short const *,struct FILE_INFO &)" (?BIPSaveImageToFile@@YGHPAXPBGAAUFILE_INFO@@@Z)
    我晕了………………