当前位置:首页 » 多媒体相关

写注册表时遇到的问题,帮忙看看


我用下面两段代码分别获得可执行程序的路径和写入注册表,程序可以执行,但是却没有写进注册表,问题可能出在哪里啊,帮忙看看  
  void   cstartupprogdlg::ongetfile()   //获得可执行程序的路径  
  {  
  //   todo:   add   your   control   notification   handler   code   here  
  static   char   szfilter[]="(*.exe)|*.exe";  
  cfiledialog   openfiledlg(  
  true,"*.tpe",null,ofn_hidereadonly,szfilter);  
  if(openfiledlg.domodal()==idcancel)  
  return;  
  m_strfilename=openfiledlg.getpathname();  
  setdlgitemtext(idc_edit,lpctstr(m_strfilename));  
   
  }  
   
  void   cstartupprogdlg::onsetasstartupprog()   //写入注册表  
  {  
  //   todo:   add   your   control   notification   handler   code   here  
  hkey   hkey;  
  cstring   skeyname;  
  unsigned   char   szfilepath[100];  
  long   lnres=regopenkeyex(  
  hkey_local_machine,  
  "software\\microsoft\\windows\\currentversion\\run",  
  0l,  
  key_write,  
  &hkey  
  );  
  lstrcpy((char*)szfilepath,lpctstr(m_strfilename));  
  if(error_success==lnres)  
  {  
  lnres=regsetvalueex(hkey,  
  lpctstr(skeyname),  
  0,  
  reg_sz,  
  szfilepath,  
  reg_sz);  
  if(error_success==lnres)  
  afxmessagebox("已经成功加载此应用程序!");  
  else  
  afxmessagebox("不能加载此应用程序!");  
  }  
  else  
  {  
  afxmessagebox("不能加载此应用程序!");  
  }  
   
   
   
   
  }

推荐阅读

  • 04.光照滤镜的学习 [详细内容]
  • 三星手机使用技巧 [详细内容]
  • 关于T408出现限制服务的处理方法 [详细内容]
  • 02.像素化滤镜制作冰晶字 [详细内容]
  • ACDSee32的使用技巧 [详细内容]
  • 惠普h6365初次使用设定 [详细内容]
  • 02.利用切变滤镜制作红旗 [详细内容]
  • 网友回答:
    网友:foxmail

    setregistrykey(_t("..."));了吗?  
     

    网友:zzqzzq

    在lnres=regsetvalueex(hkey,  
      lpctstr(skeyname),  
      0,  
      reg_sz,  
      szfilepath,  
      reg_sz);  
      中,最后一个参数应为m_strfilename.getlength()+1.

    网友:titi_lima

    lnres=regsetvalueex(hkey,  
      lpctstr(skeyname),   //   这个值没有初始化  
      0,  
      reg_sz,  
      szfilepath,  
      reg_sz);

    网友:zzqzzq

    写错了,应为strlen((char*)szfilepath)+1.

    .

    讨论区

    Login