mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 08:55:19 +00:00
Implement NtUserPostThreadMessage and add test program (all by Art Yerkes)
svn path=/trunk/; revision=5227
This commit is contained in:
parent
aa538172d6
commit
42d63c02df
4 changed files with 146 additions and 3 deletions
6
reactos/apps/tests/thread_msg/.cvsignore
Normal file
6
reactos/apps/tests/thread_msg/.cvsignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
*.o
|
||||
*.d
|
||||
*.exe
|
||||
*.coff
|
||||
*.sym
|
||||
*.map
|
21
reactos/apps/tests/thread_msg/makefile
Normal file
21
reactos/apps/tests/thread_msg/makefile
Normal file
|
@ -0,0 +1,21 @@
|
|||
# $Id: makefile,v 1.1 2003/07/23 17:00:55 gvg Exp $
|
||||
|
||||
PATH_TO_TOP = ../../..
|
||||
|
||||
TARGET_NORC = yes
|
||||
|
||||
TARGET_TYPE = program
|
||||
|
||||
TARGET_APPTYPE = console
|
||||
|
||||
TARGET_NAME = thread_msg
|
||||
|
||||
TARGET_SDKLIBS = kernel32.a user32.a
|
||||
|
||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||
|
||||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
||||
include $(TOOLS_PATH)/helper.mk
|
||||
|
||||
# EOF
|
97
reactos/apps/tests/thread_msg/thread_msg.c
Normal file
97
reactos/apps/tests/thread_msg/thread_msg.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
HANDLE hWaitForFailure;
|
||||
HANDLE hOkToPostThreadMessage;
|
||||
HANDLE hOkToTerminate;
|
||||
|
||||
DWORD WINAPI thread( LPVOID crap )
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
/* Failure case ... Wait for the parent to try to post a message
|
||||
before queue creation */
|
||||
printf( "Waiting to create the message queue.\n" );
|
||||
|
||||
WaitForSingleObject(hWaitForFailure,INFINITE);
|
||||
|
||||
printf( "Creating message queue.\n" );
|
||||
|
||||
/* "Create" a message queue */
|
||||
PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE );
|
||||
|
||||
printf( "Signalling the parent that we're ready.\n" );
|
||||
|
||||
/* Signal that it's ok to post */
|
||||
SetEvent( hOkToPostThreadMessage );
|
||||
|
||||
printf( "Listening messages.\n" );
|
||||
|
||||
/* Now read some messages */
|
||||
while( GetMessage( &msg, 0,0,0 ) ) {
|
||||
printf( "Received message: %04x %04x %08x\n",
|
||||
(msg.message & 0xffff),
|
||||
(msg.wParam & 0xffff),
|
||||
msg.lParam );
|
||||
assert( !msg.hwnd );
|
||||
}
|
||||
|
||||
printf( "Finished receiving messages.\n" );
|
||||
SetEvent( hOkToTerminate );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
DWORD id, Status;
|
||||
|
||||
printf( "Creating events\n" );
|
||||
|
||||
hOkToPostThreadMessage = CreateEvent( NULL, FALSE, FALSE, NULL );
|
||||
hOkToTerminate = CreateEvent( NULL, FALSE, FALSE, NULL );
|
||||
hWaitForFailure = CreateEvent( NULL, FALSE, FALSE, NULL );
|
||||
|
||||
printf( "Created events\n" );
|
||||
|
||||
if( CreateThread( 0, 0, thread, 0, 0, &id ) == NULL ) {
|
||||
printf( "Couldn't create one thread.\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf( "Posting to non-existent queue\n" );
|
||||
|
||||
/* Check failure case */
|
||||
assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) == FALSE );
|
||||
|
||||
printf( "Signalling thread to advance.\n" );
|
||||
|
||||
SetEvent( hWaitForFailure );
|
||||
|
||||
printf( "Waiting for signal from thread.\n" );
|
||||
WaitForSingleObject( hOkToPostThreadMessage, INFINITE );
|
||||
|
||||
printf( "Sending three messages, then quit.\n" );
|
||||
assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) );
|
||||
assert( PostThreadMessage( id, WM_USER + 1, 3, 4 ) );
|
||||
Sleep( 500 ); /* Sleep a bit, so that the queue is empty for a bit. */
|
||||
assert( PostThreadMessage( id, WM_USER + 2, 5, 6 ) );
|
||||
assert( PostThreadMessage( id, WM_QUIT, 0,0 ) );
|
||||
|
||||
WaitForSingleObject( hOkToTerminate, INFINITE );
|
||||
printf( "Test complete.\n" );
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: message.c,v 1.22 2003/06/20 16:26:14 ekohl Exp $
|
||||
/* $Id: message.c,v 1.23 2003/07/23 17:00:55 gvg Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -436,9 +436,28 @@ NtUserPostThreadMessage(DWORD idThread,
|
|||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
MSG Mesg;
|
||||
|
||||
PUSER_MESSAGE Message;
|
||||
PETHREAD peThread;
|
||||
PW32THREAD pThread;
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = PsLookupThreadByThreadId(idThread,&peThread);
|
||||
|
||||
return 0;
|
||||
if( Status == STATUS_SUCCESS ) {
|
||||
pThread = peThread->Win32Thread;
|
||||
Mesg.hwnd = 0;
|
||||
Mesg.message = Msg;
|
||||
Mesg.wParam = wParam;
|
||||
Mesg.lParam = lParam;
|
||||
Message = MsqCreateMessage(&Mesg);
|
||||
MsqPostMessage(pThread->MessageQueue, Message);
|
||||
return TRUE;
|
||||
} else {
|
||||
SetLastNtError( Status );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD STDCALL
|
||||
|
|
Loading…
Reference in a new issue