首先,我的配置是: 我正在64位win 7 pc上工作,並在虛擬機中安裝XP 32bits SP3。 我使用Visual Studio 2010和eclipse。通過C++封裝從java調用c#dll時出錯
我與以下部件工作:
- BusinessDll:C#DLL(32位.NET框架3.5),我要做出的java
- 包裝訪問:C++的dll 32這些位是爲了將Java調用轉發給C#。它引用了c#dll。
- 包裝測試調用包裝函數的C++測試exe。
- Java組件:使用jre7 32位的測試項目。
我想使用Java組件中的BusinessDll,所以我決定在C++中使用jna和包裝器。
現在,這裏的呼叫測試中,我所做的:
封裝測試 - >包裝 - > BusinessDll ----> OK
Java組件 - >包裝----> OK
- Java組件 - >包裝 - > BusinessDll ---->KO
與消息:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (0xe0434352), pid=264, tid=6488
#
# JRE version: 7.0_25-b16
# Java VM: Java HotSpot(TM) Client VM (23.25-b01 mixed mode windows-x86)
# Problematic frame:
# C [KERNELBASE.dll+0xc41f] RaiseException+0x58
崩潰堆棧:
Stack: [0x00810000,0x00860000], sp=0x0085e13c, free space=312k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [KERNELBASE.dll+0xc41f] RaiseException+0x58
C [clr.dll+0xe2b54] GetCLRFunction+0xd209
C [clr.dll+0x12849b] CopyPDBs+0x4ab5
C [clr.dll+0x2ccacd] CorLaunchApplication+0x255e5
我有與Win 7 64位和與XP 32位虛擬機相同的結果。
接下來,我使用的代碼:
Java組件
System.load("D:\\dev\\Wrapper.dll");
public interface BioWrapp extends Library
{
Wrapp INSTANCE = (Wrapp) Native.loadLibrary("Wrapper", Wrapp.class);
void SuperDummy();
}
public static void main(String[] args)
{
BioWrapp mysdll = BioWrapp.INSTANCE;
mysdll.BioSuperDummy();
}
包裝
JavaInterface.h
#ifdef BIOWRAPPDLL_EXPORTS
#define BIOWRAPPDLL_API __declspec(dllexport)
#else
#define BIOWRAPPDLL_API __declspec(dllimport)
#endif
namespace BioJavaWrapperNp
{
class BioJavaWrapper
{
public:
static BIOWRAPPDLL_API void BioSuperDummy();
};
}
DotNetInterface.h
#ifdef __cplusplus
extern "C"
{
#endif
__declspec(dllexport) void superDummy();
#ifdef __cplusplus
}
#endif
Wrapper.cpp
#include "stdafx.h"
#include "BioJavaWrapper.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace BioBusiness;
namespace BioBusinessNp
{
void BioJavaWrapper::BioSuperDummy()
{
BusinessClass::superDummy();
}
}
隨着在C#DLL中BioBusiness命名空間的BusinessClass一部分。 SuperDummy是BioBusiness的一種方法。
我一直在嘗試幾天,任何想法是值得歡迎的。 感謝您的閱讀。
阿德里安