C++单实例——节

来源:互联网 发布:数据分析师的就业调查 编辑:程序博客网 时间:2024/06/03 16:08

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;}