»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
¼¼ÊõÎĵµ > VCÎĵµ > ƽ̨SDK
Windows϶àÏ̱߳à³Ì¼¼Êõ¼°ÆäʵÏÖ
·¢±íÈÕÆÚ£º2003-07-03 00:00:00×÷ÕߣºÎ ³ö´¦£º  

Ò»¡¢ÎÊÌâµÄÌá³ö

×÷Õß×î½üÔÚ¿ª·¢»ùÓÚInternetÍøÉϵĿÉÊӵ绰¹ý³ÌÖУ¬Åöµ½ÁËÕâÑùÒ»¸öÎÊÌâ¡£ÔÚ»ùÓÚInternetÍøÉϵĿÉÊӵ绰ϵͳÖУ¬Í¬Ê±Òª½øÐÐÓïÒô²É¼¯¡¢ÓïÒô±à½âÂ롢ͼÏó²É¼¯¡¢Í¼Ïó±à½âÂë¡¢ÓïÒôºÍͼÏóÂëÁ÷µÄ´«Ê䣬ËùÓеÄÕâЩÊÂÇ飬¶¼Òª²¢Ðд¦Àí¡£ÌرðÊÇÓïÒôÐźţ¬Èç¹û½øÐÐͼÏó±à½âÂëʱ¼ä¹ý³¤£¬ÓïÒôÐźŵò»µ½·þÎñ£¬Í¨»°¾ÍÓмä¶Ï£¬Èç¹ûͼÏó»òÓïÒô´¦Àíʱ¼ä¹ý³¤£¬¶ø²»Äܼ°Ê±µÄ´«ÊäÂëÁ÷Êý¾Ý£¬Í¨ÐÅͬÑùÒ²»áÖжϡ£ÕâÑù¾ÍÒªÇóÎÒÃÇʵÏÖÒ»ÖÖ²¢Ðбà³Ì£¬ÔÚÖ»ÓÐÒ»¸öCPUµÄ»úÆ÷ÉÏ£¬Ò²¾ÍÊÇÒª½«¸ÃCPUʱ¼ä°´ÕÕÒ»¶¨µÄÓÅÏÈ×¼Ôò·ÖÅä¸ø¸÷¸öʼþ£¬¶¨ÆÚ´¦Àíijһʼþ¶ø²»»áÔÚijһʼþ´¦Àí¹ý³¤£¬ÔÚ32λWindows95»òWindowsNTÏ£¬ÎÒÃÇ¿ÉÒÔÓöàÏ̵߳ıà³Ì¼¼ÊõÀ´ÊµÏÖÕâÖÖ²¢Ðбà³Ì¡£Êµ¼ÊÉÏ£¬ÕâÖÖ²¢Ðбà³ÌÔںܶೡºÏ϶¼ÊDZØÐëµÄ¡£ÀýÈ磬ÔÚFileManager¿½±´Îļþʱ£¬ËüÏÔʾһ¸ö¶Ô»°¿ò£¬ÁгöÔ´ÎļþºÍÄ¿±êÎļþµÄÃû³Æ£¬²¢ÔÚ¶Ô»°¿òÖаüº¬ÁËÒ»¸öCancel°´Å¥¡£Èç¹ûÔÚÎļþ¿½±´¹ý³ÌÖУ¬µãÖÐCancel°´Å¥£¬¾Í»áÖÕÖ¹¿½±´¡£ÔÚ16λWindowsÖУ¬ÊµÏÖÕâÀ๦ÄÜÐèÒªÔÚFileCopyÑ­»·ÄÚ²¿ÖÜÆÚÐԵص÷ÓÃPeekMessageº¯Êý¡£Èç¹ûÕýÔÚ¶ÁÒ»¸öºÜ´óµÄÊý¾Ý¿é£¬ÔòÖ»Óе±Õâ¸ö¿é¶ÁÍêÒÔºó²ÅÄÜÏìÓ¦Õâ¸ö°´Å¥¶¯×÷£¬Èç¹û´ÓÈíÅ̶ÁÎļþ£¬ÔòÒª»¨·ÑºÃ¼¸ÃëµÄʱ¼ä£¬ÓÉÓÚ»úÆ÷·´Ó¦Ì«³Ù¶Û£¬Äã»áƵ·±µØµãÖÐÕâ¸ö°´Å¥£¬ÒÔΪϵͳ²»ÖªµÀÄãÏëÖÕÖ¹Õâ¸ö²Ù×÷¡£Èç¹û°ÑFileCopyÖ¸Áî·ÅÈëÁíÍâÒ»¸öỊ̈߳¬Äã¾Í²»ÐèÒªÔÚ´úÂëÖзÅÒ»´ó¶ÑPeekMessageº¯Êý£¬´¦ÀíÓû§½çÃæµÄÏ߳̽«ÓëËü·Ö¿ª²Ù×÷£¬ÕâÑù£¬µãÖÐCancel°´Å¥ºó»áÁ¢¼´µÃµ½ÏìÓ¦¡£Í¬ÑùµÄµÀÀí£¬ÔÚÓ¦ÓóÌÐòÖд´½¨Ò»¸öµ¥¶ÀÏß³ÌÀ´´¦ÀíËùÓдòÓ¡ÈÎÎñÒ²ÊǺÜÓÐÓõģ¬ÕâÑù£¬Óû§¿ÉÒÔÔÚ´òÓ¡´¦Àíʱ¼ÌÐøʹÓÃÓ¦ÓóÌÐò¡£

