• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Converting C/C++ Types with Union Structs to VB types

I am trying to convert the following C type definition into a VB type, but I don't know how to handle the UNION part of the Definition

typedef struct lineinitializeexparams_tag {  DWORD  dwTotalSize;
  DWORD  dwNeededSize;  DWORD  dwUsedSize;  DWORD  dwOptions; union {
  HANDLE  hEvent;  HANDLE  hCompletionPort; } Handles;  DWORD  dwCompletionKey;



1 Solution
In this case since both elements of the union have the same type (HANDLE = Long in VB) you shouldn't have a problem. Just declare the type like so:

Private Type MyType
  dwNeededSize As Long
  dwUsedSize As Long
  dwOptions As Long
  hHandle As Long
  dwCompletionKey As Long
End Type

Now in C/C++ you can access the hEvent and hCompletionPort elements independently although they still reside in the same space in memory. In VB since it doesn't support a "union" structure, you just have to access hHandle and know whether is a handle to an event or a handle to a completion port.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now