如何在我的c#windows应用程序中调用c ++类方法 [英] How to call a c++ class method in my c# windows Application

查看:104
本文介绍了如何在我的c#windows应用程序中调用c ++类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的c#windows应用程序中使用c ++类方法



我用这个



I'm trying to use c++ class method in my c# windows application

I use this

[DllImport("ZKNetLib.dll", EntryPoint = "ZK_NET_DEV_SetEventCallBack")]
        public static extern int ZK_NET_DEV_SetEventCallBack(int u32Handle, ref OnEventCallBack u32Event, IntPtr pUserData);





导入dll及其方法



但是,在dll方法还有其他一些方法也用过,我很难找到

到底发生了什么。就像在上面导入的那样,dll正在使用OnEventCallBack方法。那么,有没有办法在我的Windows应用程序中使用这些c ++类和头文件。



我听说过在c ++中使用c#应用程序类制作类对象并使用那里的命名空间。



所以,我想知道应该有任何方法将这些头文件和类用于我的c#应用程序。



请帮忙。我对此非常困惑。



to import the dll and their method

But, in dll method there are some other methods are also used, which i fine very tough to find out
what exactly is happening. Like, in above import there is "OnEventCallBack" method that dll is using. So, is there any way to use these c++ class and header files in my windows application.

I, heard of using c# application class in c++ by making the class object and using there namespace.

So, i was wondering there should be any way of using these header file and class into my c# application too.

Please help. I'm so confused in all this.

推荐答案

我认为不可能直接从C#调用任何C ++类方法(即使使用<$ c) $ C>的DllImport )。您应该创建一个C风格的包装函数,它调用您需要的类方法。我的意思是没有任何课程的旧的普通C语言。该函数应具有 stdcall 命名约定。可能你必须创建一个小的附加DLL来导出你的包装函数。
I don't think it's really possible to call any C++ class methods from C# directly (even by using DllImport). You should create a C style wrapper function which calls the class method you need. I mean good old plain C language without any classes. The function should have stdcall naming convention. Possibly you will have to create a small additional DLL which exports your wrapper function.


这篇关于如何在我的c#windows应用程序中调用c ++类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