3 #include <winpr/thread.h>
4 #include <winpr/collections.h>
6 static DWORD WINAPI message_queue_consumer_thread(LPVOID arg)
8 wMessage message = { 0 };
9 wMessageQueue* queue = (wMessageQueue*)arg;
11 while (MessageQueue_Wait(queue))
13 if (MessageQueue_Peek(queue, &message, TRUE))
15 if (message.id == WMQ_QUIT)
18 printf(
"Message.Type: %" PRIu32
"\n", message.id);
25 int TestMessageQueue(
int argc,
char* argv[])
28 wMessageQueue* queue = NULL;
33 if (!(queue = MessageQueue_New(NULL)))
35 printf(
"failed to create message queue\n");
39 if (!(thread = CreateThread(NULL, 0, message_queue_consumer_thread, (
void*)queue, 0, NULL)))
41 printf(
"failed to create thread\n");
42 MessageQueue_Free(queue);
46 if (!MessageQueue_Post(queue, NULL, 123, NULL, NULL) ||
47 !MessageQueue_Post(queue, NULL, 456, NULL, NULL) ||
48 !MessageQueue_Post(queue, NULL, 789, NULL, NULL) || !MessageQueue_PostQuit(queue, 0) ||
49 WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0)
52 MessageQueue_Free(queue);
53 (void)CloseHandle(thread);