RegisterApplicationRestart
来源:互联网 发布:windows打开隐藏文件 编辑:程序博客网 时间:2024/05/16 08:09
#include <stdlib.h>
#include <string>
BOOL SetRestartApplication(const TCHAR* commandLine)
{
typedef HRESULT (WINAPI* PFN_RegisterApplicationRestart)(LPWSTR,DWORD);
PFN_RegisterApplicationRestart pfnRegisterApplicationRestart = NULL;
HMODULE hInst = ::GetModuleHandle("kernel32.dll");
if(hInst == NULL) return FALSE;
pfnRegisterApplicationRestart = (PFN_RegisterApplicationRestart)GetProcAddress(hInst,"RegisterApplicationRestart");
if(NULL == pfnRegisterApplicationRestart) return FALSE;
DWORD dwFlags=0,dwRet = S_OK;
#if defined(_UNICODE) ||defined( UNICODE)
dwRet = pfnRegisterApplicationRestart(commandLine,dwFlags);
#else
wchar_t* cmdLine = NULL;
const char * oldLocale = setlocale(LC_CTYPE,NULL);
const char * newLocale = ::setlocale(LC_CTYPE,".936"); //equals ".936","chs",""
int len = mbstowcs(NULL,commandLine,0);
if(len >0)
{
cmdLine = new wchar_t[len+1];
mbstowcs(cmdLine,commandLine,len+1);
dwRet = pfnRegisterApplicationRestart(cmdLine,dwFlags);
delete[] cmdLine;
cmdLine = NULL;
}
else
{
dwRet = S_FALSE;
}
#endif
FreeLibrary(hInst);
if(oldLocale)
{
const char * locale = setlocale(LC_CTYPE,oldLocale);
}
return (dwRet == S_OK);
}
#include <string>
BOOL SetRestartApplication(const TCHAR* commandLine)
{
typedef HRESULT (WINAPI* PFN_RegisterApplicationRestart)(LPWSTR,DWORD);
PFN_RegisterApplicationRestart pfnRegisterApplicationRestart = NULL;
HMODULE hInst = ::GetModuleHandle("kernel32.dll");
if(hInst == NULL) return FALSE;
pfnRegisterApplicationRestart = (PFN_RegisterApplicationRestart)GetProcAddress(hInst,"RegisterApplicationRestart");
if(NULL == pfnRegisterApplicationRestart) return FALSE;
DWORD dwFlags=0,dwRet = S_OK;
#if defined(_UNICODE) ||defined( UNICODE)
dwRet = pfnRegisterApplicationRestart(commandLine,dwFlags);
#else
wchar_t* cmdLine = NULL;
const char * oldLocale = setlocale(LC_CTYPE,NULL);
const char * newLocale = ::setlocale(LC_CTYPE,".936"); //equals ".936","chs",""
int len = mbstowcs(NULL,commandLine,0);
if(len >0)
{
cmdLine = new wchar_t[len+1];
mbstowcs(cmdLine,commandLine,len+1);
dwRet = pfnRegisterApplicationRestart(cmdLine,dwFlags);
delete[] cmdLine;
cmdLine = NULL;
}
else
{
dwRet = S_FALSE;
}
#endif
FreeLibrary(hInst);
if(oldLocale)
{
const char * locale = setlocale(LC_CTYPE,oldLocale);
}
return (dwRet == S_OK);
}
0 0
- RegisterApplicationRestart
- ace bootstrap后台框架-导航栏api
- 最近遇到的若干技术问题
- Linux安装QT SDK
- 【玩转树莓派】之8款最佳Raspberry Pi 操作系统/项目!
- android多线程学习
- RegisterApplicationRestart
- matlab画出的图除了图之外的部分是灰色,如果去除
- HDU2068 RPG的错排 【组合+错排】
- indonesia poker online where the favorites
- SharePoint 2013 工作流平台的选项不可用
- 如何把UltraEDIT 添加到右键打开的快捷方式
- [笔记] 《互联网思维独孤九剑》
- 理解MySQL及其他关系数据库中JOINs用法
- NPOI操作Excel 003:写入空Excel