PC Review


Reply
Thread Tools Rate Thread

Pointer to integer into structure...

 
 
=?Utf-8?B?Y2xvcmVudHNvbg==?=
Guest
Posts: n/a
 
      22nd Feb 2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2xvcmVudHNvbg==?=
Guest
Posts: n/a
 
      22nd Feb 2005
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Void pointer and structure pointer Nasif Microsoft C# .NET 3 20th Jun 2008 06:55 PM
C# P/Invoke to pass pointer-to-pointer-to-structure (**pPtr) to C =?Utf-8?B?YnJja2Nj?= Microsoft C# .NET 0 30th Nov 2004 11:29 PM
Re: Copying unmanaged memory pointer of structure to managed structure array Mattias Sjögren Microsoft VC .NET 0 28th Aug 2004 04:19 PM
Passing pointer to integer in sub Matijaz Microsoft Dot NET Compact Framework 2 2nd Jul 2004 12:02 PM
creating a nullable integer structure giant food Microsoft VB .NET 3 21st Oct 2003 07:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.