使用JNI集成java和.net dll
Integrating java and .net dll using JNI
我正在做一个小项目,它是java和.net dll的互操作性。
焦点:
我只有一个java文件,它调用了使用C#、CPP和MCPP创建的.net dll。。
这个节目只是一个你好世界节目。。
我只是参考下面提到的网站。
http://www.codeproject.com/Articles/378826/How-to-wrap-a-Csharp-library-for-use-in-Java
http://www.codeproject.com/Articles/13093/C-method-calls-within-a-Java-program
最后,我只是得到了一些想法,并最终做了一些错误。
编码:
#using "mscorlib.dll"
#using "CSharpHelloWorld.netmodule"
using namespace System;
public __gc class HelloWorldC
{
public:
// Provide .NET interop and garbage collecting to the pointer.
CSharpHelloWorld __gc *t;
HelloWorldC() {
t = new CSharpHelloWorld();
// Assign the reference a new instance of the object
}
// This inline function is called from the C++ Code
void callCSharpHelloWorld() {
t->displayHelloWorld();
}
};
错误:
Error 1 error C4980: '__gc' : use of this keyword requires /clr:oldSyntax command line option
Error 2 error C3699: 'interior_ptr' : cannot use this indirection on type 'CSharpHelloWorld'
Error 3 error C2750: 'CSharpHelloWorld' : cannot use 'new' on the reference type; use 'gcnew' instead
Error 4 error C2440: '=' : cannot convert from 'CSharpHelloWorld *' to 'CSharpHelloWorld ^' 11 WindowsComponentProject
Error 5 error C2011: 'HelloWorldC' : 'class' type redefinition 6 WindowsComponentProject
Error 6 error C3699: '*' : cannot use this indirection on type 'HelloWorldC' 18 WindowsComponentProject
Error 7 error C2750: 'HelloWorldC' : cannot use 'new' on the reference type; use 'gcnew' instead 18 WindowsComponentProject
Error 8 error C2440: 'initializing' : cannot convert from 'HelloWorldC *' to 'HelloWorldC ^' 18 WindowsComponentProject
Error 9 error C2027: use of undefined type 'HelloWorldC' 21 WindowsComponentProject
Error 10 error C2227: left of '->callCSharpHelloWorld' must point to class/struct/union/generic type 21 WindowsComponentProject
我只是在一些网站上寻找更改CLR属性的解决方案,但它不起作用。请帮助我解决这个问题。提前感谢!!!
您使用的是旧的托管C++语法。新的称为C++/CLI。
您可以通过在类声明前面加上ref
关键字来创建引用类型。使用^
可以像在CSharpHelloWorld^ t
中一样声明引用变量。gcnew
是用来在托管堆中创建对象的。
您应该修改您的类,如下所示。
using namespace System;
public ref class HelloWorldC {
public:
// Provide .NET interop and garbage collecting to the pointer.
CSharpHelloWorld^ t;
HelloWorldC() {
t = gcnew CSharpHelloWorld();
// Assign the reference a new instance of the object
}
// This inline function is called from the C++ Code
void callCSharpHelloWorld() {
t->displayHelloWorld();
}
};
相关文章:
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- VB.NET DLL中的C++DLL函数复制
- 是否可以编译使用 .NET DLL 和 GCC 的C++?
- 列出 C# 中的 non-.NET DLL 函数
- 如何为64位应用程序注册.NET DLL
- System.DllNotFoundException in .NET DLL
- 获取传递给子模块(C#.NET dll)中的主模块(VC++ exe)的参数
- 使用JNI集成java和.net dll
- 如何解决"原生DLL libmbusmaster.dll的问题不见了!请将 DLL 文件部署到与 mbusmaster.net.dll 相同的目录中。
- 如何更改.net dll的guid
- 动态加载.NET DLL包装C++DLL
- 使用 CoCreateInstance 从C++调用 COMVisible VB.Net dll
- .Net DLL vs C++ DLL
- 一个C++客户端无法使用我们新的 COM 注册的 .NET .dll加载,另一个客户端可以正常工作
- 如何在 Ubuntu 中将 c++ 编译为 Windows 的 .net Dll 文件
- Calling .NET DLL from Java
- 从本机C++调用.NET dll
- 从ASP调用后端.net dll.. NET Web api
- 从.Net Dll创建.Ocx文件
- 如何创建一个使用AFX库的混合模式CLR . net DLL