我試圖從Java程序中調用第三方.NET的DLL(從here兩者)第三方.NET的DLL。 尋找here和here後,我設法讓整個事情編譯和運行。但我運行.NET代碼時得到一個異常:調用使用JNI
由Java運行時環境
這隻有當我嘗試從內部訪問另一個.NET對象和方法發生已檢測
致命錯誤NET DLL:
JNIEXPORT void JNICALL Java_test_broadcast
(JNIEnv *, jobject)
{
// Instantiate the MC++ class.
IManagedWrapper* t = IManagedWrapper::CreateInstance();
// The actual call is made.
t->Broadcast();
}
void ManagedWrapper::Broadcast(std::string message)
{
//Uncommenting the following line will raise the error
//IXDBroadcast^ broadcast = XDBroadcast::CreateBroadcast(XDTransportMode::WindowsMessaging);
}
我設法創建一個.NET DLL,鏈接到上面的代碼,並按需要工作。
如何我可以調用從Java代碼中的.NET對象和方法?
Google向我展示了:[JNI4NET](http://jni4net.sourceforge.net/)和[在不使用regasm.exe的情況下從Java代碼調用.NET Dll](http:// codefry.blogspot.com/2012/01/calling-net-dlls-from-java-code-without.html)。如果您渴望並堅持不懈,它可能會向您展示更多解決方案。 – 2012-04-08 13:03:06
謝謝!我在這裏發帖前找了2天,但我從未遇到您發佈的第二個鏈接。這就是訣竅! – Eldad 2012-04-08 14:23:36
不客氣,祝你好運。 – 2012-04-08 14:25:41