是这样的,我想在程序运行时把自己的路径写入注册表,以便下次启动机器时自己运行。GetCurrentDirectory 得到的似乎是运行程序时的“当时目录”,而不是程序本身所在的目录:)多谢!:D

解决方案 »

  1.   

    我现在的情况是~~~~假定可执行文件放在 d:\my documents\hello.exe,  用资源管理器浏览到 hello.exe ,运行后程序把自己写入注册表 windows/currentversion/run  里,写的是 "d:\my documents\hello.exe" 
    重启机器,系统自动找到 d:\my documents\hello.exe 并执行,但这个时候写主注册表的就是 C:\hello.exe 了:D
      

  2.   

    CString strAppName;
    GetModuleFileName(AfxGetApp()->m_hInstance,strAppName.GetBuffer(MAX_PATH),MAX_PATH);
    strAppName.ReleaseBuffer();
      

  3.   

    CString Path;
        GetModuleFileName(NULL,Path.GetBufferSetLength(MAX_PATH+1),MAX_PATH);用这个获得当前文件