473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MarshalAs for DWORD array?

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
2 5068
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: __PPS__ | last post by:
Actually what I mean is that - if I have some memory buffer, lets say char a; and then I do like this: DWORD num = 0x1234; *(DWORD*)a = num; (1) *(DWORD*)(a+1) = num; (2) either...
0
by: Bob | last post by:
I have an old project written in VC++ that I want to convert to C#. In the old project I have a structure that has an array within it that is predefined to be 10 elements long. Anyway, I had issues...
0
by: [Yosi] | last post by:
I have DLL (unmannaged code) , in this DLL I have some functions and structures. one of those functions is GetDataBaseStructure (GDS_Structure *str), the structure definition is as following : ...
1
by: Gabest | last post by:
Running this piece of code while having the sse optimization turned on (vcnet2003), something really strange happens I cannot explain. Without sse it is giving me the right results. float f =...
7
by: monkeydragon | last post by:
how to would you transfer a DWORD variable from inside of a function to the caller ex. InvokeProcessData(LPDWORD prtDW) { ... // we have created, initialized and processed // dword variable...
4
by: Virajitha Sarma | last post by:
Hi, I have a code in C which i am rewritting it in C#. I am facing problem with the following two lines : char *cipher; (DWORD*)cipher(C) and (uint*)cipher(C#) are giving different values...
0
by: Piotrekk | last post by:
Hi I have an dword array returned by send message with TBM_GETPTICS Message. Thus i need to convert IntPtr to managed block of memory ( Int32 because od dword ). I tried saveral ways but it...
1
by: =?Utf-8?B?VGhvbWFzUg==?= | last post by:
Hi together, I have following little problem with a structure which I need for unmanaged code: Public Structure Info Public Header As HeaderInfo ...
3
by: O.B. | last post by:
Below is a program that shows a test for marshaling data from a byte array to a class structure. Unfortunately, there are two annoying problems (bugs?) that I can't seem to get around. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.