¶þ¡¢Ï̵߳ĸÅÄî

ΪÁËÁ˽âÏ̵߳ĸÅÄÎÒÃDZØÐëÏÈÌÖÂÛһϽø³ÌµÄ¸ÅÄî¡£

Ò»¸ö½ø³Ìͨ³£¶¨ÒåΪ³ÌÐòµÄÒ»¸öʵÀý¡£ÔÚWin32ÖУ¬½ø³ÌÕ¼¾Ý4GBµÄµØÖ·¿Õ¼ä¡£ÓëËüÃÇÔÚMS-DOSºÍ16λWindows²Ù×÷ϵͳÖв»Í¬£¬Win32½ø³ÌÊÇûÓлîÁ¦µÄ¡£Õâ¾ÍÊÇ˵£¬Ò»¸öWin32½ø³Ì²¢²»Ö´ÐÐʲôָÁËüÖ»ÊÇÕ¼¾Ý×Å4GBµÄµØÖ·¿Õ¼ä£¬´Ë¿Õ¼äÖÐÓÐÓ¦ÓóÌÐòEXEÎļþµÄ´úÂëºÍÊý¾Ý¡£EXEÐèÒªµÄÈÎÒâDLLÒ²½«ËüÃǵĴúÂëºÍÊý¾Ý×°Èëµ½½ø³ÌµÄµØÖ·¿Õ¼ä¡£³ýÁ˵ØÖ·¿Õ¼ä£¬½ø³Ì»¹Õ¼ÓÐijЩ×ÊÔ´£¬±ÈÈçÎļþ¡¢¶¯Ì¬ÄÚ´æ·ÖÅäºÍÏ̡߳£µ±½ø³ÌÖÕֹʱ£¬ÔÚËüÉúÃüÆÚÖд´½¨µÄ¸÷ÖÖ×ÊÔ´½«±»Çå³ý¡£

µ«Êǽø³ÌÊÇûÓлîÁ¦µÄ£¬ËüÖ»ÊÇÒ»¸ö¾²Ì¬µÄ¸ÅÄΪÁËÈýø³ÌÍê³ÉһЩ¹¤×÷£¬½ø³Ì±ØÐëÖÁÉÙÕ¼ÓÐÒ»¸öỊ̈߳¬ËùÒÔÏß³ÌÊÇÃèÊö½ø³ÌÄÚµÄÖ´ÐУ¬ÕýÊÇÏ̸߳ºÔðÖ´Ðаüº¬ÔÚ½ø³ÌµÄµØÖ·¿Õ¼äÖеĴúÂ롣ʵ¼ÊÉÏ£¬µ¥¸ö½ø³Ì¿ÉÒÔ°üº¬¼¸¸öỊ̈߳¬ËüÃÇ¿ÉÒÔͬʱִÐнø³ÌµÄµØÖ·¿Õ¼äÖеĴúÂ롣ΪÁË×öµ½ÕâÒ»µã£¬Ã¿¸öÏß³ÌÓÐ×Ô¼ºµÄÒ»×éCPU¼Ä´æÆ÷ºÍ¶ÑÕ»¡£Ã¿¸ö½ø³ÌÖÁÉÙÓÐÒ»¸öÏß³ÌÔÚÖ´ÐÐÆäµØÖ·¿Õ¼äÖеĴúÂ룬Èç¹ûûÓÐÏß³ÌÖ´Ðнø³ÌµØÖ·¿Õ¼äÖеĴúÂ룬½ø³ÌÒ²¾ÍûÓмÌÐø´æÔÚµÄÀíÓÉ£¬ÏµÍ³½«×Ô¶¯Çå³ý½ø³Ì¼°ÆäµØÖ·¿Õ¼ä¡£ÎªÁËÔËÐÐËùÓÐÕâЩỊ̈߳¬²Ù×÷ϵͳΪÿ¸ö¶ÀÁ¢Ḭ̈߳²ÅÅһЩCPUʱ¼ä£¬²Ù×÷ϵͳÒÔÂÖת·½Ê½ÏòÏß³ÌÌṩʱ¼äƬ£¬Õâ¾Í¸øÈËÒ»ÖÖ¼ÙÏ󣬺ÃÏóÕâЩÏ̶߳¼ÔÚͬʱÔËÐС£´´½¨Ò»¸öWin32½ø³Ìʱ£¬ËüµÄµÚÒ»¸öÏ̳߳ÆΪÖ÷Ị̈߳¬ËüÓÉϵͳ×Ô¶¯Éú³É£¬È»ºó¿ÉÓÉÕâ¸öÖ÷Ïß³ÌÉú³É¶îÍâµÄỊ̈߳¬ÕâЩỊ̈߳¬ÓÖ¿ÉÉú³É¸ü¶àµÄÏ̡߳£

Èý¡¢Ï̵߳ıà³Ì¼¼Êõ

1¡¢±àдÏ̺߳¯Êý

ËùÓÐÏ̱߳ØÐë´ÓÒ»¸öÖ¸¶¨µÄº¯Êý¿ªÊ¼Ö´ÐУ¬¸Ãº¯Êý³ÆΪÏ̺߳¯Êý£¬Ëü±ØÐë¾ßÓÐÏÂÁÐÔ­ÐÍ£ºDWORDWINAPIYourThreadFunc(LPVOIDlpvThreadParm);

¸Ãº¯ÊýÊäÈëÒ»¸öLPVOIDÐ͵IJÎÊý£¬¿ÉÒÔÊÇÒ»¸öDWORDÐ͵ÄÕûÊý£¬Ò²¿ÉÒÔÊÇÒ»¸öÖ¸ÏòÒ»¸ö»º³åÇøµÄÖ¸Õ룬·µ»ØÒ»¸öDWORDÐ͵ÄÖµ¡£ÏóWinMainº¯ÊýÒ»Ñù£¬Õâ¸öº¯Êý²¢²»ÓɲÙ×÷ϵͳµ÷Ó㬲Ù×÷ϵͳµ÷Óðüº¬ÔÚKERNEL32.DLLÖеķÇCÔËÐÐʱµÄÒ»¸öÄÚ²¿º¯Êý£¬ÈçStartOfThread£¬È»ºóÓÉStartOfThreadº¯Êý½¨Á¢ÆðÒ»¸öÒì³£´¦Àí¿ò¼Üºó£¬µ÷ÓÃÎÒÃǵĺ¯Êý¡£

2¡¢´´½¨Ò»¸öÏß³Ì

Ò»¸ö½ø³ÌµÄÖ÷Ïß³ÌÊÇÓɲÙ×÷ϵͳ×Ô¶¯Éú³É£¬Èç¹ûÄãÒªÈÃÒ»¸öÖ÷Ï̴߳´½¨¶îÍâµÄỊ̈߳¬Äã¿ÉÒÔµ÷ÓÃÀ´CreateThreadÍê³É¡£

HANDLECreateThread(LPSECURITY_ATTRIBUTESlpsa,DWORDcbstack,LPTHREAD_START_ROUTINElpStartAddr,LPVOIDlpvThreadParm,DWORDfdwCreate,LPDWORDlpIDThread);

ÆäÖÐlpsa²ÎÊýΪһ¸öÖ¸ÏòSECURITY_ATTRIBUTES½á¹¹µÄÖ¸Õë¡£Èç¹ûÏëÈöÔÏóΪȱʡ°²È«ÊôÐԵĻ°£¬¿ÉÒÔ´«Ò»¸öNULL£¬Èç¹ûÏëÈÃÈÎÒ»¸ö×Ó½ø³Ì¶¼¿É¼Ì³ÐÒ»¸ö¸ÃÏ̶߳ÔÏó¾ä±ú£¬±ØÐëÖ¸¶¨Ò»¸öSECURITY_ATTRIBUTES½á¹¹£¬ÆäÖÐbInheritHandle³ÉÔ±³õʼ»¯ÎªTRUE¡£²ÎÊýcbstack±íʾÏß³ÌΪ×Ô¼ºËùÓöÑÕ»·ÖÅäµÄµØÖ·¿Õ¼ä´óС£¬0±íʾ²ÉÓÃϵͳȱʡֵ¡£²ÎÊýlpStartAddrÓÃÀ´±íʾÐÂÏ߳̿ªÊ¼Ö´ÐÐʱ´úÂëËùÔÚº¯ÊýµÄµØÖ·£¬¼´ÎªÏ̺߳¯Êý¡£lpvThreadParmΪ´«ÈëÏ̺߳¯ÊýµÄ²ÎÊý£¬fdwCreate²ÎÊýÖ¸¶¨¿ØÖÆÏ̴߳´½¨µÄ¸½¼Ó±êÖ¾£¬¿ÉÒÔÈ¡Á½ÖÖÖµ¡£Èç¹û¸Ã²ÎÊýΪ0£¬Ï߳̾ͻáÁ¢¼´¿ªÊ¼Ö´ÐУ¬Èç¹û¸Ã²ÎÊýΪCREATE_SUSPENDED£¬Ôòϵͳ²úÉúÏ̺߳󣬳õʼ»¯CPU£¬µÇ¼ÇCONTEXT½á¹¹µÄ³ÉÔ±£¬×¼±¸ºÃÖ´ÐиÃÏ̺߳¯ÊýÖеĵÚÒ»ÌõÖ¸Áµ«²¢²»ÂíÉÏÖ´ÐУ¬¶øÊǹÒÆð¸ÃÏ̡߳£×îºóÒ»¸ö²ÎÊýlpIDThreadÊÇÒ»¸öDWORDÀàÐ͵ØÖ·£¬·µ»Ø¸³¸ø¸ÃÐÂÏ̵߳ÄIDÖµ¡£

3¡¢ÖÕÖ¹Ïß³Ì

Èç¹ûijÏ̵߳÷ÓÃÁËExitThreadº¯Êý£¬¾Í¿ÉÒÔÖÕÖ¹×Ô¼º¡£

VOIDExitThread(UINTfuExitCode);

Õâ¸öº¯ÊýΪµ÷Óøú¯ÊýµÄÏß³ÌÉèÖÃÁËÍ˳öÂëfuExitCodeºó£¬¾ÍÖÕÖ¹¸ÃÏ̡߳£

µ÷ÓÃTerminateThreadº¯ÊýÒà¿ÉÖÕÖ¹Ï̡߳£

BOOLTerminateThread(HANDLEhThread,DWORDdwExitCode);

¸Ãº¯ÊýÓÃÀ´½áÊøÓÉhThread²ÎÊýÖ¸¶¨µÄỊ̈߳¬²¢°ÑdwExitCodeÉè³É¸ÃÏ̵߳ÄÍ˳öÂë¡£µ±Ä³¸öÏ̲߳»ÔÚÏìӦʱ£¬ÎÒÃÇ¿ÉÒÔÓÃÆäËûÏ̵߳÷Óøú¯ÊýÀ´ÖÕÖ¹Õâ¸ö²»ÏìÓ¦µÄÏ̡߳£

4¡¢É趨Ï̵߳ÄÏà¶ÔÓÅÏȼ¶

µ±Ò»¸öÏ̱߳»Ê״δ´½¨Ê±£¬ËüµÄÓÅÏȼ¶µÈͬÓÚËüËùÊô½ø³ÌµÄÓÅÏȼ¶¡£ÔÚµ¥¸ö½ø³ÌÄÚ¿ÉÒÔͨ¹ýµ÷ÓÃSetThreadPriorityº¯Êý¸Ä±äÏ̵߳ÄÏà¶ÔÓÅÏȼ¶¡£Ò»¸öÏ̵߳ÄÓÅÏȼ¶ÊÇÏà¶ÔÓÚÆäËùÊôµÄ½ø³ÌµÄÓÅÏȼ¶¶øÑԵġ£

BOOLSetThreadPriority(HANDLEhThread,intnPriority);

ÆäÖвÎÊýhThreadÊÇÖ¸Ïò´ýÐÞ¸ÄÓÅÏȼ¶Ï̵߳ľä±ú£¬nPriority¿ÉÒÔÊÇÒÔϵÄÖµ£º

THREAD_PRIORITY_LOWEST,THREAD_PRIORITY_BELOW_NORMAL,THREAD_PRIORITY_NORMAL,THREAD_PRIORITY_ABOVE_NORMAL,THREAD_PRIORITY_HIGHEST

5¡¢¹ÒÆð¼°»Ö¸´Ïß³Ì

ÏÈÇ°ÎÒÌáµ½¹ý¿ÉÒÔ´´½¨¹ÒÆð״̬µÄỊ̈߳¨Í¨¹ý´«µÝCREATE_SUSPENDED±êÖ¾¸øº¯ÊýCreateThreadÀ´ÊµÏÖ£©¡£µ±ÄãÕâÑù×öʱ£¬ÏµÍ³´´½¨Ö¸¶¨Ï̵߳ĺËÐĶÔÏ󣬴´½¨Ï̵߳ÄÕ»£¬ÔÚCONTEXT½á¹¹Öгõʼ»¯Ïß³ÌCPU×¢²á³ÉÔ±¡£È»¶ø£¬Ï̶߳ÔÏó±»·ÖÅäÁËÒ»¸ö³õʼ¹ÒÆð¼ÆÊýÖµ1£¬Õâ±íÃ÷ÁËϵͳ½«²»ÔÙ·ÖÅäCPUÈ¥Ö´ÐÐÏ̡߳£Òª¿ªÊ¼Ö´ÐÐÒ»¸öỊ̈߳¬ÁíÒ»¸öÏ̱߳ØÐëµ÷ÓÃResumeThread²¢´«µÝ¸øËüµ÷ÓÃCreateThreadʱ·µ»ØµÄÏ߳̾ä±ú¡£DWORDResumeThread(HANDLEhThread);

Ò»¸öÏ߳̿ÉÒÔ±»¹ÒÆð¶à´Î¡£Èç¹ûÒ»¸öÏ̱߳»¹ÒÆð3´Î£¬Ôò¸ÃÏß³ÌÔÚËü±»·ÖÅäCPU֮ǰ±ØÐë±»»Ö¸´3´Î¡£³ýÁËÔÚ´´½¨Ïß³ÌʱʹÓÃCREATE_SUSPENDED±êÖ¾£¬Ä㻹¿ÉÒÔÓÃSuspendThreadº¯Êý¹ÒÆðÏ̡߳£

DWORDSuspendThread(HANDLEhThread);

ËÄ¡¢¶àÏ̱߳à³Ì¼¼ÊõµÄÓ¦ÓÃ

ÎÒÔÚÇ°Ãæ˵¹ý£¬ÎªÁËʵÏÖ»ùÓÚTCP/IPϵĿÉÊӵ绰£¬¾Í±ØÐë¡°²¢ÐС±µØÖ´ÐÐÓïÒô²É¼¯¡¢ÓïÒô±à½âÂ롢ͼÏó²É¼¯¡¢Í¼Ïó±à½âÂëÒÔ¼°ÂëÁ÷Êý¾ÝµÄ½ÓÊÕÓë·¢ËÍ¡£ÓïÒôÓëͼÏóµÄ²É¼¯ÓÉÓ²¼þ²É¼¯¿¨½øÐУ¬ÎÒÃǵijÌÐòÖ»Ðè³õʼ»¯¸ÃÓ²¼þ²É¼¯¿¨£¬È»ºóʵʱ¶ÁÈ¡²É¼¯Êý¾Ý¼´¿É£¬µ«ÓïÒôºÍͼÏóÊý¾ÝµÄ±à½âÂëÒÔ¼°ÂëÁ÷Êý¾ÝµÄ´«Ê䶼±ØÐëÓɳÌÐòȥЭµ÷Ö´ÐУ¬¾ö²»ÄÜÔÚijһ¼þʼþÉÏ´¦Àí¹ý³¤£¬±ØÐëÈÃCPUÂÖÁ÷µÄΪ¸÷¸öʼþ·þÎñ£¬Windows95ϵÄÏß³ÌÕýÊÇÂú×ãÕâÖÖÒªÇóµÄ±à³Ì¼¼Êõ¡£

ÏÂÃæÎÒ¸ø³öÁËÀûÓÃWindows95»·¾³ÏµĶàÏ̱߳à³Ì¼¼ÊõʵÏֵĻùÓÚTCP/IPµÄ¿ÉÊӵ绰µÄ²¿·ÖÔ´Â룬ÆäÖаüÀ¨Ö÷´°¿Ú¹ý³Ìº¯Êý£¬ÒÔ¼°Ö÷½Ð¶ËÓë±»½Ð¶ËµÄTCP/IP½ÓÊÕÏ̺߳¯ÊýºÍÓïÒô±à½âÂëµÄÏ̺߳¯Êý¡£ÓÉÓÚͼÏó±à½âÂëµÄʵʱÐÔ±ÈÓïÒô´¦ÀíÓë´«ÊäÄ£¿éµÄʵʱÐÔµÄÒªÇóÒªµÍЩ£¬ËùÒÔÎÒÒÔÓïÒô±à½âÂëΪʼþÈ¥²éѯͼÏóÊý¾Ý£¬È»ºó½øÐÐͼÏó±à½âÂ룬¶øûÓÐΪͼÏó±à½âÂëÈ¥µ¥¶ÀʵÏÖÒ»¸öÏ̡߳£

