Link to home
Start Free TrialLog in
Avatar of camejos
camejos

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And you may need to type cast as follows.

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_TRANSACTION), hwnd, (DLGPROC)TransactionDialogProc, NULL);
Avatar of NickRepin
NickRepin

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

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


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.
<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>

nils