Ladislav Dud&#225&#59;š

I have application compiled with MultiByte character set. This application load dll compiled with unicode character set. DLL create new class derived from MFC CTreeCtrl. All works ok, except notification and messages didn't get to my control.

I think this is problem that dll is compiled with unicode support and application not. If i compile dll with no unicode support notification and messages get normal. How is problem with delivery of notification

- Ladislav Duda




Re: Visual C++ Language Non unicode app with unicode dll

Ramkrishna Pawar

One can mix Unicode and ANSI versions of modules, but the integration must handle the case, like if one module sends strings (or anything which is char set dependant) to another then it must be converted.

Have you tried debugging it






Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

How can i debug this Where put breakpoint Cannot put to function that controls notification (notification is not received by my class). I tried Spy++, but if i click on tree control, no messages or notification is received by my class or parent window. Any other ideas






Re: Visual C++ Language Non unicode app with unicode dll

Ramkrishna Pawar

How does the DLL send notification isnt there some WndProc in DLL's class implementation Try overrriding it and debug that. You can also try debugging the way you have called the DLL (some function from DLL may be).




Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

Thank you for answer. It's hard to debug this, but i debuged and problem is in file wincore.cpp line 2908.

Code Snippet

CWnd* pWnd = (CWnd*)pMap->LookupPermanent(hWndChild);

ASSERT(pWnd == NULL || pWnd->m_hWnd == hWndChild);

if (pWnd == NULL)

{

#ifndef _AFX_NO_OCC_SUPPORT

// check if the window is an OLE control

CWnd* pWndParent = (CWnd*)pMap->LookupPermanent(::GetParent(hWndChild));

if (pWndParent != NULL && pWndParent->m_pCtrlCont != NULL)

{

// If a matching control site exists, it's an OLE control

COleControlSite* pSite = (COleControlSite*)pWndParent->

m_pCtrlCont->m_siteMap.GetValueAt(hWndChild);

if (pSite != NULL)

{

CWnd wndTemp(hWndChild);

wndTemp.m_pCtrlSite = pSite;

LRESULT lResult = wndTemp.SendChildNotifyLastMsg(pResult);

wndTemp.m_hWnd = NULL;

return lResult != 0;

}

}

#endif //!_AFX_NO_OCC_SUPPORT

return FALSE;

}

// only OLE controls and permanent windows will get reflected msgs

ASSERT(pWnd != NULL);

return pWnd->SendChildNotifyLastMsg(pResult);

LookupPermanent return NULL if dll is Unicode compiled, but regular CWnd if dll is not compiled with unicode character set. So next code go to if and here return FALSE, because this is not OLE control.

Here is call stack:

mfc80d.dll!CWnd::ReflectLastMsg(HWND__ * hWndChild=0x000a0b0e, long * pResult=0x0012ebe8) Line 2908 C++
mfc80d.dll!CWnd:SurprisenNotify(unsigned int __formal=12345, long lParam=1241000, long * pResult=0x0012ebe8) Line 2319 + 0xd bytes C++
mfc80d.dll!CWnd:SurprisenWndMsg(unsigned int message=78, unsigned int wParam=12345, long lParam=1241000, long * pResult=0x0012ed14) Line 1767 + 0x2a bytes C++

May be problem is when i create my control. Here is code how i create my control:

Code Snippet

tree = new CMyTree();

if (!tree->Create (WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_SHOWSELALWAYS

| TVS_LINESATROOT | TVS_HASBUTTONS | TVS_EDITLABELS | TVS_TRACKSELECT,

lRectDummy, parentP, 12345))

{

return false;

}

parentP is window acquired from application (non-unicode). Any ideas what is wrong I'm using VS 2005.

- Laco.






Re: Visual C++ Language Non unicode app with unicode dll

Bruno van Dooren

Surprised noone mentioned this yet, but the instance you get from the DLL is possibly not compatible with the one in your application.

If there is anything in CTreeCtrl that depends on MBCS or UNICODE selection at compile time, then they will be incompatible and you should not mix the 2





Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

But all wokrs ok, except notifications




Re: Visual C++ Language Non unicode app with unicode dll

Bruno van Dooren

Yes, that is perfectly possible. If all the other stuff you use does not depends on UNICODE vs ANSI, it can al work fine, but if the notification stuff in some way does, then it will fail.

I have had a similar problem when I tried using a DLL written in VC6 in a VC7 application. Everything worked fine except event notification. The events were never fired.

Things like MFC and STL are only supposed to work between different modules if all modules were compiled with the same CRT and char set parameters. If not, then all bets are off.





Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

It's may be a problem in BEGIN_MESSAGE_MAP and END_MESSAGE_MAP. For example if notification is writed as ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged), TVN_SELCHANGED is defined as TVN_SELCHANGEDA or TVN_SELCHANGEDW depending on unicode or non-unicode build. So if application is non unicode TVN_SELCHANGEDA notification is sended, but you are catching TVN_SELCHANGEDW. I don't know why microsoft define these notofication with different numbers. If you changed TVN_SELCHANGED to TVN_SELCHANGEDA, may by you can solve problem.

But this not solve my problem. I have problem find correct CWnd* by pMap->LookupPermanent(hWndChild). But i don't know why. May i use some macro. But i don't know what. This function didn't find correct window and then code not go to find massage WM_NOTIFY in message map of my class.

- Laco.






Re: Visual C++ Language Non unicode app with unicode dll

Bruno van Dooren

If that is what happens then yes, you will have problems.

Since you have the code for the DLL, why don't you use the same settings for building both

You may be able to work around this problem, but the chances are that you'll have a similar problem later on.

And even worse, you could get all sorts of undefined behavior that cannot easily be debugged.

Versions of MFC (and other libraries) are not compatible when compiled with different compile time settings.

They are not meant to be. that is why you have to choose.

Don't mix and match.





Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

Yes, i know the best solution is have both application and dll with same settings. But is problem, that i develop only dll, not application. Application is not unicode ready, and is very hard compile it with unicode. But my tree view control must support unicode characters. Is another solution




Re: Visual C++ Language Non unicode app with unicode dll

Bruno van Dooren

There is no solution that I know of, but I'll admit I am not an MFC expert.

If faced with this problem I would choose one of the following:

  1. Bite the bullet and convert the app to unicode. I know this can be a pain, but unless you plan to phase out that application, you'll have to do it eventually. Or
  2. Refactor the application and the DLL interface so that you don't need to pass MFC objects.
    I don't know your code so I don't even know if that is possible. In any case you simply cannot allow MFC objects to be passed from your dll to the app or the other way around.
    If you can refactor your application just a bit so that it does not directly depend on MFC in the interface, your DLL could take care of all the MBCS to Unicode conversions.





Re: Visual C++ Language Non unicode app with unicode dll

Ladislav Dudá?

Thanks all to answers. Very good forum.