1

I am programming a software in C# to control and receiving images from a spectral camera that uses cameralink interface, using a Framegrabber of Matrox company and the ActiveMIL libraries. I am using Visual Studio 2008.

The library gives ActiveX controls to receive and displaying camera images in a control window, but I need to pass the data loaded by the control to my own array.

The library gives me the following method to make this:

void object.Get{
     ref Array UserArray,
     ImFormatConstants Format,
     ImBandConstats Band,
     int OffsetX,
     int OffsetY,
     int SizeX,
     int SizeY
     }

Then, I wrote my code as follow:

Object IMG = new Object[256*320]; //Size of image is 256 rows and 320 columns
axMImage1.Get(ref IMG, Matrox.ActiveMIL.ImFormatConsts.imPlanar, Matrox.ActiveMIL.ImBandConstants.imAllBands, 0, 0, 320, 256);

When I execute this code, I get the following error:

An invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the CLR can cause unexpected exceptions, corruption or data loss

Can you help me to understand the error?

NOTE: the parameters functions says that the first parameter is an Array passed by reference, but if I use and declare an Array as follow:

Array[] IMG = new Array[256*320];

I receive the following error:

Argument '1': cannot convert from 'ref System.Array[]' to 'ref object'

Thanks.

  • 1
    Is the library managed c# or unmanaged c++? You cannot take managed c# objects and just pass to c++. – jdweng Dec 13 '19 at 13:11
  • Hi jdweng. I ran **corflags** tool to the library I am using, following the link [link](https://stackoverflow.com/questions/5275985/is-this-dll-managed-or-unmanaged) and I can say after that the dll is managed. Regards. – leandro.prog Dec 16 '19 at 13:20
  • If it is a manged library you do not need DllImport. Instead add existing item to project and browse to the dll. Then add a top of module the "using" statement for the namespace of the dll and the classes you are using. ActiveX libraries are not managed. ActiveX Microsoft tried to obsolete in 2004 (VB4 and C++ Version 4) but people are still using. This was prior to the Managed VS releases. I wouldn't use any libraries before Net 3.5 (late 2008). Net 3.0 originally came out with a lot of bugs and quickly Microsoft fixed the bugs and came out with Net 3.5. – jdweng Dec 16 '19 at 13:33

0 Answers0