Click here to Skip to main content
15,885,197 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to use c++ class method in my c# windows application

I use this

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


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.
Posted
Comments
Richard MacCutchan 17-Jan-14 4:42am    
you should check the documentation for the DLL or talk to the person who created it.
Member 10486677 31-Jan-14 1:13am    
i do check the documentation and use it to pass the value... but someone told me that i should use a wrapper to call these dll. I don't know how to make a wrapper. plzzz help
Richard MacCutchan 31-Jan-14 3:18am    
Sorry, but I don't have the documentation for this library so I have no idea why it doesn't work. You should talk to the people who produce the library. I have no idea whether creating a C-style wrapper would help, but again you need to consult the documentation.
Member 10486677 31-Jan-14 5:52am    
I have sdk in vc++ and also its documentation.. i can provide it to you if you want to...
I want to develop my application in c# by using these vc++ dll.
Richard MacCutchan 31-Jan-14 6:28am    
Sorry but I am not going to read a load of documentation on some library that I know nothing about. I have other calls on my time.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900