Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
Issues of 64-bit code in real programs:…

Issues of 64-bit code in real programs: virtual functions

Sep 15 2009
Author:

We have already written in our articles about one of the problems of code migration to 64-bit systems relating to incorrect overload of virtual functions. For example, our article "20 issues of porting C++ code on the 64-bit platform" was published in March, 2007 (although is still relevant). It described the issue of virtual functions.

The point of the problem consists in the following. There is CWinApp class in MFC library which has WinHelp function:

class CWinApp {
  ...
  virtual void WinHelp(DWORD dwData, UINT nCmd);
};

This function must be overlapped to allow showing its own Help in a user application:

class CSampleApp : public CWinApp {
  ...
  virtual void WinHelp(DWORD dwData, UINT nCmd);
};

Everything went alright until 64-bit systems appeared. And MFC developers had to change the interface of WinHelp function (and some other functions) in this way:

class CWinApp {
  ...
  virtual void WinHelp(DWORD_PTR dwData, UINT nCmd);
};

In 32-bit mode DWORD_PTR and DWORD types coincided but in 64-bit one... Of course developers of user applications, too, had to change the type to DWORD_PTR for correct overload but the compiler did not inform about this and the error appeared only at the stage of testing when Help system began to behave "mysteriously". To learn the details I refer you to the article mentioned above.

What made me recall this error? The fact that now, in the end of 2009, this error is still present in the code of real applications. You doubt?

There is an excellent component library BCGControlBar. You must have heard about it because the components by BCGSoft Ltd are included into Microsoft Visual Studio 2008 Feature Pack. So, if you download the demo-version of this library, install it and search the word "WinHelp" through .h-files... you will see that everywhere this function is supposedly overlapped, DWORD parameter is used instead of DWORD_PTR. And this means that Help system in these classes will behave incorrectly on a 64-bit system.

Can it really be true that this error is still in the code of such a popular library? I think the point is that the company's clients have access to source codes of this library and they can always introduce some corrections into it. Besides, WinHelp function is used very rarely nowadays. HtmlHelp is much more popular. And it does have the right parameter DWORD_PTR in BCGControlBar. But the fact remains: there is an error in a real code and the compiler will not detect it.

What to do? Use PVS-Studio :-) . For our analyzer has been able to detect such errors from its very appearance, and Help system includes a detailed example (see description of error V301).

Popular related articles


Comments (0)

Next comments next comments
close comment form