Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unmanaged/managed interop - trouble passing int[]

I am working on my phd in chemistry and for that reason I need to write a software application to help me with the imaging of samples under a microscope. This microscope is fitted with an x-y-z nanopositioning stage. The stage is controlled using an unmanaged DLL written in VC++ by the hardware vendor. I could provide you with more specifics of needed but let me start with this;

One of the methods in the dll allows me to read settings for the axis of motion:

C++ syntax:

BOOL E7XX_qSVO (int ID, const char* szAxes, BOOL* pbValueArray) 

Where BOOL is int 0 or 1 according to the convention.

My C# wrapper contains:

[DllImport("E7XX_GCS_DLL.dll", EntryPoint = "E7XX_qSVO")]   
public static extern int qSVO(int iId, string sAxes, int []iValArray);

This seems correct to me. However when I try something like this in my main application (to query axis 1,2 and 3):

Int32 [] _iValues = new Int32[3];
E7XXController.qSVO(m_iControllerID, "123", _iValues);

I consistently get an array like this:

{6, 0, 10} while I should get {0, 0 , 0} according to the display on the device itself. The complementary function:

BOOL E7XX_SVO (int ID, const char* szAxes, const BOOL* pbValueArray) to set the same status bits on the stage also don't work...

Other commands in the dll work perfectly. I can pass strings and doubles in and out without troublem but not the BOOL type...

Do you guys have any idea what could be wrong?


1 Answers

BOOL in C++ is actually an "int" so make sure you use System.Int32 and not System.Boolean. Alternatively it might be using COM data types i.e. VARIANT_BOOL, in which case you need do need System.Boolean. Have you tried running dependency viewer to confirm the function prototype?

like image 71
Ady Kemp Avatar answered Dec 22 '25 23:12

Ady Kemp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!