首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

创建线程时Windows是怎么填充CONTEXT结构体的

2012-03-11 
创建线程时Windows是如何填充CONTEXT结构体的?请问在使用CreateThread函数时,StartProcess和Param两个参数

创建线程时Windows是如何填充CONTEXT结构体的?
请问在使用CreateThread函数时,StartProcess和Param两个参数如何填入的CONTEXT,而后NtCreateThread又如何处理?

[解决办法]
楼主想问的是这个吗?下面是MSDN中的代码,我对Windows的多进程多线程不熟悉...

C/C++ code
#include <windows.h>#include <conio.h>DWORD WINAPI ThreadFunc( LPVOID lpParam ) {     char szMsg[80];    wsprintf( szMsg, "Parameter = %d.", *(DWORD*)lpParam );     MessageBox( NULL, szMsg, "ThreadFunc", MB_OK );    return 0; }  VOID main( VOID ) {     DWORD dwThreadId, dwThrdParam = 1;     HANDLE hThread;     char szMsg[80];    hThread = CreateThread(         NULL,                        // default security attributes         0,                           // use default stack size          ThreadFunc,                  // thread function         &dwThrdParam,                // argument to thread function         0,                           // use default creation flags         &dwThreadId);                // returns the thread identifier     // Check the return value for success.     if (hThread == NULL)    {      wsprintf( szMsg, "CreateThread failed." );       MessageBox( NULL, szMsg, "main", MB_OK );   }   else    {      _getch();      CloseHandle( hThread );   }}
[解决办法]
参考:

http://www.blog.edu.cn/user4/beiyu/archives/2006/1594977.shtml
[解决办法]
注意这个函数:

C/C++ code
BaseInitializeContext(PCONTEXT Context, // 0x200 bytesPPEB Peb,PVOID EntryPoint,DWORD StackTop,int Type // union (Process, Thread, Fiber));
[解决办法]
内核调试器 like Softice

热点排行