5

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); 

to import the dll and their method

But, in dll method there are some other methods are also used, which i find 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?

Below is the edited question

ZK_NET_DEV_SetDataCallBack This function is used for information data callback. HI_S32 ZK_NET_DEV_SetDataCallBack ( HI_U32 u32Handle HI_ON_DATA_CALLBACK cbDataCallBack, HI_VOID* pUserData );

Parameters u32Handle [IN] Operation handle cbDataCallBack [IN] Information data callback function pUserData [IN] User data

Callback Function typedef HI_S32 (*HI_ON_DATA_CALLBACK)( HI_U32 u32Handle, HI_U32 u32DataType, HI_U8* pu8Buffer, HI_U32 u32Length, HI_VOID* pUserData );

Callback Function Parameters u32Handle Operation handle u32DataType Data type Macro Definition Value Meaning ZK_NET_DEV_MOTION_DETECTION 0 Motion detection alarm ZK_NET_DEV_INPUT_ALARM 1 Input alarm ZK_NET_DEV_KEEP_ALIVE 2 Heartbeat packet pu8Buffer Data. If the value of u32DataType is ZK_NET_DEV_MOTION_DETECTION, pu8Buffer is stored as HI_S_ALARM_MD. typedef struct { HI_U32 u32Area; //Area HI_U32 u32X; //x coordinate HI_U32 u32Y; //y coordinate HI_U32 u32Width; //Rectangular width HI_U32 u32Height; //Rectangular height } HI_S_ALARM_MD; The maximum value of u32Area is 4. Related data is as follows: Macro Definition Value Meaning ZK_NET_DEV_MOTION_AREA_1 1 Area 1 ZK_NET_DEV_MOTION_AREA_2 2 Area 2 ZK_NET_DEV_MOTION_AREA_3 3 Area 3 ZK_NET_DEV_MOTION_AREA_4 4 Area 4 u32Length Data length. If the value of u32DataType is ZK_NET_DEV_MOTION_DETECTION and alarms are generated in two areas, the value of u32Length is: u32Length = 2*sizeof(HI_S_ALARM_MD) u32DataType User data

Return Values HI_SUCCESS is returned for a successful operation and HI_ FAILURE for a failed operation.

12
  • You mentioned "C++ class" but the code is referencing something that looks like a global function, ZK_NET_DEV_SetEventCallBack. There's no class here. Commented Jan 22, 2014 at 7:58
  • You might not read the question properly. ZK_NET_DEV_SetEventCallBack is a dll method. And, this dll method accessing another c++ class method like 'OnEventCallBack', that are declared and defined in c++ code. So, is there any way to directly use this class into my c# application. Commented Jan 22, 2014 at 8:04
  • Through COM you can access a C++ class and its methods, Commented Jan 22, 2014 at 8:14
  • I don't know how to access a C++ class and its methods using COM, Can you please guide me in doing so. Commented Jan 22, 2014 at 8:25
  • Please, post the relevant information from the C(++) header file of the DLL - that is, the method definition and the callback method definition. A simple method call like this definitely does not need a C++.NET intermediate :) Commented Jan 22, 2014 at 10:05

1 Answer 1

1

SWIG by far is the most reliable option you can use (recommended by Mono guys as it supports even Xamarin.iOS and Xamarin.Android)

http://www.swig.org/

As it has been used in too many scenarios (Java, C# and so on).

There are of course other alternatives, such as cxxi from Mono and so on, but if SWIG works for you then why use them?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.