The solution I found and implemented was:
myInt
IntPtr p_myInt = Marshal.AllocHGlobal(Marshal(SizeOf(myInt.GetType()));
Marshal.WriteInt32(p_myInt, 0); // to initialize
....function call
myInt = Marshal.ReadInt32(p_myInt);
Carl
"clorentson" wrote:
> How do I get a pointer to an integer into an IntPtr in a structure? I have a
> native structure like this:
>
> typedef struct {
> DCM_ELEMENT e;
> long flag;
> long *flagAddress;
> } DCM_FLAGGED_ELEMENT;
>
> Going into the native function:
> CONDITION
> DCM_ParseObject(DCM_OBJECT ** callerObject, DCM_ELEMENT * vector,
> int count, DCM_FLAGGED_ELEMENT * flaggedVector, int flagCount,
> int *parseCount)
>
> This is what I have in C# so far:
>
> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
> public struct DCM_FLAGGED_ELEMENT
> {
> DCM_ELEMENT e;
> int flag;
> IntPtr flagAddress;
> public DCM_FLAGGED_ELEMENT(DCM_ELEMENT elem, int fl, IntPtr pfl)
> {
> e = elem;
> flag = fl;
> flagAddress = pfl;
> }
> }
>
> and the C# function prototype is:
>
> [DllImport("DICOM_Lib.dll", CharSet = CharSet.Ansi)]
> public static extern UInt32 DCM_ParseObject(
> ref IntPtr callerObject,
> [MarshalAs(UnmanagedType.LPArray)]
> DCM_ELEMENT[] requiredVector,
> int count,
> [MarshalAs(UnmanagedType.LPArray)]
> DCM_FLAGGED_ELEMENT[] optionalVector,
> int flagCount,
> IntPtr parseCount);
>
>
> But how do i actually get the address of an integer into the IntPtr
> flagAddress?
>
> Thanks,
> Carl
|