Not sure if this will make a difference in your case, but it's worth a
shot.

I have my structs for unmanaged C++ calls declared as such:

Note, the LayoutKind parameter. Also should note the differences between
VC++ data types and C# data types. 

long and int in VC++ both correspond to int in C#, etc.

[Guid( "..." ), StructLayout(LayoutKind.Sequential)]
public struct MyStruct{
        public short Rows;
        public short Cols;
        public short Padding1;
        public short Padding2;
        [MarshalAs(UnmanagedType.ByValArray,SizeConst=128)]
        public double[] Vals;
}

> -----Original Message-----
> From: Ron Young [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, February 25, 2003 1:25 PM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Need help with a P/Invoke function
> 
> 
> Hello all,
> 
> If someone could help me out with this, I'd appreciate it very much.
> 
> I have this function signature in a Win32 .dll:
> 
> S32 AIL_enumerate_filter_attributes( HPROVIDER filter, 
> HINTENUM *next, RIB_INTERFACE_ENTRY *dest )
> 
> the RIB_INTERFACE_ENTRY is a struct defined like so:
> 
> struct RIB_INTERFACE_ENTRY
> {
>    char const * entry_name;
>    int type;
>    int subtype;
> }
> 
> I've attempted to define the struct in C# like so:
> 
> public struct RIBInterfaceEntry
> {
>     [MarshalAs( UnmanagedType.ByValTStr, SizeConst=128 )]
>     public string name;
>     int entrytype;
>     int subtype
> }
> 
> and wrapped the c++ method like so:
> 
> [DllImport( "mss32.dll", 
> EntryPoint="AIL_enumerate_filter_attributes" )]
> private static extern int EnumFilterAttributes( IntPtr 
> filter, ref int next, ref RIBInterfaceEntry dest );
> 
> and call it like:
> 
> IntPtr next = 0;
> 
> public RIBInterfaceEntry[] GetFilterAttributes( DigitalFilter filter )
> {
> while ( true )
> {
>     RIBInterfaceEntry entry = new RIBInterfaceEntry();
>     if ( EnumFilterAttributes( filter.Handle, ref next, ref 
> entry ) == 0 ) break;
>     // add the entry to an arraylist
> }
> 
> // return arraylist.ToArray()
> }
> 
> The DigitalFilter is another struct populated from another 
> unmanaged call which holds all the available filters for a 
> digital audio driver. When the app is run, and the 
> GetFilterAttributes() method called, I don't get any run-time 
> arrays, and stepping through the code shows the 
> RIBInterfaceEntry[] array has a length of 2, but the 
> individual properties of a specific entry don't seem right. 
> The "Name" property has what appears to be a null terminator 
> in it, and the 2 int properties are 0 (which is a valid value 
> for the struct). But I was hoping to at least see a 
> descriptive name of the entry, as in a C++ application I have 
> that does basically the same thing (enumerates attributes, 
> printf them to console window).
> 
> Thanks again, and in advance for any advice.
> 
> Ron
> 

Reply via email to