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

Converting C code to VB code

Can somebody help me to rewrite the following C code to VB.

SRCONTROL srcontrol;
CTRLCONFIG *pCtrlConfig = &srControl.command.config;

and this is structure

typedef struct tagSRCONTROL
{
  ULONG nID;
  CTYPE command;
}SRCONTROL;

typedef union tagCTYPE
{
  CEVENT event;
  CTRLCONFIG config;
}CTYPE;

typedef struct tagCTRLCONFIG
{
  USHORT parity;
  USHORT stopbits;
}CTRLCONFIG;

0
azsoft
Asked:
azsoft
1 Solution
 
marconovaroCommented:

I guess this will be not possible, since VB does not have any equivalent structure for a union...

Furthermore, VB types are always signed, and I think that your "ULONG2 and "USHORT" are all unsigned types.

This could be the translation (without the union):

Public type CTRLCONFIG
   parity as byte
   stopbits as byte
End Type

Public Type SRCONTROL
  nId as long
  command as CTYPE
End Type


M
0
 
marconovaroCommented:

Also, this

SRCONTROL srcontrol;

shall be converted to:

Dim srcontrol as SRCONTROL

But you can't translate this:

CTRLCONFIG *pCtrlConfig = &srControl.command.config;

to VB since VB does not have pointers...
There is no way of finding the address of the variable.

But, a question to you: what are you trying to do? Maybe I can help you more...
M
0
 
SmallintCommented:
Nearest to C I think is possible in VB:

Private Type CTRLCONFIG
 parity As Integer
 stopbits As Integer
End Type

Private Type CTYPE
 'event As CEVENT
 config As CTRLCONFIG
End Type

Private Type srcontrol
 nID As Long
 command As CTYPE
End Type


Dim srcontrol As srcontrol
Dim pCtrlConfig As CTRLCONFIG

pCtrlConfig = srcontrol.command.config
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
marconovaroCommented:

Smallint: that is correct, but it is the "literal" translation ... :-)

The CTYPE will be not the same structure, because in C is declared as an union...
This:

pCtrlConfig = srcontrol.command.config

is correct, but he will have the full structure, and not only a pointer to it (depends on the use he needs).

Regards
M
0
 
SmallintCommented:
You are right marconovaro, it's a "literal" translation.

Of course CTYPE will not be the same. CEVENT, if i'm not wrong is a class in C++ ... and pointers don't exist, magic is not possible, as you can see I have written "nearest" ;)

Only a comment, there is a way in VB6 to find address of a variable. There are three "undocumented" functions named varptr, strptr and objptr that return adresses of variables, strings and objects. I use these functions when I use API calls, move memory blocks and this kind of things VB is not thought... very useful.

Cheers
0
 
Richie_SimonettiIT OperationsCommented:
hearing...
0
 
azsoftAuthor Commented:
I have second question which is continue from this one. Please looks into it and help me.
0

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