Hi, i am a newbie to native methods. Previous method tries to take the javastring, converts to BSTR and passes it to a visual basic application. Encoding is important and it must support non UTF-8 characters. The problem is that it passes only first character of all string. I couldn't comment where the problem is. Thanks in advance...
BSTR _stdcall getMessageAsText(){
jmethodID id = env->GetMethodID(testClass, "checkSendingTextMessage", "()Ljava/lang/String;");
jstring strJava = (jstring) env->CallObjectMethod( testObject, id );
BSTR retValue = NULL;
env->ExceptionDescribe();
if (strJava != NULL){
jboolean isCopy = 0;
const jchar *data = env->GetStringChars(strJava, &isCopy);
int length = env->GetStringLength(strJava);
char* rtn = (char *)malloc( length*2+1 );
int size = 0;
size = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)data, length, rtn, (length*2+1), NULL, NULL );
if( size <= 0 )
return NULL;
retValue = ::SysAllocString((WCHAR *)data);
if (!isCopy)
env->ReleaseStringChars(strJava,data);
return retValue;
}
return NULL;
}