Marshaling structure with pointer to array of strings


G

Guest

I am struggling with the following

How do I marshal/access a pointer to an array of strings within a structure

Than

Jef

----------------------------------------------------------------

namespace Win32Wrapper

...

/
typedef struct
unsigned long flag; // function rule
unsigned long timeout_msec; // maximum allowed tim
unsigned long version_major
unsigned long version_minor
my_tag_list_t *taglist; // pointer to tag lis
unsigned int start_tag; // first tag to be processe
unsigned int end_tag; // last tag to be processe
unsigned int valid_tags; // number of valid taglist entrie
unsigned int max_tags; // maximum size of taglis
signed long status; // overall function statu
signed long *istatus; // pointer to input status lis
signed long *ostatus; // pointer to output status lis
signed long **field_status; // pointer to array of arrays of statu
signed long **field_status_save;// pointer to saved field_statu
unsigned long select_list_number; // the selection list numbe
char *select_equation; // pointer to select lis
unsigned int fields; // number of field name
char **field_name; // pointer to arrays of name
void **tag_field_value; // pointer to array of arrays of value
void **field_value; // pointer to array of constant value
my_physadrs_t **physadrs; // pointer to array of arrays of addres
my_physadrs_t **physadrs_save; // to saved physadr
my_access_ids_t **access_ids; // ptr to array of lists of stuf
void *custom_table; // ptr to config dat
char *cust_file_name; // ptr to name of vendor-specific cfg fil
} myType2
*
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)
public class myType2
public uint flag; // function rule
public uint timeout_msec; // maximum allowed tim
public uint version_major
public uint version_minor
public IntPtr taglist; // pointer to tag lis
public uint start_tag; // first tag to be processe
public uint end_tag; // last tag to be processe
public uint valid_tags; // number of valid taglist entrie
public uint max_tags; // maximum size of taglis
public int status; // overall function statu
public IntPtr istatus; // pointer to input status lis
public IntPtr ostatus; // pointer to output status lis
public IntPtr field_status; // pointer to array of statu
public IntPtr field_status_save; // pointer to saved field_statu
public uint select_list_number; // the selection list numbe
public IntPtr select_equation; // pointer to select lis
public uint fields; // number of field name
public IntPtr field_name; // pointer to array of field name
public IntPtr tag_field_value; // pointer to array of value
public IntPtr field_value; // pointer to array of constant value
public IntPtr physadrs; // pointer to array of addresse
public IntPtr physadrs_save; // to saved physadr
public IntPtr access_ids; // ptr to array of lists of stuf
public IntPtr custom_table; // ptr to config dat
public IntPtr cust_file_name; // ptr to name of cfg fil
} // myType

public class RfidWrapper

...

/
EXPORT_CFUNC signed long EXPORT_STDCALL GetFieldNames(myType1 *aType1, myType2 *aType2, signed long *status)
*
[DllImport("D:\\Progra~1\\Intermec\\Intell~1\\it500.dll")
public static extern int GetFieldNames([In, Out] myType1 aType1, [In, Out] myType2 aType2, out int Status)

....

} // public class Win32Wrapper
} // namespace MyStuff


// Calling program
....
rc = Win32Wrapper.GetFieldNames(aType1, aType2, out nStatus);

//
// How do I marshal aType2 to access field_name[] that is an array of strings???
// i.e. aType2.field_name[valid_tags]
//
....
 
Ad

Advertisements

M

Mattias Sjögren

Marshal.ReadIntPtr() to retrieve one of the string pointers in the
array, then call Marsahal.PtrToStringAnsi() with the pointer to get
the string.



Mattias
 

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