定制main之前或之后的执行代码

/* prepostdemo.c */
#include 
<windows.h>

int WINAPI WinMain(
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   PSTR szCmdLine,
   
int iCmdShow)
{
   MessageBox(NULL, TEXT(
"Hello, Main Program!"), TEXT("Hello"), 0);

   
return 0;
}


int PreMain1(void)
{
   MessageBox(NULL, TEXT(
"First Pre-Main Function"),
                    TEXT(
"PreMain1"), 0);
   
return 0;
}


int PreMain2(void)
{
   MessageBox(NULL, TEXT(
"Second Pre-Main Function"),
                    TEXT(
"PreMain2"), 0);
   
return 0;
}


int PostMain1(void)
{
   MessageBox(NULL, TEXT(
"First Post-Main Function"),
                    TEXT(
"PostMain1"), 0);
   
return 0;
}


int PostMain2(void)
{
   MessageBox(NULL, TEXT(
"Second Post-Main function"),
                    TEXT(
"PostMain2"), 0);
   
return 0;
}


typedef 
int cb(void);

#pragma data_seg(
".CRT$XIU")
static cb *autostart[] = { PreMain1, PreMain2 };

#pragma data_seg(
".CRT$XPU")
static cb *autoexit[] = { PostMain1, PostMain2 };

#pragma data_seg()    
/* reset data-segment */
http://www.codeguru.com/Cpp/misc/misc/threadsprocesses/article.php/c6945__1/
posted @ 2005-11-11 11:21  Rookie.Zhang  阅读(331)  评论(0)    收藏  举报