ReactOS 0.4.15-dev-7924-g5949c20
thread_msg.c File Reference
#include <windows.h>
#include <stdio.h>
#include <assert.h>
Include dependency graph for thread_msg.c:

Go to the source code of this file.

Functions

DWORD WINAPI thread (LPVOID crap)
 
int main (int argc, char **argv)
 

Variables

HANDLE hWaitForFailure
 
HANDLE hOkToPostThreadMessage
 
HANDLE hOkToTerminate
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 57 of file thread_msg.c.

58{
59 DWORD id;
60
61 printf( "Creating events\n" );
62
66
67 printf( "Created events\n" );
68
69 if( CreateThread( 0, 0, thread, 0, 0, &id ) == NULL ) {
70 printf( "Couldn't create one thread.\n" );
71 return 0;
72 }
73
74 printf( "Posting to non-existent queue\n" );
75
76 /* Check failure case */
77 assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) == FALSE );
78
79 printf( "Signalling thread to advance.\n" );
80
82
83 printf( "Waiting for signal from thread.\n" );
85
86 printf( "Sending three messages, then quit.\n" );
87 assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) );
88 assert( PostThreadMessage( id, WM_USER + 1, 3, 4 ) );
89 Sleep( 500 ); /* Sleep a bit, so that the queue is empty for a bit. */
90 assert( PostThreadMessage( id, WM_USER + 2, 5, 6 ) );
91 assert( PostThreadMessage( id, WM_QUIT, 0,0 ) );
92
94 printf( "Test complete.\n" );
95
96 return 0;
97}
static HANDLE thread
Definition: service.c:33
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define assert(x)
Definition: debug.h:53
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:93
GLuint id
Definition: glext.h:5910
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
HANDLE hOkToTerminate
Definition: thread_msg.c:18
HANDLE hOkToPostThreadMessage
Definition: thread_msg.c:17
HANDLE hWaitForFailure
Definition: thread_msg.c:16
#define CreateEvent
Definition: winbase.h:3748
#define WM_QUIT
Definition: winuser.h:1623
#define PostThreadMessage
Definition: winuser.h:5833
#define WM_USER
Definition: winuser.h:1895

◆ thread()

DWORD WINAPI thread ( LPVOID  crap)

Definition at line 20 of file thread_msg.c.

21{
22 MSG msg;
23
24 /* Failure case ... Wait for the parent to try to post a message
25 before queue creation */
26 printf( "Waiting to create the message queue.\n" );
27
29
30 printf( "Creating message queue.\n" );
31
32 /* "Create" a message queue */
33 PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE );
34
35 printf( "Signalling the parent that we're ready.\n" );
36
37 /* Signal that it's ok to post */
39
40 printf( "Listening messages.\n" );
41
42 /* Now read some messages */
43 while( GetMessage( &msg, 0,0,0 ) ) {
44 printf( "Received message: %04x %04x %08lx\n",
45 (msg.message & 0xffff),
46 (msg.wParam & 0xffff),
47 msg.lParam );
48 assert( !msg.hwnd );
49 }
50
51 printf( "Finished receiving messages.\n" );
53
54 return 0;
55}
#define msg(x)
Definition: auth_time.c:54
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define GetMessage
Definition: winuser.h:5790
#define PeekMessage
Definition: winuser.h:5830
#define PM_NOREMOVE
Definition: winuser.h:1195

Variable Documentation

◆ hOkToPostThreadMessage

HANDLE hOkToPostThreadMessage

Definition at line 17 of file thread_msg.c.

Referenced by main(), and thread().

◆ hOkToTerminate

HANDLE hOkToTerminate

Definition at line 18 of file thread_msg.c.

Referenced by main(), and thread().

◆ hWaitForFailure

HANDLE hWaitForFailure

Test case for PostThreadMessage (C) 2003 ReactOS License: LGPL See: LGPL.txt in top directory. Author: arty

Windows thread message queue test case. Derived from ../event/event.c in part.

Definition at line 16 of file thread_msg.c.

Referenced by main(), and thread().