现在的位置: 首页 > 综合 > 正文

windows调用运行和重启

2013年08月04日 ⁄ 综合 ⁄ 共 1695字 ⁄ 字号 评论关闭

 

void COutRunDlgDlg::OnRun()
{
 CString pszDllName="shell32.dll";
 HINSTANCE hLib = ::LoadLibrary(pszDllName);
 
 typedef void (__stdcall *pRunFileDlg)(HWND, HICON, LPCTSTR, LPCTSTR, LPCTSTR, UINT);
 pRunFileDlg RunFileDlg;
 if (hLib==NULL)
 {
  return ;
 }
 RunFileDlg = (pRunFileDlg)GetProcAddress(hLib, (char *)61);
 CString name ="wolfbaby的运行";
 CString sss = "输入程序路径";
 LPWSTR wname=new WCHAR[100];
 LPWSTR wsss=new WCHAR[100]; 
 memset(wname,0,sizeof(WCHAR)*100);
 memset(wsss,0,sizeof(WCHAR)*100);
 MultiByteToWideChar(CP_ACP,
     MB_PRECOMPOSED,        // character-type options
  name,  // address of string to map
     name.GetLength(),      // number of bytes in string
  wname,  // address of wide-character buffer
  100
  );
 MultiByteToWideChar(CP_ACP,
  MB_PRECOMPOSED,        // character-type options
  sss,  // address of string to map
  sss.GetLength(),      // number of bytes in string
  wsss,  // address of wide-character buffer
  100
  );

 if(RunFileDlg!=NULL)
 {
  RunFileDlg(this->GetSafeHwnd(),NULL,NULL,(LPCTSTR)wname,(LPCTSTR)wsss,0x02);
 }

 ::FreeLibrary(hLib);

  delete []wname;
  delete []wsss;

}

void COutRunDlgDlg::OnRestar()
{
 CString pszDllName="shell32.dll";
 HINSTANCE hLib = ::LoadLibrary(pszDllName);
 
 
 typedef void (__stdcall *pRunFileDlg)(HWND, LPCTSTR, UINT);
 pRunFileDlg RunFileDlg;
 if (hLib==NULL)
 {
  return ;
 }
 RunFileDlg = (pRunFileDlg)GetProcAddress(hLib, (char *)59);
 CString name ="wolfbaby重启";
 wchar_t *wname=new WCHAR[100];
 memset(wname,0,sizeof(WCHAR)*100);
 MultiByteToWideChar(CP_ACP,
  MB_PRECOMPOSED,        // character-type options
  name,  // address of string to map
  name.GetLength(),      // number of bytes in string
  wname,  // address of wide-character buffer
  100
  );
    if(RunFileDlg!=NULL)
 {
  RunFileDlg(this->GetSafeHwnd(),(LPCTSTR)wname,0x02);
 }
 
 ::FreeLibrary(hLib);
 delete []wname;
}

抱歉!评论已关闭.