I’m using an API (written in c++) to connect to a DVR machine, actually I only have the .dll and the .lib files, and I want to do the job in .NET (C#).
So, the API doc contains definitions to all functions inside the dll, and I’m having a hard time trying to figure out how to translate those functions to equivalente C# definitions. Some of them are straightforward, but some I cannot make it work.
For example, there is this function:
bool searchEvent(int channel, const LONG* condition, bool next)
In my c# class I put the following:
[DllImport("search.dll")]
protected static extern bool searchEvent(int channel,
[MarshalAs(UnmanagedType.I8)]long condition, bool next);
but when I call the searchEvent function, it raises an error (memory error), I guess because of that long var. So my question is how can I translate “const LONG* condition” to c#?
Also, that searchEvent function triggers a callback that returns a struct. I am unable to translate some vars of that struct, like:
char _version[2]
time_t _time
BYTE* _minute
unsigned short int _dwell[MAX]
Can someone help me with this, please? I´m no expert in c++, so any tips are greatly appreciated. Thanks!
You will have to marshal the Mumble.Minute value yourself with Marshal.ReadXxxx(). These declarations are not great for interop, writing a wrapper in the C++/CLI language is advisable.