?
Solved

Converting C code to VB code

Posted on 2003-03-07
7
Medium Priority
?
183 Views
Last Modified: 2010-04-07
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
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
7 Comments
 
LVL 6

Expert Comment

by:marconovaro
ID: 8086937

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
 
LVL 6

Expert Comment

by:marconovaro
ID: 8086952

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
 
LVL 7

Accepted Solution

by:
Smallint earned 1000 total points
ID: 8086965
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!

 
LVL 6

Expert Comment

by:marconovaro
ID: 8087011

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
 
LVL 7

Expert Comment

by:Smallint
ID: 8087251
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8087880
hearing...
0
 

Author Comment

by:azsoft
ID: 8101021
I have second question which is continue from this one. Please looks into it and help me.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

752 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