2013-02-05 55 views
2

我需要一個Java應用程序來調用非託管C++。我將MSVCR90.dll從Visual Studio 2008 redist路徑手動複製到vmware的Windows Server Datacenter。通過Java調用非託管C++

這是我的錯誤:

已經由Java運行時環境檢測到致命錯誤:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x73b4ae7a, pid=1108, tid=2272 

JRE version: 6.0_38-b05 
Java VM: Java HotSpot(TM) Client VM (20.13-b02 mixed mode, sharing windows-x86) 
Problematic frame: 
C [MSVCR90.dll+0x3ae7a] 

An error report file with more information is saved as: 
...\hs_err_pid1108.log 

If you would like to submit a bug report, please visit: 
http://java.sun.com/webapps/bugreport/crash.jsp 
The crash happened outside the Java Virtual Machine in native code. 
See problematic frame for where to report the bug. 

這是C++代碼:

#include "stdafx.h" 

#include <stdio.h> 

#include "CCCheckString.h" 

#include <vector> 

#include <String> 

using namespace std; 
#include "jobHandler.h" 

JNIEXPORT jbolean JNICALL Java_CCCheckString_Login 
    (JNIEnv *env, jobject object, jstring host, jstring UserName, jstring Domain, jstring Password) 
{ 
    bool result; 

    jobHandler *handler = new jobHandler(); 

    const char *hostStr = (env)->GetStringUTFChars(host, NULL); 
    string hostS(hostStr); 
    const char *UserNameStr = (env)->GetStringUTFChars(UserName, NULL); 
    string UserNameS(UserNameStr); 
    const char *DomainStr = (env)->GetStringUTFChars(Domain, NULL); 
    string DomainS(DomainStr); 
    const char *PasswordStr = (env)->GetStringUTFChars(Password, NULL); 
    string PasswordS(PasswordStr); 

     //if comment this line everthing is okey 
    **result = handler->Login(hostS,UserNameS,DomainS,PasswordS);** 

    (env)->ReleaseStringUTFChars(host, NULL); 
    (env)->ReleaseStringUTFChars(UserName, NULL); 
    (env)->ReleaseStringUTFChars(Domain, NULL); 
    (env)->ReleaseStringUTFChars(Password, NULL); 


    delete handler; 

    return result; 

} 

以下是Java中的處理代碼:

CCCheckString ccCheckString = new CCCheckString(); 

result=ccCheckString.Login("xxx", "xxx", "xx", "xxx"); 

我該如何解決這個錯誤?

+1

提高可讀性 – 2013-02-05 09:39:39

+0

@ACB就是那個okey – edelibas

+0

在任何一段代碼之前加上4個空格。 (C++)' – 2013-02-05 09:53:20

回答

1

我解決了

問題是,登錄()接受的std :: string,但我們不能把它

我們重組我們登錄(),它必須爲const char []

例:

bool ClassName::Login(std::string host,std::string userName,std::string userDomain,std::string userPassword) 
{ //Orginal Code Here ....} 

bool ClassName::Login(const char host[],const char userName[],const char userDomain[],const char userPassword[]) 
{ 
std::string strHost(host); 
std::string strUserName(userName); 
std::string strUserDomain(userDomain); 
std::string strUserPassword(userPassword); 
return Login(strHost,strUserName,strUserDomain,strUserPassword); 

} 

一切都很好。