Go Premium for a chance to win a PS4. Enter to Win


Upgrading VC++ 1.53 app to VC++ 5.0

Posted on 1998-09-23
Medium Priority
Last Modified: 2012-05-04
Platform: Win95/Win32, Compiler: VC++ 5.0 (Visual Studio)

I have an application wich was made in Visual C++ v.1.53. It uses the VBX-control GRID.VBX to display data in grid-form.

Now I'm going to upgrade the app. to Visual C++ v.5.0, and had two immediate problems upon trying to build the converted app. (automatic upgrade in VC). The first was the _near keyword, wich I was told is obsolete, and that it just can be removed as it isn't neccesary in the Win32 development platform.

The second problem is the VBX-comtrol, wich I have to replace with the GRID32.OCX.

I'm a novice to C++, and C also, for that matter, and would like an easy to understand explanation to what steps I have to undergo to make this application work with the GRID32.OCX instead of the old VBX.

O.E. Auran
Question by:oddau
LVL 22

Expert Comment

ID: 1173541
I can confirm that just need to remove the near and far keywords.  Or you can use
#define _near
#define _far
to define them "nothing".  Then they won't cause problems and can be deleted more liesurely.

Expert Comment

ID: 1173542
Near and Far are not used in the win32 flat memory model. All data is automatically declared with far (32bit) access. This means that the near keyword does not apply and the far keyword might not give you any problems. It only determines where in memory the variables live and thus should not change the working of your code. (Local variables that are stored on the heap are a bit different but they will work so do not worry, since you claim to be a novice I will try not to go into too much detail)

The interfaces and fucntion calls should look much the same. If you are lucky you can just replace grid.vbx with grid32.vbx without too much effort. If the interfaces are the same (as they should be) the code will work without modification.

Expert Comment

ID: 1173543
Actually, that would be grid32.ocx

I've gone through the convertion the code for grid.vbx to grid32.ocx.  While most interfaces are the same, some are different, plus some Get/Set methods have changed a bit.  Unfortunately, I don't have the code of that now (I did that about 3 years ago with VC 4.0), but in general, it's not much trouble at all.
Industry Leaders: 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!


Author Comment

ID: 1173544
Hi, and thanks for the replies. I tried to add the GRID32.OCX, and got the classes for the control installed, however when trying to replace the visual control of the VBX with the new (OCX), GRID control, I got a message saying that I didn't have a runtime-licence for the control. That made me mad, and I replaced the GRID32.OCX with the MSFLEXIGRID control instead.

The methods for this OCX was quite similar, except for the syntax, and the conversion went well. (Apparently well, that is, I still haven't got the chance to see for myself).

The problem I now am left with is the .RemoveItem and the .AddItem methods.
The VBX-way to do this was to include a string parameter, and a integer for the rowindex.

This is not true with the FlexiGrid control however. I have tried to convert the int to a long, but this is not the way to do it either. The Visual Basic help topic for this control says the second parameter is a Long, and that it is optional.

The error I get is this:
  CREDITINFORM: C:\Program Files\DevStudio\MyProjects\VC\CreditInform\BenchMark\Sokresul.cpp
C:\Program Files\DevStudio\MyProjects\VC\CreditInform\BenchMark\Sokresul.cpp(132) : error C2664: 'AddItem' : cannot convert parameter 2 from 'long' to 'const struct tagVARIANT &'
C:\Program Files\DevStudio\MyProjects\VC\CreditInform\BenchMark\Sokresul.cpp(274) : error C2664: 'AddItem' : cannot convert parameter 2 from 'const int' to 'const struct tagVARIANT &'
Generating Code...
Error executing cl.exe.
Creating browse info file...

BenchMrk.exe - 2 error(s), 2 warning(s)

O.E. Auran


Author Comment

ID: 1173545
Do someone have the spesifics of the .AddItem method call on the MSFlexiGrid-control, and how to implement such calls? I don't get the meaning of the tagVariant parameter...

Pleez help now!

O.E. Auran
LVL 13

Expert Comment

ID: 1173546
struct tagVariant is of the dispatch type variant. The tag variant is just something that you can use for your own purpose. So if you do not use it you can pass a reference to a 0 pointer.
LVL 11

Accepted Solution

mikeblas earned 1500 total points
ID: 1173547
Mirkwood's comment is incoherent; please ignore it.

The parameters for the wrapper function generated by the gallery are LPCTSTR and a const VARIANT&.  If you read the documentation for this method on the control, you'll find that it takes two parameters: a string (which is the item) and an index, which is the item within the control where the new row is to be placed.

You need to construct a VARIANT that contains that information. A VARIANT is a structure which allows data to be passed safely from one OLE object to another. OLE requires this because it might have to step in and marshall the data--translate the data as it's being passed so it makes sense to both the giver and the receiver.

The documentation also says that the parameter is optional.  If you don't want to pass the parameter, you still have to make a variant--just make the variant empty. So, to pass nothing:

    COleVariant varEmpty;
    m_FlexGrid.AddItem("Column1\tColumn2", varEmpty);

to pass 35 as an 2-byte integer:

    COleVariant varNumber((short) 35, VT_I2);
    m_FlexGrid.AddItem("Column1\tColumn2", varNumber);

I used a cast to make sure I got the right COleVariant constructor. Since variants can handle so many types, the constructor is heavily overloaded and I have to be careful here.  The type of the variant is given by "VT_I2". If you look at the COLeVariant documentation, you'll see the other types available.

For other functions which require variants, you'll need to formulate the call and variant yourself. By reading the documentation for the control, you can deduce the type of variant you need from the context. For example, numbers are almost always VT_I2 or VT_I4.

B ekiM


Author Comment

ID: 1173548
This has been a question under construction, and I got a little help from most of the comments, and the answer from fellow biker Mike was satisfactory, although I recently found the answer for this from an other source. (I got tired of waiting).

So, thanks to everyone who made the effort!


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

772 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