Solved

c declaration in vb - (structure)

Posted on 2001-06-13
10
205 Views
Last Modified: 2010-05-02
how to declare the following c structure in vb

typedef struct tagVBPARAM
{
    UINT nParam;
    ULONG nStatus;
}
VBPARAM;
0
Comment
Question by:azsoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6187085
Type tagVBPARAM
  nParam As Integer
  nStatus As Long
End Type
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187113
Tim, I think UINT is 32 bit and ULONG is 64 bit.  I was thinking it would be:

Type tagVBPARAM
 nParam As Long
 nStatus As Double
End Type

But there are definitely problems reading the binary unsigned integer from a floating point var.
0
 

Author Comment

by:azsoft
ID: 6187312
what happen to the VBPARAM on the last line.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Accepted Solution

by:
Joebob earned 50 total points
ID: 6187429
typedef struct tagVBPARAM
{
   UINT nParam;
   ULONG nStatus;
}
VBPARAM;

UINT = Unsigned Integer - 16bits on 16bit machine, 32bits on 32bit machine
ULONG = Unsigned Long - Always 32 bits

Type VBPARAM
    nParam as Long
    sStatus as Long
End Type

VB doesn't support unsigned values so the variable ranges will no go from 0 to 4294967295, they will go from -2147483648 to 2147483647.

The C++ structure you show has 2 names, tagVBPARAM and VBPARAM.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187467
>The C++ structure you show has 2 names, tagVBPARAM and VBPARAM.

More that there is a declared instance of the structure.  In VB:

Dim VBPARAM as tagVBPARAM
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6187500
I am with Paul.
Cheers
0
 
LVL 3

Expert Comment

by:Joebob
ID: 6187768
The C++ structure has 2 different names.  The VBPARAM is not a variable of type tagVBPARAM, it is the type tagVBPARAM.

If you had the exact c declaration in VB, you would be able to do the following with exactly the same results.
   DIM t1 as tabVBPARAM
   DIM t2 as VBPARAM

VB doesn't support assigning multiple type names to the same data type and I have never found a place where doing it in C is benefitial.  To have the exact same thing in VB you would do the following, but my first post should be all you need.
----------------------------------------------
Type VBPARAM
   nParam as Long
   sStatus as Long
End Type

Type tagVBPARAM
   nParam as Long
   sStatus as Long
End Type
----------------------------------------------
Notice that the type is declared twice, once for each name that the C declaration used.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187816
Ah you're right JoeBob.  I confused typedef with a simple struct definition.  Mebad.
0
 
LVL 3

Expert Comment

by:Joebob
ID: 6192280
How is that a "B" answer?  I gave you exactly what you asked for plus a little extra info.  You can copy and paste my answer into your VB app and it will work.
0
 

Author Comment

by:azsoft
ID: 6196046
Joebob, thank you very much. I wish i could change the score to A.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question