Compiling windows apps (not using MFC) with .cpp extension

I am using Microsoft VC++ 5.0

I've been writing a windows app in C, recently I changed the file extension of the main project file to .cpp so I could use some handy classes I created a while ago. Everything was fine after the change except that the DialogBoxParam func will not compile (this worked fine before), the actual code in question is below along with the error.

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_TRANSACTION), hwnd, TransactionDialogProc, NULL);

error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'

will this conversion not work in c++? I can't imagine that I can't use a dialog box just because I am using the cpp complier
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is because C++ has stronger type check. The TransactionDialogProc function must match the following prototype.

  HWND hwndDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
And you may need to type cast as follows.

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_TRANSACTION), hwnd, (DLGPROC)TransactionDialogProc, NULL);
Nice shot :)
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Right on, "chensu", ... right on!!
"camejos" do you understand what "chensu" has done?  If you don't, this is your moment to ask questions.
nils pipenbrinckCommented:

I had the same problem yesterday night writing an example code for the c++ programming area :)

I've simply casted the function pointer to DLGPROC and it compiled...


nils pipenbrinckCommented:
the code line was:

  DialogBox (hInstance, "DIALOG_1", 0, DlgFunc);

the c++ version is:

  DialogBox (hInstance, "DIALOG_1", 0, (DLGPROC) DlgFunc);

If you are used to C programming, you will experience a lot of such things in C++ due to C++'s strong type check. The new C++ standard also introduces four type cast operators - static_cast, const_cast, reinterpret_cast and dynamic_cast.
Some of these cast operators are equivalent to playing with fire, which we know can cause severe discomfort.  For example, 'const_cast' allows 'const-ness' to be cast away.

C++ then goes one step further and in addition to 'const_cast', provides the storage class specifier 'mutable' as an alternative to 'const_cast'.  A 'mutable' data member is ALWAYS modifiable even in a 'const' member function or 'const' object.

Handle with care, or keep a lot of heartburn remedies nearby.
nils pipenbrinckCommented:
<offtopic, sorry>

I'm very glad about these new typecasting things..

you know.. when I really want to modify a const value I can do it.. using inline assembler or void * casting... the whole thing just makes it more portable.

</offtopic, sorry>

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.