[英]Error while calling a c# dll from java through a C++ wrapper
First, here's my config : I'm working on a 64 bit win 7 pc, along with a XP 32bits SP3 in a virtual machine. 首先,这是我的配置:我正在使用64位win 7 pc,以及虚拟机中的XP 32位SP3。 I use Visual studio 2010 and eclipse.
我使用Visual Studio 2010和eclipse。
I'm working with the following components : 我正在使用以下组件:
I want to use BusinessDll from Java component so I decided to use jna and a wrapper in C++. 我想从Java组件中使用BusinessDll,所以我决定在C ++中使用jna和包装器。
Now here the calling tests I've done: 现在这里是我做过的调用测试:
Wrapper Test -> Wrapper -> BusinessDll ----> OK 包装测试 - >包装 - > BusinessDll ---->好的
Java component -> Wrapper ----> OK Java组件 - > Wrapper ---->好的
with the message : 随着消息:
#
# 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
Crash stack : 崩溃堆栈:
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
I've got the same result with Win 7 64bits and with the XP 32bits virtual machine. 我在Win 7 64位和XP 32bits虚拟机上获得了相同的结果。
Follows, the code I used : 关注,我使用的代码:
Java component 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();
}
Wrapper 包装纸
JavaInterface.h 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 DotNetInterface.h
#ifdef __cplusplus
extern "C"
{
#endif
__declspec(dllexport) void superDummy( );
#ifdef __cplusplus
}
#endif
Wrapper.cpp 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();
}
}
With BusinessClass part of the BioBusiness Namespace in the C# dll. BusinessClass是C#dll中BioBusiness命名空间的一部分。 And superDummy a method of BioBusiness.
而superDummy是BioBusiness的一种方法。
I've been trying for a few days now, any idea is welcome. 我已经尝试了几天,任何想法都是受欢迎的。 Thanks for reading.
谢谢阅读。
Adrien 阿德里安
Your C++ DLL is written by managed C++, I double this this is the reason why you got this exception. 您的C ++ DLL是由托管C ++编写的,我加倍,这就是您遇到此异常的原因。 I think you can try this: 1. Write the wrapper DLL in native C++, which will call functions in mixed C++ DLL, then mixed C++ will call functions in C# DLL 2. Write the wrapper DLL in native C++, and export the C# DLL as COM, then use this COM component in the native C++ DLL.
我想你可以试试这个:1。在本机C ++中编写包装DLL,它将调用混合C ++ DLL中的函数,然后混合C ++将调用C#DLL中的函数。在本机C ++中编写包装DLL,并导出C#DLL作为COM,然后在本机C ++ DLL中使用此COM组件。
One more thing: Internal Error (0xe0434352). 还有一件事:内部错误(0xe0434352)。 0xe0434352 means this exception generated by CLR.
0xe0434352表示CLR生成此异常。 You can get the details of the exception with Windbg.
您可以使用Windbg获取异常的详细信息。 Please read this article
请阅读这篇文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.