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.
Yes it does change how you address the function, but in this case you don’t need to qualify because you’re already inside
MyNamespace. So:Valid:
Invalid: