--- mstools/samples/mltithrd/mltithrd.c 2018/08/09 18:20:01 1.1.1.1 +++ mstools/samples/mltithrd/mltithrd.c 2018/08/09 18:20:43 1.1.1.2 @@ -1,61 +1,3 @@ -/****************************** Module Header ******************************\ -* Module Name: demo.c -* -* Copyright (c) 1991, Microsoft Corporation -* -* Yet another User test program. -* -* History: -* 04-17-90 ??????? Created. - -* 09-09-91 PetrusW Rewrote. -* create as many threads (windows) as we wish -* change the UI to MDI -\***************************************************************************/ - - -/* ******MULTI-THREADED GUIDE******** - - - There are aspects to a multi-threaded app, that need be explained, - so that a programmer understand the pitfalls of a multi-threaded app, - and avoid future problems in a multi-threaded application. - - The primary pifalls involve the usage of GDI objects. (DC's, regions, etc). - GDI is the only subsytem in NT win32, that does NOT serialize access - to its objects. This is for speed/throughput reasons. The premise - of GDI objects, is that an object is per process owned, per thread locked. - - This means if you have multiple threads, accessing the same GDI object, - you will have MAJOR headaches, because while one thread deletes an object, - the other may be using it. The model we put forward towards developers, is - the following model. - - Seperate threads for - - > Input - > File IO - > Printing - > Graphics * Note its ok to have graphics/Printing threads, because - The use a different device. - - - Note that you can be single threaded, and have no GDI object serialization - problems. What types of problems occur, is when seperate threads attempt - to delete/use a GDI object, or share an object between multiple threads. - Since an object is per thread locked, means you will get an unexpected - error within the other thread. Many windows programmers, do not expect - certain calls to ever fail, but a poorly constructed multi-threaded app - under win32 (given the above scenerios) may fail, and if not checked, - will cause subsequent GDI calls to fail, ultimately causing the GDI client - side server to die, taking the app with it. - - Thus its most important to realize that while multi-threaded apps are cool, - they must be programmed with respect to the above guidelines. - -*/ - - #include #include "mltithrd.h" @@ -209,7 +151,7 @@ BOOL InitializeApp(void) ghbrBlack = CreateSolidBrush(0x00000000); wc.style = CS_OWNDC; - wc.lpfnWndProc = MainWndProc; + wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(LONG); wc.hInstance = ghModule; @@ -223,7 +165,7 @@ BOOL InitializeApp(void) return FALSE; wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = ThreadWndProc; + wc.lpfnWndProc = (WNDPROC)ThreadWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = ghModule; @@ -434,7 +376,7 @@ long MainWndProc( } case MM_ABOUT: - if (DialogBox(ghModule, "AboutBox", ghwndMain, About) == -1) + if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1) MessageBox(ghwndMain, "Mltithrd: About Dialog Creation Error!", "Error", MB_OK); return 0L; @@ -830,3 +772,4 @@ void MoveBox( *pdy = *pvy; } } +