VS2010新建win32空工程,加入C++代码:
#include <windows.h>
#pragma data_seg("Shared") //创建新节
int volatile g_lAppInstance =0; //必须有初示化
#pragma data_seg() //结束
#pragma comment(linker,"/section:Shared,RWS")
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if(++g_lAppInstance>1)
{
MessageBox(NULL, L"程序已经运行!",NULL,NULL);
ExitProcess(0);
}
while(1);
return 0;
}