By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,733 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,733 IT Pros & Developers. It's quick & easy.

MarshalAs for DWORD array?

P: n/a
Hi,
I have some VB6 code that calls unmanaged DLLs, and I am converting it to
C#. There's a couple of structs I need to define. I've had no problems with
this one:

Public Type A
sz(128) As Byte
End Type

The above VB6 translates happily into C# as the following:

public struct A {
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=128)]
public string sz;
}
However, I'm not sure what to do with this one:

Public Type B
dwData(34) As Long
End Type

I'm sure dwData(34) is a DWORD array of lengh 34, and a DWORD is a 32-bit
unsigned integer, so I tried this:

public struct B {
[MarshalAs(UnmanagedType.U4,SizeConst=34)]
public uint dwData;
}

Unfortunately, it isn't working. How should I define a DWORD array in C#?
Any help would be appreciated!

Paul
Oct 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
However, I'm not sure what to do with this one:
>
Public Type B
dwData(34) As Long
End Type
I'm sure dwData(34) is a DWORD array of lengh 34, and a DWORD is a
32-bit unsigned integer, so I tried this:

public struct B {
[MarshalAs(UnmanagedType.U4,SizeConst=34)]
public uint dwData;
}
Unfortunately, it isn't working. How should I define a DWORD array in
C#? Any help would be appreciated!
Use the UnmanagedType.ByValArray enumeration element like this:

public struct B {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmangedType.U4, SizeConst=34)]
public uint[] dwData;
}

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 16 '06 #2

P: n/a
Hi,
Finally got my code working. Thanks a lot for your help! I was actually
still having a lot of trouble until I found out that a Long in VB6 is only
32-bit!! I made leaps of progress when I changed my C# longs to ints!

Paul
Oct 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.