ÔÚÖ÷´°¿Ú³õʼ»¯Ê±£¬ÎÒÓÃCREATE_SUSPENDED±êÖ¾´´½¨ÁËÁ½¸öÏß³ÌhThreadG7231ºÍhThreadTCPRev¡£Ò»¸öÓÃÓÚÓïÒô±à½âÂ룬ËüµÄÏ̺߳¯ÊýΪG723Proc£¬¸ÃÏ̲߳»¶Ï²éѯ±¾µØÓÐÎÞ±àºÃÂëµÄÓïÒôºÍͼÏóµÄÂëÁ÷£¬ÈçÓУ¬Ôò½øÐÐH.223´ò°ü£¬È»ºóͨ¹ýTCPµÄ¶Ë¿Ú·¢Ë͸ø¶Ô·½¡£ÁíÍâÒ»¸öÏß³ÌÓÃÓÚTCP/IPµÄ½ÓÊÕ£¬ËüµÄÏ̺߳¯ÊýΪAcceptThreadProcRev£¬¸ÃÏ̲߳»¶ÏÕì²âTCP/IP¶Ë¿ÚÓÐÎÞ¶Ô·½´«À´µÄÂëÁ÷£¬ÈçÓУ¬¾Í½ÓÊÕÂëÁ÷£¬½øÐÐH.223½âÂëºóËÍÈëÏàÓ¦µÄ»º³åÇø¡£¸Ã»º³åÇøµÄÄÚÈÝ£¬ÓÉÓïÒô±à½âÂëÏß³ÌG723Proc²éѯ£¬²¢ËÍÈëÏàÓ¦µÄ½âÂëÆ÷¡£ÓÉÓÚʹÓÃÁ˶àÏ̵߳ıà³Ì¼¼Êõ£¬Ê¹µÃ²Ù×÷ϵͳ¶¨Ê±È¥·þÎñÓïÒô±à½âÂëÄ£¿éºÍ´«ÊäÄ£¿é£¬´Ó¶ø±£Ö¤ÁËͨÐŵIJ»Öжϡ£

Îå¡¢³ÌÐòÔ´Âë

//»ùÓÚTCP/IP¿ÉÊӵ绰Ö÷´°¿ÚµÄ´°¿Ú¹ý³Ì

