I am trying to access the microscope from my C # application. The SDK is written in C ++, and I cannot add Dlls as links in my application (due to their unmanaged code). As a result, I found out that I would need to use DllImport to use C # functions.
Unfortunately, this looks like my head.
An example is C ++ code (from an example application included in the SDK):
interface Camera; typedef Camera * CameraHandle; struct CameraInfo { wchar_t camera_name[64]; // camera head type wchar_t controller_name[64]; // controller type wchar_t firmware_version[64]; // firmware version long lib_id; // library ID long controller_id; // controller ID long camera_id; // camera ID CameraHandle handle; // handle to opened camera long status; // status (0 = available) CameraInfo() { memset(this,0,sizeof(*this)); } }; typedef struct CameraInfo CameraInfo; CamDiscoverCameras(OUT const struct CameraInfo ** info, OUT long * count);
And here is how it is used later:
CamResult result;
How do I convert this to C # code? I already tried something like:
[StructLayout(LayoutKind.Sequential)] struct CameraInfo { string camera_name; // camera head type string controller_name; // controller type string firmware_version; // firmware version int lib_id; // library ID int controller_id; // controller ID int camera_id; // camera ID public IntPtr handle; // handle to opened camera int status; // status (0 = available) } [DllImport("Cam.dll", EntryPoint = "CamDiscoverCameras")]
But in principle, I have no idea what I'm doing and what needs to be done next (for example, how a function should be defined, how to deal with this “interface” in C ++ code, whether the structure is correctly transformed, and so on).
source share