Click here to Skip to main content
14,691,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an MDI created and it works until I press on menu new file and I get this error message I wrote on message box.. that the New MDI child creation failed this is the part where the compiler says Local mcs. szClass "Cannot acces memory at adress 0xcdbaabcd"

HWND CreateNewMDIChild(HWND hMDIClient)
    HWND hChild;

    mcs.szTitle     = "Act 1";
    mcs.szClass     = ChildClass;
    mcs.hOwner      = GetModuleHandle(NULL);
    mcs.x =  = CW_USEDEFAULT;

    hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
        MessageBox(hMDIClient, "Act 1 MDI child creation failed !", "Error", MB_ICONERROR | MB_OK);
    return hChild;

What I have tried:

I didn't try anything because the compiler doesn't give me any errors ..
and if the entire code is needed I can uploaded right away...

Well I did ask someone and told me this would be the issue:
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);

It means I did a bad cast...?!
What will be look like?

hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, reinterpret_cast<LPARAM>(&mcs));
Updated 15-May-20 6:29am
Richard MacCutchan 15-May-20 11:02am
"the compiler says Local mcs. szClass "Cannot acces memory at adress 0xcdbaabcd""
That is not a compiler message, but a runtime exception. Where exactly does that occur and what is "ChildClass"?

This someone is right the LONG is truncating the value and so a simple cast to LPARAM is enough.

So this should work when your hMDIClient is a good citizen.
M@gelearn 15-May-20 11:04am
Well i did change that and doesn't change anything.. the child window refuse to create.. :(
Richard MacCutchan 15-May-20 11:05am
LONG and LPARAM are both the same size. Oops - only in 32 bit.
M@gelearn 15-May-20 11:21am
yes my compiler is 32 bit... IF 64 I would use the LPARAM well that's what the function expectes.

hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
but hey.. that someone I have mention has solved my problem.
I just give him the hole code.. well in poor words i didn't register the MDI child window at the WM_CREATE.. and ofc. the window can't show up.. but the problem was that the compiler didn't gave me any errors .. that was the real problem so.. i just forgot to put this ..

// registering MDI after client window is made here!


<pre>case WM_CREATE:
		/// Create MDI client ///////////////////////////////////

		////////// Find window menu where children will be listed

		ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 2);
		ccs.idFirstChild = ID_MDI_FIRSTCHILD;

		hMDIClientWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
			hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);

		if (hMDIClientWindow == NULL)
			MessageBox(hwnd, "Could not create MDI client !", "Error", MB_ICONERROR | MB_OK);

		// Create Status bar
		HWND hStatus;
		int statwidths[] = { 140, 300, -1 };

		hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
			0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);

		SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);

		SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)" Author:      Me");
		SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)"                 - MDI2 - ");
		SendMessage(hStatus, SB_SETTEXT, 2, (LPARAM)"                  May 2020");

                // registering MDI after client window is made here!


However thanks everyone ... cheers
Richard MacCutchan 15-May-20 11:42am
Of course the compiler didn't give you an error. The compiler can only analyze and convert the source code you provide, it cannot guess whether you are doing things in the correct order, or whether you have missed a step.
M@gelearn 15-May-20 11:44am
Richard MacCutchan 15-May-20 11:54am
Instead of posting a generic error message which tells you nothing, you should use GetLastError to find the reason why it failed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900