LONG APIENTRY MainWndProc(HWND hWnd,UINT message,UINT wParam,

LONG lParam){

static HANDLE hThreadG7231,hThreadTCPListen,hThreadTCPRev;

DWORDThreadIDG7231,ThreadIDTCPListen,ThreadIDTCPRev;

static THREADPACK tp;

static THREADPACK tp1;

unsigned char Buf[80];

CAPSTATUS capStatus;

switch (message) {

case WM_CREATE:

Init_Wsock(hWnd); //³õʼ»¯Ò»Ð©Êý¾Ý½á¹¹

Init_BS(2,&bs);

vd_tx_pdu.V_S = 0;vd_tx_pdu.N_S = 0;

vd_rx_pdu.V_R = 0;vd_tx_sdu.bytes = 0;

if( dnldProg ( hWnd, "h324g723.exe") )

{//×°ÈëÓïÒô±à½âÂëµÄDSPºËÐÄ

MessageBox(hWnd,"Load G.723.1 Kernel Error","Error",MB_OK);

PostQuitMessage(0); }

else

MessageBox(hWnd,"Load G.723.1 Kernel OK!","Indication",MB_OK);

//´´½¨ÓïÒô±à½âÂëµÄÏß³Ì

parag7231.hWnd = hWnd;

hThreadG7231=CreateThread (NULL, 0,

(LPTHREAD_START_ROUTINE)G723Proc,

(G7231DATA *)?g7231,CREATE_SUSPENDED,

(LPDWORD)&ThreadIDG7231);

if (!hThreadG7231){

wsprintf(Buf, "Error in creating G7231 thread: %d",GetLastError());

MessageBox (hWnd, Buf, "WM_CREATE", MB_OK);}

//´´½¨TCP/IP½ÓÊÕÏß³Ì

tp1.hWnd = hWnd;

hThreadTCPRev = CreateThread (NULL, 0,

(LPTHREAD_START_ROUTINE)AcceptThreadProcRev,

(G7231DATA *)&tp1,CREATE_SUSPENDED,

(LPDWORD)&ThreadIDTCPRev);

if (!hThreadTCPRev){

wsprintf(Buf, "Error in creating TCP Receive thread: %d",GetLastError());

MessageBox (hWnd, Buf, "WM_CREATE", MB_OK);}

//¿ªÊ¼ÕìÌýÍøÂç

SendMessage(hWnd,WM_COMMAND,IDM_LISTEN,NULL);

break;

case WM_VIDEO_ENCODE: //ͼÏó±àÂë

if(needencode)EncodeFunction(hWnd);

needencode = SendVideoToBuff(&vd_tx_sdu, buff);

frameMode=TRUE;

capPreview(capWnd,FALSE);capOverlay(capWnd,FALSE);

capGrabFrameNoStop(capWnd);

break;

case WM_VIDEO_DECODE: //ͼÏó½âÂë

Video_Decod_begin = 1;

play_movie();

Video_Decod_begin = 0;

break;

case WM_COMMAND:

switch(LOWORD(wParam)) {

case IDM_CONNECT: //

ÏìÓ¦¶Ô·½µÄºô½Ð£¬½Óͨ¿ÉÊӵ绰

WskConnect( hWnd );

ResumeThread(hThreadTCPRev);//ÔËÐÐTCP/IP½ÓÊÕÏß³Ì

ResumeThread(hThreadG7231);//ÔËÐÐÓïÒô±à½âÂëÏß³Ì

BeginG7231Codec();

//³õʼ»¯Í¼Ïó²É¼¯¿¨£¬²¢¿ªÊ¼²É¼¯Í¼Ïó

frameMode = FALSE;

capWnd= capCreateCaptureWindow((LPSTR)"Capture Window",

WS_CHILD | WS_VISIBLE,

100, 100, 176,144 ,

(HWND) hWnd, (int) 0) ;

capSetCallbackOnError(capWnd, (FARPROC)ErrorCallbackProc) ;

capSetCallbackOnStatus(capWnd, (FARPROC)StatusCallbackProc) ;

capSetCallbackOnFrame(capWnd, (FARPROC)FrameCallbackProc) ;

capDriverConnect(capWnd, 0);

CenterCaptureWindow(hWnd, capWnd);

capDlgVideoSource(capWnd);

capDlgVideoFormat(capWnd);

capDlgVideoCompression(capWnd);

capGetStatus(capWnd,&capStatus,sizeof(CAPSTATUS));

StartNewVideoChannel(hWnd, capWnd) ;

image = image_one;

frameMode = TRUE;

capPreview(capWnd,FALSE);

capOverlay(capWnd,FALSE);

capGrabFrameNoStop(capWnd);

break;

case IDM_LISTEN: //²¦¶Ô·½ºÅÂ룬ºô½Ð¶Ô·½

sock = socket( AF_INET, SOCK_STREAM, 0);

if (sock == INVALID_SOCKET) {

MessageBox(hWnd, "socket() failed", "Error", MB_OK);

closesocket(sock);

break;}

if (!FillAddr(hWnd, &local_sin, FALSE )) //

»ñÈ¡TCP/IPµØÖ·ºÍ¶Ë¿ÚºÅ

break;

EnableMenuItem(GetMenu( hWnd ), IDM_LISTEN, MF_GRAYED);

SetWindowText( hWnd, "Waiting for connection..");

bind ( sock , (struct sockaddr FAR *)&local_sin,sizeof(local_sin);

if (listen( sock, MAX_PENDING_CONNECTS ) <0) { sprintf(szBuff, "%d is the error", WSAGetLastError()); MessageBox(hWnd, szBuff, "listen(sock) failed", MB_OK); break;} tp.hWnd="hWnd;//¿ªÊ¼±¾µØµÄTCP/IP½ÓÊÕÏß³Ì" _beginthread(AcceptThreadProc,0,&tp); ResumeThread(hThreadG7231); // ¿ªÊ¼±¾µØÓïÒô±à½âÂëµÄÏß³Ì break; case IDM_DISCONNECT: //¹Ò¶Ï¿ÉÊӵ绰 CloseG7231Codec(); SuspendThread(hThreadG7231); SuspendThread(hThreadTCPRev); WSACleanup(); Init_Video_Decod_Again(); capSetCallbackOnError(capWnd, NULL) ; capSetCallbackOnStatus(capWnd, NULL) ; InvalidateRect(hWnd,NULL,1); capSetCallbackOnFrame(capWnd, NULL) ; capSetCallbackOnVideoStream(capWnd, NULL) ; capDriverDisconnect(capWnd); Init_Wsock(hWnd); MessageBox(hWnd, "Now closing the Video telephone","",MB_OK); SetDisConnectMenus(hWnd); SendMessage(hWnd, WM_COMMAND,IDM_LISTEN,NULL); break; case IDM_EXIT: CloseG7231Codec(); SendMessage(hWnd, WM_CLOSE, 0, 0l); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } break; case WM_CLOSE: if (IDOK !="MessageBox(" hWnd, "OK to close window?", gszAppName, MB_ICONQUESTION | MB_OKCANCEL )) break ; case WM_DESTROY: WSACleanup(); CloseG7231Codec(); TerminateThread(hThreadG7231,0); TerminateThread(hThreadTCPRev,0); capSetCallbackOnError(capWnd, NULL) ; capSetCallbackOnStatus(capWnd, NULL) ; capSetCallbackOnFrame(capWnd, NULL) ; capSetCallbackOnVideoStream(capWnd, NULL) ; capDriverDisconnect(capWnd); FreeAll(); PostQuitMessage(0); break; default: /* Passes it on if unproccessed*/ return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0); } //Ö÷½Ð·½TCP/IP½ÓÊÕÏß³Ì DWORD WINAPI AcceptThreadProc( PTHREADPACK ptp ){ SOCKADDR_IN acc_sin;/* Accept socket address internet style*/ int acc_sin_len;/* Accept socket address length */ int status; acc_sin_len="sizeof(acc_sin);" //µ÷ÓÃ×èÈûº¯Êýaccept,Ò»Ö±µ½Ô¶¶ËÏìӦΪֹ sock="accept(" sock,(struct sockaddr FAR *) &acc_sin,(int FAR *) &acc_sin_len ); if (sock < 0) { sprintf(szBuff, "%d is the error", WSAGetLastError()); MessageBox(ptp->hWnd, szBuff, "accept(sock) failed", MB_OK);

return (1);

}

SetConnectMenus( ptp->hWnd ); //Ô¶¶ËÌá»ú£¬¿ÉÊӵ绰½Óͨ

BeginG7231Codec();

while (1) {

beg1: status = recv((SOCKET)sock, r_mux_buf,

MY_MSG_LENGTH, NO_FLAGS_SET );

if (status == SOCKET_ERROR) {

status = WSAGetLastError();

if( status == 10054 ){

MessageBox(ptp->hWnd,"¶Ô·½¹Ò¶Ïµç»°","Indication", MB_OK);

SendMessage( ptp->hWnd, WM_COMMAND,IDM_DISCONNECT,NULL);

_endthread();

return (1);

}

goto beg1;

}

if (status) {

r_mux_buf[ status ] = '\0';

if( r_mux_buf_filled == 1 )

r_mux_buf_overwrite = 1;

else

r_mux_buf_filled = 1;

r_mux_buf_length = status;

}

else {

MessageBox( hWnd, "Connection broken", "Error", MB_OK);

SendMessage( ptp->hWnd, WM_COMMAND,

IDM_DISCONNECT,NULL);

_endthread();

return (2);

}

demux(); //Ïß·ÂëÁ÷H.223½âÂë

}

return (0);

}

//±»½Ð·½TCP/IP½ÓÊÕÏß³Ì

DWORD WINAPI AcceptThreadProcRev( PTHREADPACK ptp ){

int status;

while (1) {

beg2:status = recv((SOCKET)sock, r_mux_buf,

MY_MSG_LENGTH, NO_FLAGS_SET );

if (status == SOCKET_ERROR) {

status =WSAGetLastError();

if( status == 10054 ){

MessageBox(ptp->hWnd,"¶Ô·½¹Ò¶Ïµç»°","Indication", MB_OK);

SendMessage( ptp->hWnd, WM_COMMAND,

IDM_DISCONNECT,NULL);

return (1);

}

goto beg2;

}

if (status) {

r_mux_buf[ status ] = '\0';

if( r_mux_buf_filled == 1 )

r_mux_buf_overwrite = 1;

else

r_mux_buf_filled = 1;

r_mux_buf_length = status;

}

else {

MessageBox( hWnd, "Connection broken", "Error", MB_OK);

SendMessage( ptp->hWnd, WM_COMMAND,

IDM_DISCONNECT,NULL);

return (2);

}

demux();

}/* while (forever) */

return (0);

}

//ÓïÒô±à½âÂëÏß³Ì

DWORD WINAPI G723Proc(G7231DATA *data){

int i,len;

Audio_tx_pduad_tx_pdu;

unsigned char mux[MAX_MUX_PDU_SIZE];

do {

len = 0;

//¼ì²â±¾µØÓÐÎÞÓïÒô£¬Í¼ÏóÂëÁ÷Òª´«Êä

i = DetectAudioVideoData();

switch(i){

case AUDIO_ONLY: //Ö»ÓÐÓïÒôÂëÁ÷

AL2_CRC_coder(&ad_tx_sdu,&ad_tx_pdu);

//H.223´ò°ü

len = AL2_To_MUX(&ad_tx_pdu, mux);

break;

case VIDEO_ONLY://Ö»ÓÐͼÏóÂëÁ÷

SDU_To_PDU(&vd_tx_sdu,&vd_tx_pdu);

tx_AL3_I_PDU(&vd_tx_pdu ,&bs , 1);

//H.223´ò°ü

len = AL3_To_MUX(&vd_tx_pdu,mux);

break;

case AUDIO_VIDEO://ÓïÒôºÍͼÏóÂëÁ÷

AL2_CRC_coder(&ad_tx_sdu,&ad_tx_pdu);

SDU_To_PDU(&vd_tx_sdu,&vd_tx_pdu);

tx_AL3_I_PDU(&vd_tx_pdu ,&bs , 1);

//H.223´ò°ü

len = AL2_AL3_To_MUX(&ad_tx_pdu,&vd_tx_pdu,mux);

break;

case NO_AUDIO_VIDEO://´Ë¿ÌÎÞÂëÁ÷Òª´«Êä

break;

}

//TCP/IP·¢ËÍÂëÁ÷

if(len != 0)

send((SOCKET)sock,mux,len,0);

//ÊÇ·ñ½ÓÊÕµ½´ý½âÂëµÄÂëÁ÷£¬Óо͵÷ÓýâÂëÆ÷

PutVideoStreamToDecod();

} while(1);

return (0);

}

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00381