Improve company productivity with a Business Account.Sign Up

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

Upgrading VC++ 1.53 app to VC++ 5.0

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
1 Solution
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.
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.
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.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

oddauAuthor Commented:
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

oddauAuthor Commented:
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
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.
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

oddauAuthor Commented:
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!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now