tags:

views:

61

answers:

0

Hi everyone, I've strange problem:

the MFC structure is

#define SENSOR_DESC_LEN   30
#define CAM_ID_LEN        20  
typedef struct
{
 unsigned int SensorType;
 char         Desc[SENSOR_DESC_LEN];
 unsigned int CommType;  // USB or TCP - COMM_TYPE
 float        FirmwareVersion;
 float        HardwareVersion;
 int          Width;
 int          Height;
 int          ActiveStartX;
 int          ActiveStartY;
 char         CameraID[CAM_ID_LEN];
 unsigned int pCam;
 char         Color;
} CAMERA_CAP_API; 

the corresponding C# structure is:

[StructLayout(LayoutKind.Sequential)]
  public struct CAMERA_CAP_API
  {
    public uint SensorType;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
    public byte[] Desc;
    public uint CommType;
    public float FirmwareVersion;
    public float HardwareVersion;
    public int Width;
    public int Height;
    public int ActiveStartX;
    public int ActiveStartY;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
    public byte[] CameraID;
    public uint pCam;
    public sbyte Color;
  } ;

it is correct - I can pass this structure through DLL using the following signature:

[System.Runtime.InteropServices.DllImport("Camelot.dll", EntryPoint = "CamGetCamCaps", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
    public static extern int CamGetCamCaps(int nCamNum, ref CAMERA_CAP_API CameraCap);

The problem is in ActiveX. (MFC)

I make the parameter as VARIANT. And it shows as object in C# side. however trying to pass the same structure to object fails:

object c = new CAMERA_CAP_API();
Camera1.GetCamCaps(ref c);  // Camera1 is the ActiveX control

I get the following error: An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: Value does not fall within the expected range.

I've also tried:

IntPtr ptr = Marshal.AllocCoTaskMem(200);
GetNativeVariantForObject...
  • without success.

I get the same error.

What is the problem?