Before when I tried to make a window wrapper class, I learned that you cannot pass a dialog procedure to CreateDialogParam() that is in a class, because it being a class member changes the signature and therefor doesn't match that of DLGPROC. I used a workaround where all dialogs used one global procedure that used a map to find the class member procedure from the window handle passed to the global procedure. It would find the correct class pointer in the map, and pass the arguments to its procedure and return the result.
Now I am using this same method, but, in this project everything is going to be in a namespace. Is this valid?
namespace MyNamespace
{
INT_PTR MyProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
return 0;
}
class MyDlg
{
public:
HWND hwnd;
MyDlg(void) {
hwnd = CreateDialogParam(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_MYDLG),
HWND_DESKTOP,
(DLGPROC)MyProc, // Maybe 'MyNamespace::MyProc'?
NULL
);
}
};
}
I'm not sure if namespaces change the function type signature like classes do.
MyProcincorrectly. The compiler error was trying to tell you that, but you appear to have cast the error message away. Now your code compiles, but it will also corrupt memory.CALLBACKin the return type ofMyProc, my mistake.