Solved

Upgrading VC++ 1.53 app to VC++ 5.0

Posted on 1998-09-23
8
385 Views
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.

WR
O.E. Auran
0
Comment
Question by:oddau
8 Comments
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 2

Expert Comment

by:gysbert1
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.
0
 
LVL 2

Expert Comment

by:shchuka
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.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Author Comment

by:oddau
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)
---

WR
O.E. Auran

0
 
LVL 1

Author Comment

by:oddau
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
0
 
LVL 13

Expert Comment

by:Mirkwood
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.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 500 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

0
 
LVL 1

Author Comment

by:oddau
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!

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

776 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