Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Issues of 64-bit code in real programs:…

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

15 Sep 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

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam