Convert C# struct to VARIENT

Joined
Nov 26, 2009
Messages
1
Reaction score
0
I got an ArgumentException while calling
Marshal.GetNativeVariantForObject(segInfo, resultVar);

The exception detailis {"Value does not fall within the expected range."}


I have a C# struct as follows

[StructLayout(LayoutKind.Sequential)]

public struct segmentInfo_st

{ public int nSegID;

public int nSegFillOrder;

public int nSelectFlag;

public int nGraficDispFlag;

public int nImgTextDispFlag;

public int nScalBarDispFlag;

public int nShutterDispFlag;

public int nSummaryFlag;

public int nNoteFlag;

public ArrayList segList;

}



I tried it to convert to VARIENT using Marshal.GetNativeVariantForObject


like
IntPtr resultVar;

segmentInfo_st segInfo = new segmentInfo_st();

segInfo.nSegID = 1;

int sz = Marshal.SizeOf(typeof(segmentInfo_st));

resultVar =
Marshal.AllocCoTaskMem(sz);



Marshal.GetNativeVariantForObject(segInfo, resultVar);

Expecting early help .

Thanks & regards,
Dileep S

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top