#define WIN32_LEAN_AND_MEAN #include #include typedef void (*throwFuncType)(); void dothrow_func() { throw 300; } DWORD CALLBACK threadproc( void * ) { printf("BeginThread\n"); int i=0; try{ while(1) { i++; } }catch( int ){ printf("\n%d: catched exception.\n",i); } return 0; } int main() { throwFuncType dothrow_ptr = dothrow_func; DWORD id; HANDLE hThread = CreateThread(NULL,0,threadproc,NULL,0,&id); char t[255]; fgets(t,200,stdin); CONTEXT context; context.ContextFlags = CONTEXT_CONTROL; SuspendThread( hThread); GetThreadContext(hThread, &context); context.Eip = (DWORD)dothrow_ptr; SetThreadContext(hThread, &context); ResumeThread( hThread); WaitForSingleObject(hThread,INFINITE); }