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;



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.