dotnet compact framework:
Hello to all NG.
Startint from the (working) "Asynchronous callbacks from native Win32
code" MSDN example, I modified the source code adding a second instance
of "public MyMessageWnd msgWnd;", calling them msgWnd1 and msgWnd2 (I
can observe that two classes have different .hWnd values).
Then I modified the C++ class, adding 2 new WM_ events
(WM_ASYNCDATA_START and WM_ASYNCDATA_STOP) and the code in
RandomWndDataFeeder like this:
DWORD WINAPI RandomWndDataFeeder (LPVOID lpParameter)
{
if(g_hWndManaged2 != NULL)
{
PostMessage(g_hWndManaged2, WM_ASYNCDATA_START, 0,
::GetTickCount());//0);
//::Sleep(0);
}
for(int i = 0; i < g_dwCicli; i++)
{
PostMessage(g_hWndManaged1, WM_ASYNCDATA_RECEIVED, 0,
::GetTickCount());//(LPARAM)g_pszWndSource);
//::Sleep(0);
}
if(g_hWndManaged2 != NULL)
{
PostMessage(g_hWndManaged2, WM_ASYNCDATA_STOP, 0,
::GetTickCount());//0);
//::Sleep(0);
}
return 0L;
}
The function
RANDOMDATA_API void StartWndCommunication (DWORD messageType, HWND
hWnd1, HWND hWnd2, DWORD cicli)
now has 2 HWND parameters, one for the first managed class and one for
the second managed class and is called by the managed application with:
UnmanagedWndAPI.StartWndCommunication(msgWnd1.Hwnd, msgWnd2.Hwnd,
1000);
What I doing? I want to demonstrate that with PostMessage the message
queue is asyncronous, so the C++ "for" cicle, adds the messages as
quick as possible, then ends BEFORE the C# appl has readed all the
messages in his queue (in fact C++ adds in the queue at least 8-9
messages in 1 milliseconds, and the maneged application needs at least
30-35 milliseconds to get the message and add it to the list).
[quoted text, click to view] >From the c# application side, I have to take the WM_ASYNCDATA_START on
the second class instance, then 1000 WM_ASYNCDATA_RECEIVED in the
first class instance, and finally a WM_ASYNCDATA_STOP in the second
class instance.
Every message received is displayes on a list control. What happens if
I run the application? I get the messages in the list, clear! However
the WM_ASYNCDATA_STOP message is displayed as last item in the list,
after the last WM_ASYNCDATA_RECEIVED: this is wrong. If I send 2
different hWnd to C++ application, the 2 queues are separated, and I
have to receive the WM_ASYNCDATA_STOP in the second class instance
before then first class instance ends his messages.
If I create 2 different exe, and I pass to C++ the hWnd of the class
instance of each different exe, it works! in second exe I get the
WM_ASYNCDATA_STOP message when the first exe is receiving the 8th-9th
WM_ASYNCDATA_RECEIVED message (and there are 1000 messages in his
queue!)
Is seems that different hWnd queue in the same exe are working in
syncronous mode each other.
Who can explain me better how Windows Messages works?
Thanks.