有 一个 叫  PrevInstance 的句柄检测一下就可以了

解决方案 »

  1.   

    PrevInstance在windows98里好象行不通,我记得在哪本书上看到过PrevIntance在win16可以。但在win32上就因为是完全隔离的空间而行不通了。不知道是不是?好象是CreateMultex?
      

  2.   


        HANDLE  hd=::CreateMutex(NULL,TRUE,*****);
    if(GetLastError()==ERROR_ALREADY_EXISTS) 
    {
    return FALSE; 

    *****为你编译后的EXE文件的的文件名
      

  3.   

    at the beginning of your cpp file#pragma data_seg("YourSec")
    LONG g_Global=0;
    #pragma data_seg()#pragma comment(linker,"/section:YourSec,RWS")at the beginning of your entry point function:if(InterLockedIncrement(g_Global)!=1)
    InterLockedDecrement(g_Global);
    return 0;
      

  4.   

    Oh I am sorry, for a problems:the right code is below:at the beginning of your entry point function:if(InterlockedIncrement(&g_Global)!=1)
    {
        InterlockedDecrement(&g_Global);
        return 0;
    }
      

  5.   

    使用system原子
    //======================================================================
    // 函 数 名: RunAlready
    // 功能描述: 保证程序只运行一次
    // 输入参数: 
    // 输出类型: bool 
    // 创建日期:
    // 修改日期:
    // 作    者:
    // 附加说明:
    //======================================================================
    const char *myAtonstring = "hello";
    ATOM myAtom = 0;
    bool RunAlready()
    {
        myAtom = GlobalFindAtom(myAtonstring);
        if (myAtom != 0) return true;  //已运行
        myAtom = GlobalAddAtom(myAtonstring);
        return false; //没有运行
    }程序结束时:GlobalDeleteAtom(myAtom);GlobalDeleteAtom(myAtom);
      

  6.   

    例如
    BOOL C???App::InitInstance()
    {
        .....
        if(RunAlready())//找到原子
            return false;
     
       .....    
        GlobalDeleteAtom(GlobalAtom);
        return FALSE;
    }
      

  7.   

    看来使用CreateMutex()和用ATOM的办法明显要方便得多。
    不知houjzs()
      

  8.   

    houjzs()你的技术有什么特别的地方?看上去很复杂,是否值得做这么多事?还有没有更好的适用之处?