VB to C++ conversion

A

Alex

I need to transfer a Visual Basic program to C++ (stop laughing at the
use of VB, as I didn't write it). The program in question is ~3500
lines long, so it would be VERY unpleasant to convert it by hand. In
adition, only the sintax on a line to line basis needs be transfered as
this program is almost entirely computational, no UI or anything more
complicated than If, For, Case and While statements. Essentially, I am
looking for a sintax converter. Does anyone know of any?
 
P

Phlip

Alex said:
I need to transfer a Visual Basic program to C++ (stop laughing at the
use of VB, as I didn't write it). The program in question is ~3500
lines long, so it would be VERY unpleasant to convert it by hand. In
adition, only the sintax on a line to line basis needs be transfered as
this program is almost entirely computational, no UI or anything more
complicated than If, For, Case and While statements. Essentially, I am
looking for a sintax converter. Does anyone know of any?

If the program is purely computational, follow this strategy. Download a
light C++ unit test rig, such as NanoCppUnit or CppUnitLite.

(CppUnit itself is hard to use, and somewhat derivative.)

Write a test case that calls system() or popen(), and calls the legacy VB
program's executable.

Pass to that program its simplest possible input. Collect the output into a
string, or something, and parse out its numbers.

(At this point, if you are completely adept at ActiveX, you could build a
DLL in VB and call it from ATL in C++, but don't even start without at least
a year's experience in COM in C++...)

Now your test case is going to call a new C++ function, that does not exist
yet. Pass into the function that same simplest input, and collect its
output. Write an ASSERT_EQUAL() statement that matches the new output to the
legacy output.

Run the test and predict failure.

Now add the minimum amount of C++ code required to pass that test.

Write another test case, and repeat this procedure for each of the source
code's abilities.

Stop occassionally to refactor the C++, running the tests after the fewest
possible edits. Extract duplicated statements into new methods. Along this
process, objects may appear. They might not be the same as the objects in
the legacy VB code. This is a good thing.

I used that technique, between BASIC and Ruby, to extract an old LParser
algorithm and produce this project:

http://flea.sourceforge.net/
 
I

Ioannis Vranos

Alex said:
I need to transfer a Visual Basic program to C++ (stop laughing at the
use of VB, as I didn't write it). The program in question is ~3500
lines long, so it would be VERY unpleasant to convert it by hand. In
adition, only the sintax on a line to line basis needs be transfered as
this program is almost entirely computational, no UI or anything more
complicated than If, For, Case and While statements. Essentially, I am
looking for a sintax converter. Does anyone know of any?


If your program is written in VB .NET, then you may encapsulate it to a
class (if it isn't), and make it a .NET dll which will be callable from
C++ (and any other .NET language).

Then you can continue developing it in C++.
 
P

Phlip

Ioannis said:
If your program is written in VB .NET, then you may encapsulate it to a
class (if it isn't), and make it a .NET dll which will be callable from
C++ (and any other .NET language).

Then you can continue developing it in C++.

Doesn't that give you the choice of either Managed C++ or #import and all
the COM wrapper stuff?
 
A

Alf P. Steinbach

* Alex:
I need to transfer a Visual Basic program to C++ (stop laughing at the
use of VB, as I didn't write it). The program in question is ~3500
lines long, so it would be VERY unpleasant to convert it by hand. In
adition, only the sintax on a line to line basis needs be transfered as
this program is almost entirely computational, no UI or anything more
complicated than If, For, Case and While statements. Essentially, I am
looking for a sintax converter. Does anyone know of any?

Since nobody's mentioned this yet, there are VB to Java converters, and
there are Java to C++ converters. Google (I did, earlier, but got
sidetracked by something else). Probably it won't work but might be
worth a try -- let us know... :)
 
I

Ioannis Vranos

Phlip said:
Doesn't that give you the choice of either Managed C++ or #import and all
the COM wrapper stuff?


I did not understand the question. May you explain what do you mean?

As a note, "Managed C++" is not the official term (although this term is
also used even in some MS sites). The official term is "managed extensions".

In the current version of VS, ISO C++ code compiles in CLR mode, however
you can not use all ISO C++ features on managed types.

Things will improve in VS 2005 (templates will be able to be used on
managed types along with generics), and vastly improve in the release
after that.


In any case, ISO C++ code compiles everywhere including .NET.
 
I

Ioannis Vranos

Ioannis said:
I did not understand the question. May you explain what do you mean?


I rechecked it and I think you mean that it leaves us with either
"managed extensions" (and upcoming C++/CLI which will replace them), or
COM and other unmanaged stuff.

Actually this is not exactly the case. It leaves us with either "managed
extensions" *and* ISO C++, or ISO C++ and the other unmanaged stuff.

More precisely, the other unmanaged stuff can also be compiled in
managed mode.


However ISO C++ can be entirely managed and this will be the case in the
upcoming releases, since also C++ becomes the systems programming
language of .NET!

An example using the current Beta of VC++ 2005:


inline int add(int x, int y) { return x+y; }


int main()
{
int a=add(1,2);
}


C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.41013
for Microsoft (R) .NET Framework version 2.00.41013.0
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.41013
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>




The /clr:safe means that this code is 100% CLR verified and thus is
binary portable to all CLI VMs (Mono, DotGNU, etc). That is, it is pure
CLI bytecode.


It does not contain any native code.
 
P

Phlip

Ioannis said:
It does not contain any native code.

I just meant that either the OP must learn the old-fashioned #import stuff,
commonly called "ATL", or they must bond their application with .NET just to
get a link between a VB module and a C++ one.

OTOH it sounds like Microsoft _finally_ invented a p-code they can live
with...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top