DWORD watcher(LPVOID arg) { HANDLE heap = GetProcessHeap(), handle; STARTUPINFO startupinfo; LPPROCESS_INFORMATION cc_procinfo; LPTSTR lpCmdLine = arg; LPTSTR argv0; LPTSTR srcpath; LPTSTR cc_cmdline; TCHAR tmpdir[MAX_PATH]; TCHAR fullExecutablePath[MAX_PATH]; PTSTR spc = StrChr(lpCmdLine, ' '); if(spc == NULL) { argv0 = HeapAlloc(heap, 0, lstrlen(lpCmdLine)+1); StringCbCat(argv0, lstrlen(lpCmdLine), lpCmdLine); } else { argv0 = HeapAlloc(heap, 0, spc-lpCmdLine+1); StringCbCat(argv0, spc-lpCmdLine, lpCmdLine); } GetModuleFileName(NULL, fullExecutablePath, MAX_PATH); size_t len = lstrlen(fullExecutablePath)+1; srcpath = HeapAlloc(heap, 0, len); StringCbCat(srcpath, len-4, fullExecutablePath); StringCchCat(srcpath, len, ".c"); printf("srcpath is \"%s\"\n", srcpath); //WaitForSingleFile(srcpath, FILE_NOTIFY_LAST_WRITE); ZeroMemory(&startupinfo, sizeof(STARTUPINFO)); startupinfo.cb = sizeof(STARTUPINFO); size_t cclen = lstrlen(CC)+1+len-1+4+lstrlen(argv0)+1; cc_cmdline = HeapAlloc(heap, 0, cclen); StringCbCat(cc_cmdline, cclen, CC); StringCchCat(cc_cmdline, cclen, " "); StringCchCat(cc_cmdline, cclen, srcpath); StringCchCat(cc_cmdline, cclen, " -o "); StringCchCat(cc_cmdline, cclen, argv0); printf("cc_cmdline is \"%s\"\n", cc_cmdline); return 0; CreateProcess(NULL, cc_cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &startupinfo, cc_procinfo); HeapFree(heap, 0, argv0); HeapFree(heap, 0, srcpath); HeapFree(heap, 0, cc_cmdline); WaitForSingleObject(cc_procinfo->hProcess, INFINITE); printf("Execing...\n"); CreateProcess(NULL, lpCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &startupinfo, cc_procinfo); ExitProcess(0); }
static void create_minidump() { HANDLE dumpfile = INVALID_HANDLE_VALUE; if (!set_dump_privileges()) { fputws(L"Unable to adjust privileges to create minidump\n", stderr); goto cleanup; } DWORD const buf_size = MAX_PATH * 2; wchar_t dump_filename[buf_size]; ::GetTempPathW(buf_size, dump_filename); StringCbCat(dump_filename, buf_size, *app_name_? app_name_ : L"app"); StringCbCat(dump_filename, buf_size, L"-crash.dmp"); dumpfile = ::CreateFile(dump_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (dumpfile == INVALID_HANDLE_VALUE) { fputws(L"Unable to create minidump file ", stderr); fputws(dump_filename, stderr); goto cleanup; } MINIDUMP_TYPE const dump_type = MiniDumpWithFullMemory;//MiniDumpNormal; MINIDUMP_EXCEPTION_INFORMATION dump_exception_info; dump_exception_info.ThreadId = ::GetCurrentThreadId(); dump_exception_info.ExceptionPointers = exception_pointers_; dump_exception_info.ClientPointers = false; if (!::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), dumpfile, dump_type, &dump_exception_info, nullptr, nullptr)) { fputws(L"Unable to write minidump file ", stderr); fputws(dump_filename, stderr); goto cleanup; } fputws(L"Minidump has been written to ", stderr); fputws(dump_filename, stderr); if (*report_contact_) { fputws(L"Please send it to ", stderr); fputws(report_contact_, stderr); } cleanup: if (dumpfile != INVALID_HANDLE_VALUE) { ::CloseHandle(dumpfile); } }
/*F+F++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Function: SetRegKeyValue Summary: Internal utility function to set a Key, Subkey, and value in the system Registry under HKEY_CLASSES_ROOT. Args: LPTSTR pszKey, LPTSTR pszSubkey, LPTSTR pszValue) Returns: BOOL TRUE if success; FALSE if not. ------------------------------------------------------------------------F-F*/ BOOL SetRegKeyValue( LPTSTR pszKey, LPTSTR pszSubkey, LPTSTR pszValue) { BOOL bOk = FALSE; HRESULT hr; LONG ec; HKEY hKey; TCHAR szKey[MAX_STRING_LENGTH]; hr = StringCbCopy(szKey, sizeof(szKey), pszKey); assert(hr == S_OK); if (NULL != pszSubkey) { hr = StringCbCat(szKey, sizeof(szKey), TEXT("\\")); assert(hr == S_OK); hr = StringCbCat(szKey, sizeof(szKey), pszSubkey); assert(hr == S_OK); } ec = RegCreateKeyEx( HKEY_CLASSES_ROOT, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if (NULL != pszValue && ERROR_SUCCESS == ec) { ec = RegSetValueEx( hKey, NULL, 0, REG_SZ, (BYTE *)pszValue, (lstrlen(pszValue)+1)*sizeof(TCHAR)); if (ERROR_SUCCESS == ec) bOk = TRUE; RegCloseKey(hKey); } return bOk; }
static BOOL DeleteDir(char * path) { WIN32_FIND_DATA finddata; HANDLE hfind = NULL; char * pdir; int nDirLength = strlen( path ) + 16; pdir=new char[nDirLength]; ZeroMemory( pdir, nDirLength ); StringCbCopy( pdir, nDirLength, path ); if(path[strlen(path)-1]!='\\') StringCbCat( pdir, nDirLength, "\\*.*" ); else StringCbCat( pdir, nDirLength, "*.*" ); hfind=FindFirstFile(pdir,&finddata); if(hfind==INVALID_HANDLE_VALUE) return FALSE; delete []pdir; do { int nPathLength = strlen(path)+strlen(finddata.cFileName)+16; pdir=new char[nPathLength]; ZeroMemory( pdir, nPathLength ); _stprintf_s( pdir, nPathLength, "%s\\%s", path, finddata.cFileName ); if(strcmp(finddata.cFileName,".")==0 ||strcmp(finddata.cFileName,"..")==0) { delete []pdir; pdir = NULL; RemoveDirectory(pdir); continue; } if((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0) DeleteFile(pdir); else DeleteDir(pdir); delete []pdir; pdir = NULL; }while(FindNextFile(hfind,&finddata)); FindClose( hfind ); hfind = NULL; if(RemoveDirectory(path)) return TRUE; else return FALSE; }
/* 缓存目录 */ static CString GetCacheDirectory() { #if 0 char szModule[MAX_PATH*2] = {0}; GetModuleFileName( NULL, szModule, MAX_PATH*2 ); if ( !PathFileExists( szModule ) ) { return ""; } char* pTemp = strrchr( szModule, '\\' ); if ( pTemp == NULL ) { return ""; } szModule[ pTemp-szModule ] = '\0'; StringCbCat( szModule, MAX_PATH*2, "\\RunCache" ); if ( !PathFileExists( szModule ) ) { if ( !MakeSureDirectoryPathExists( szModule ) ) { return ""; } } return szModule; #else CString sCacheDirectory = GetPeraGlobalDataFromReg( "LM", "PeraPRCacheDir" ); if ( MakeSureDirectoryPathExists( sCacheDirectory ) ) { } return sCacheDirectory; #endif }
static LRESULT CALLBACK notifier_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == TOKEN_MESSAGE_ID) { switch (lParam) { case NIN_SELECT: case NIN_KEYSELECT: { NOTIFYICONDATA idata; khm_int32 cmd = KHUI_ACTION_OPEN_APP; khc_read_int32(NULL, L"CredWindow\\NotificationAction", &cmd); khui_action_trigger(cmd, NULL); ZeroMemory(&idata, sizeof(idata)); Shell_NotifyIcon(NIM_SETFOCUS, &idata); } return 0; case WM_CONTEXTMENU: handle_context_menu(); return TRUE; default: return 0; } } else if (uMsg == WM_COMMAND) { switch (LOWORD(wParam)) { case ID_DEFAULT: { khm_int32 cmd; cmd = get_default_notifier_action(); khui_action_trigger(cmd, NULL); } return TRUE; case ID_SHOWHELP: { wchar_t helploc[MAX_PATH + MAX_PATH]; get_help_file(helploc, sizeof(helploc)); StringCbCat(helploc, sizeof(helploc), L"::index.html"); HtmlHelp(notifier_window, helploc, HH_DISPLAY_TOPIC, 0); } return TRUE; } } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
HRESULT CModuleHashNode::RectifyFileName(LPCTSTR pszPath, DWORD cbPath) { HRESULT hr = S_OK; TCHAR szBuf[MAX_PATH+1], *pszTemp; hr = StringCbCopy(szBuf, sizeof(szBuf), _szPath); if (FAILED(hr)) { goto exit; } pszTemp = PathFindFileName (szBuf); if (pszTemp <= szBuf) { hr = HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME); goto exit; } *(pszTemp) = TEXT('\0'); if( (lstrlenW(szBuf) + cbPath) > MAX_PATH ) { hr = FUSION_E_INVALID_NAME; goto exit; } hr = StringCbCat(szBuf, sizeof(szBuf), pszPath); if (FAILED(hr)) { goto exit; } if ( !WszMoveFile(_szPath, szBuf) ) { BOOL fExists = FALSE; HRESULT hrTmp = HRESULT_FROM_WIN32(GetLastError()); // Preserve the MoveFile error hr = CheckFileExistence(szBuf, &fExists, NULL); if(FAILED(hr)) { goto exit; } else if(!fExists) { hr = hrTmp; goto exit; } // someone else already downloaded this file. WszDeleteFile(_szPath); hr = S_OK; } exit: return hr; }
void dotitle(Char **vc, struct command * c) { int k; char titlebuf[512]; char errbuf[128],err2[128]; char **v; Char **nvc; UNREFERENCED_PARAMETER(c); vc++; nvc = glob_all_or_error(vc); if (nvc == NULL) return; if (nvc != vc) cleanup_push(nvc, blk_cleanup); if ((k = GetConsoleTitle(titlebuf, sizeof(titlebuf))) != 0) { setcopy(STRoldtitle,str2short(titlebuf), VAR_READWRITE|VAR_NOGLOB); } titlebuf[0] = '\0'; v = short2blk(nvc); if (nvc != vc) cleanup_until(nvc); cleanup_push((Char **)v, blk_cleanup); for (k = 0; v[k] != NULL ; k++){ __try { StringCbCat(titlebuf,sizeof(titlebuf),v[k]); StringCbCat(titlebuf,sizeof(titlebuf)," "); } __except(GetExceptionCode()) { stderror(ERR_TOOMANY); } } if (!SetConsoleTitle(titlebuf) ) { make_err_str(GetLastError(),errbuf,128); (void)StringCbPrintf(err2,sizeof(err2),"%s",v[k]); stderror(ERR_SYSTEM,err2,errbuf); } cleanup_until((Char **)v); return; }
// // Write the captured wave data to an output file so that it can be examined later. // void SaveWaveData(BYTE *CaptureBuffer, size_t BufferSize, const WAVEFORMATEX *WaveFormat) { wchar_t waveFileName[MAX_PATH]; HRESULT hr = StringCbCopy(waveFileName, sizeof(waveFileName), L"WASAPICaptureEventDriven-"); if (SUCCEEDED(hr)) { GUID testGuid; if (SUCCEEDED(CoCreateGuid(&testGuid))) { wchar_t *guidString; if (SUCCEEDED(StringFromCLSID(testGuid, &guidString))) { hr = StringCbCat(waveFileName, sizeof(waveFileName), guidString); if (SUCCEEDED(hr)) { hr = StringCbCat(waveFileName, sizeof(waveFileName), L".WAV"); if (SUCCEEDED(hr)) { HANDLE waveHandle = CreateFile(waveFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (waveHandle != INVALID_HANDLE_VALUE) { if (WriteWaveFile(waveHandle, CaptureBuffer, BufferSize, WaveFormat)) { printf("Successfully wrote WAVE data to %S\n", waveFileName); } else { printf("Unable to write wave file\n"); } CloseHandle(waveHandle); } else { printf("Unable to open output WAV file %S: %d\n", waveFileName, GetLastError()); } } } CoTaskMemFree(guidString); } } } }
TIFILE_t* ImportZipFile(LPCTSTR filePath, TIFILE_t *tifile) { unzFile uf; TCHAR path[MAX_PATH]; uf = unzOpen(filePath); StringCbCopy(path, sizeof(path), _tgetenv(_T("appdata"))); StringCbCat(path, sizeof(path), _T("\\Wabbitemu")); int err = extract_zip(uf, path); unzClose(uf); return err ? NULL: tifile; }
void HttpRequest::FetchGravatarForEmail() { unsigned char ehash[MD5LEN]; { char email[1024]; DWORD d; size_t len; if (WideCharToMultiByte(CP_UTF8, 0, m_target.c_str(), -1, email, sizeof(email), NULL, NULL) == 0) { ReportStatus(KHERR_ERROR, L"Can't convert email address to UTF-8", L"%s", GetLastErrorString().c_str()); return; } _strlwr_s(email, sizeof(email)); if (FAILED(StringCbLengthA(email, sizeof(email), &len))) { ReportStatus(KHERR_ERROR, L"UTF-8 email address too long", L"The email address can't be longer than 1024 characters"); return; } d = sizeof(ehash); if (KHM_FAILED(hash_data((BYTE *) email, (DWORD)len, CALG_MD5, (BYTE *) ehash, &d))) { ReportStatus(KHERR_ERROR, L"Failed to hash email address", NULL); return; } } { wchar_t resource[60]; wchar_t * tail; size_t len; int i; static const wchar_t hexdigits[] = L"0123456789abcdef"; StringCbCopyEx(resource, sizeof(resource), L"/avatar/", &tail, &len, STRSAFE_NO_TRUNCATION); for (i = 0; i < sizeof(ehash); i++) { *tail++ = hexdigits[ehash[i] >> 4]; *tail++ = hexdigits[ehash[i] & 0xf]; len -= sizeof(wchar_t) * 2; } *tail++ = L'\0'; StringCbCat(resource, sizeof(resource), L".jpg?d=404&s=128"); FetchResource(L"www.gravatar.com", resource, jpg_mimetypes); } }
HRESULT LoadConfigurationFile() { DWORD count = 0; HRESULT hRes = S_OK; HANDLE hFile; CHAR lpProfile[MAX_PATH] = { 0 }; LPTSTR lpConfHost = NULL; LPTSTR lpConfPort = NULL; count = GetEnvironmentVariable("userprofile", lpProfile, MAX_PATH); if (count == 0 || count > MAX_PATH){ return E_FAIL; } hRes = StringCbCat(lpProfile, MAX_PATH, CONF_FILE); if FAILED(hRes){ return E_FAIL; } hFile = CreateFile(lpProfile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE){ return E_FAIL; } CloseHandle(hFile); lpConfHost = (LPTSTR)malloc(MAX_PATH); lpConfPort = (LPTSTR)malloc(MAX_PATH); if (lpConfHost == NULL || lpConfPort == NULL){ goto failed; } count = GetPrivateProfileString("INTERFACE", "host", "127.0.0.1", lpConfHost, MAX_PATH, lpProfile); if ((count == 0) || (count >= (MAX_PATH - 2))){ goto failed; } count = GetPrivateProfileString("INTERFACE", "port", "9100", lpConfPort, MAX_PATH, lpProfile); if ((count == 0) || (count >= (MAX_PATH - 2))){ goto failed; } g_DefaultHost = lpConfHost; g_DefaultPort = lpConfPort; g_ExtConfFile = true; return hRes; failed: if (lpConfHost != NULL){ free(lpConfHost); } if (lpConfPort != NULL){ free(lpConfPort); } return E_FAIL; }
char * AclToString(struct Acl *acl) { static char mydata[AFS_PIOCTL_MAXSIZE]; char tstring[AFS_PIOCTL_MAXSIZE]; char dfsstring[30]; struct AclEntry *tp; if (acl->dfs) { if( FAILED(StringCbPrintf(dfsstring, sizeof(dfsstring), " dfs:%d %s", acl->dfs, acl->cell))) { fprintf (stderr, "dfsstring - cannot be populated"); exit(1); } } else { dfsstring[0] = '\0'; } if( FAILED(StringCbPrintf(mydata, sizeof(mydata), "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus))) { fprintf (stderr, "mydata - cannot be populated"); exit(1); } for (tp = acl->pluslist;tp;tp=tp->next) { if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) { fprintf (stderr, "tstring - cannot be populated"); exit(1); } if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) { fprintf (stderr, "mydata - not enough space"); exit(1); } } for (tp = acl->minuslist;tp;tp=tp->next) { if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) { fprintf (stderr, "tstring - cannot be populated"); exit(1); } if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) { fprintf (stderr, "mydata - not enough space"); exit(1); } } return mydata; }
// 'png' can be NULL if there is no current file. void Viewer::UpdateViewerWindowTitle() { TCHAR title[500]; if(!m_hwndViewer) return; title[0]='\0'; if(m_filename_base[0]) { StringCbPrintf(title,sizeof(title),_T("%s - "),m_filename_base); } StringCbCat(title,sizeof(title),_T("TweakPNG Image Viewer")); if(!globals.use_gamma) { StringCbCat(title,sizeof(title),_T(" [gamma off]")); } if(!globals.use_custombg && !globals.use_imagebg) { StringCbCat(title,sizeof(title),_T(" [background off]")); } ::SetWindowText(m_hwndViewer,title); }
/** * @name KmtLoadDriver * * Load the specified special-purpose driver (create/start the service) * * @param ServiceName * Name of the driver service (Kmtest- prefix will be added automatically) * @param RestartIfRunning * TRUE to stop and restart the service if it is already running */ VOID KmtLoadDriver( IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning) { DWORD Error = ERROR_SUCCESS; WCHAR ServicePath[MAX_PATH]; StringCbCopy(ServicePath, sizeof ServicePath, ServiceName); StringCbCat(ServicePath, sizeof ServicePath, L"_drv.sys"); StringCbCopy(TestServiceName, sizeof TestServiceName, L"Kmtest-"); StringCbCat(TestServiceName, sizeof TestServiceName, ServiceName); Error = KmtCreateAndStartService(TestServiceName, ServicePath, NULL, &TestServiceHandle, RestartIfRunning); if (Error) { // TODO __debugbreak(); } }
void CTimeMApp::LoadTitleSettings() { TCHAR szBakPath[MAX_PATH]; GetModuleFileName(NULL, szBakPath, MAX_PATH); PathRemoveFileSpec(szBakPath); StringCbCat(szBakPath, MAX_PATH, _T("\\UserData")); m_Params.SetMaxBak(GetProfileInt(_T("Settings"), _T("MaxBackup"), 3)); m_Params.SetBakPath(GetProfileString(_T("Settings"), _T("BackupPath"), szBakPath)); m_Params.SetStartDelay(GetProfileInt(_T("Settings"), _T("StartDelay"), 0)); m_Params.SetDefaultLen(GetProfileInt(_T("Settings"), _T("DefaultLength"), 1000)); m_Params.SetAutoSave(GetProfileInt( _T("Settings"), _T("IsAutoSave"), TRUE)); m_Params.SetZipToolsPath(GetProfileString( _T("Settings"), _T("ZipToolPath"))); }
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F Function: DllUnregisterServer Summary: The standard exported function that can be called to command this DLL server to unregister itself from the system Registry. Args: void. Returns: HRESULT NOERROR F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/ STDAPI DllUnregisterServer(void) { HRESULT hr = NOERROR; TCHAR szID[GUID_SIZE+1]; TCHAR szCLSID[GUID_SIZE+1]; TCHAR szTemp[GUID_SIZE+1]; /*------------------------------------------------------------------------- Delete registry entries for the Ball Component. -------------------------------------------------------------------------*/ //Create some base key strings. StringFromGUID2(CLSID_Ball, szID, GUID_SIZE); hr = StringCbCopy(szCLSID, sizeof(szCLSID), TEXT("CLSID\\")); assert(hr == S_OK); hr = StringCbCat(szCLSID, sizeof(szCLSID), szID); assert(hr == S_OK); RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("DllBall\\CurVer")); RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("DllBall\\CLSID")); RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("DllBall")); RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("DllBall1.0\\CLSID")); RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("DllBall1.0")); hr = StringCbPrintf(szTemp, sizeof(szTemp), TEXT("%s\\%s"), szCLSID, TEXT("ProgID")); assert(hr == S_OK); RegDeleteKey(HKEY_CLASSES_ROOT, szTemp); hr = StringCbPrintf(szTemp, sizeof(szTemp), TEXT("%s\\%s"), szCLSID, TEXT("VersionIndependentProgID")); assert(hr == S_OK); RegDeleteKey(HKEY_CLASSES_ROOT, szTemp); hr = StringCbPrintf(szTemp, sizeof(szTemp), TEXT("%s\\%s"), szCLSID, TEXT("NotInsertable")); assert(hr == S_OK); RegDeleteKey(HKEY_CLASSES_ROOT, szTemp); hr = StringCbPrintf(szTemp, sizeof(szTemp), TEXT("%s\\%s"), szCLSID, TEXT("InprocServer32")); assert(hr == S_OK); RegDeleteKey(HKEY_CLASSES_ROOT, szTemp); RegDeleteKey(HKEY_CLASSES_ROOT, szCLSID); return hr; }
/** * @name KmtOpenDriver * * Open special-purpose driver (acquire a device handle) */ VOID KmtOpenDriver(VOID) { DWORD Error = ERROR_SUCCESS; WCHAR DevicePath[MAX_PATH]; StringCbCopy(DevicePath, sizeof DevicePath, L"\\\\.\\Global\\GLOBALROOT\\Device\\"); StringCbCat(DevicePath, sizeof DevicePath, TestServiceName); TestDeviceHandle = CreateFile(DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (TestDeviceHandle == INVALID_HANDLE_VALUE) error(Error); if (Error) { // TODO __debugbreak(); } }
int parse_cmd_line(int argc, _TCHAR * argv[]) { int i; if(argc == 1) { return show_usage(argv[0]); } for(i=1; i<argc; i++) { if(!_tcscmp(argv[i], _T("-d"))) { if(++i < argc && _tcslen(argv[i]) < MAX_PATH) { size_t len; StringCbCopy(test_dir, sizeof(test_dir), argv[i]); StringCbLength(test_dir, sizeof(test_dir), &len); if(len > 0 && test_dir[len-1] != _T('\\')) StringCbCat(test_dir, sizeof(test_dir), _T("\\")); } else { return show_usage(argv[0]); } } else if (!_tcscmp(argv[i], _T("-nr"))) { tst_read_write = FALSE; } else if(!_tcscmp(argv[i], _T("-child"))) { isChild = TRUE; } else if(!_tcscmp(argv[i], _T("-p"))) { tst_pause = TRUE; } else if(!_tcscmp(argv[i], _T("-wS"))) { tst_wlock_single = TRUE; } else if(!_tcscmp(argv[i], _T("-wP"))) { tst_wlock_parent = TRUE; } else if(!_tcscmp(argv[i], _T("-wC"))) { tst_wlock_child = TRUE; } else { cerr << "Invalid option : " << argv[i] << "\n"; return show_usage(argv[0]); } } return 0; }
BOOL CSaveOptionPage::OnInitDialog() { TCHAR szBakPath[MAX_PATH]; GetModuleFileName(NULL, szBakPath, MAX_PATH); PathRemoveFileSpec(szBakPath); StringCbCat(szBakPath, MAX_PATH, _T("\\UserData")); m_nTimeDelay = AfxGetApp()->GetProfileInt(_T("Settings"), _T("BackupTime"), 10); m_nMaxBak = AfxGetApp()->GetProfileInt(_T("Settings"), _T("MaxBackup"), 3); m_strBakPath = AfxGetApp()->GetProfileString(_T("Settings"), _T("BackupPath"), szBakPath); CPropertyPage::OnInitDialog(); // TODO: Add extra initialization here CheckDlgButton(IDC_CHK_AUTOSAVE, AfxGetApp()->GetProfileInt(_T("Settings"), _T("IsAutoSave"), TRUE)); CheckDlgButton(IDC_CHK_AUTOBAK, AfxGetApp()->GetProfileInt(_T("Settings"), _T("IsAutoBackup"), TRUE)); CheckDlgButton(IDC_CHK_SRTASSOCIATE, HasRegistered(_T(".srt"))); CheckDlgButton(IDC_CHK_ASSASSOCIATE, HasRegistered(_T(".ass"))); CheckDlgButton(IDC_CHK_SSAASSOCIATE, HasRegistered(_T(".ssa"))); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
/** * @name KmtCreateService * * Create the specified driver service and return a handle to it * * @param ServiceName * Name of the service to create * @param ServicePath * File name of the driver, relative to the current directory * @param DisplayName * Service display name * @param ServiceHandle * Pointer to a variable to receive the handle to the service * * @return Win32 error code */ DWORD KmtCreateService( IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, OUT SC_HANDLE *ServiceHandle) { DWORD Error = ERROR_SUCCESS; WCHAR DriverPath[MAX_PATH]; HRESULT result = S_OK; assert(ServiceHandle); assert(ServiceName && ServicePath); if (!GetModuleFileName(NULL, DriverPath, sizeof DriverPath / sizeof DriverPath[0])) error_goto(Error, cleanup); assert(wcsrchr(DriverPath, L'\\') != NULL); wcsrchr(DriverPath, L'\\')[1] = L'\0'; result = StringCbCat(DriverPath, sizeof DriverPath, ServicePath); if (FAILED(result)) error_value_goto(Error, result, cleanup); if (GetFileAttributes(DriverPath) == INVALID_FILE_ATTRIBUTES) error_goto(Error, cleanup); *ServiceHandle = CreateService(ScmHandle, ServiceName, DisplayName, SERVICE_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, DriverPath, NULL, NULL, NULL, NULL, NULL); if (!*ServiceHandle) error_goto(Error, cleanup); cleanup: return Error; }
STDAPI DllUnregisterServer(void) { char szID[128]; WCHAR wcID[128]; char szCLSID[128]; size_t * intReturnValue = NULL; HKEY hKey; // Create the path using the CLSID memset(wcID, NULL, sizeof(wcID)); memset(szID, NULL, sizeof(szID)); StringFromGUID2(CLSID_methodprovider, wcID, sizeof(wcID)/sizeof(WCHAR)); wcstombs_s(intReturnValue, szID, sizeof(szID), wcID, sizeof(szID)); StringCbCopy(szCLSID, sizeof(szCLSID), "Software\\classes\\CLSID\\"); StringCbCat(szCLSID, sizeof(szCLSID), (LPCTSTR)szID); // First delete the InProcServer subkey. DWORD dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCLSID, 0, KEY_WRITE, &hKey); if(dwRet == NO_ERROR) { RegDeleteKey(hKey, "InProcServer32"); RegCloseKey(hKey); } dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\CLASSES\\CLSID\\"), 0, KEY_WRITE, &hKey); if(dwRet == NO_ERROR) { RegDeleteKey(hKey,szID); RegCloseKey(hKey); } return NOERROR; }
static VOID SearchScreenSavers(HWND hwndScreenSavers, LPCTSTR pszSearchPath, PDATA pData) { WIN32_FIND_DATA fd; TCHAR szSearchPath[MAX_PATH]; HANDLE hFind; ScreenSaverItem *ScreenSaverItem; HANDLE hModule; UINT i, ScreenSaverCount; HRESULT hr; ScreenSaverCount = pData->ScreenSaverCount; hr = StringCbCopy(szSearchPath, sizeof(szSearchPath), pszSearchPath); if (FAILED(hr)) return; hr = StringCbCat(szSearchPath, sizeof(szSearchPath), TEXT("\\*.scr")); if (FAILED(hr)) return; hFind = FindFirstFile(szSearchPath, &fd); if (hFind == INVALID_HANDLE_VALUE) return; while (ScreenSaverCount < MAX_SCREENSAVERS) { /* Don't add any hidden screensavers */ if ((fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) { TCHAR filename[MAX_PATH]; hr = StringCbCopy(filename, sizeof(filename), pszSearchPath); if (FAILED(hr)) { FindClose(hFind); return; } hr = StringCbCat(filename, sizeof(filename), _T("\\")); if (FAILED(hr)) { FindClose(hFind); return; } hr = StringCbCat(filename, sizeof(filename), fd.cFileName); if (FAILED(hr)) { FindClose(hFind); return; } ScreenSaverItem = pData->ScreenSaverItems + ScreenSaverCount; ScreenSaverItem->bIsScreenSaver = TRUE; hModule = LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); if (hModule) { if (0 == LoadString(hModule, 1, ScreenSaverItem->szDisplayName, sizeof(ScreenSaverItem->szDisplayName) / sizeof(TCHAR))) { // If the string does not exists, copy the name of the file hr = StringCbCopy(ScreenSaverItem->szDisplayName, sizeof(ScreenSaverItem->szDisplayName), fd.cFileName); if (FAILED(hr)) { FreeLibrary(hModule); FindClose(hFind); return; } ScreenSaverItem->szDisplayName[_tcslen(fd.cFileName)-4] = '\0'; } FreeLibrary(hModule); } else { hr = StringCbCopy(ScreenSaverItem->szDisplayName, sizeof(ScreenSaverItem->szDisplayName), _T("Unknown")); if (FAILED(hr)) { FindClose(hFind); return; } } hr = StringCbCopy(ScreenSaverItem->szFilename, sizeof(ScreenSaverItem->szFilename), filename); if (FAILED(hr)) { FindClose(hFind); return; } i = SendMessage(hwndScreenSavers, CB_ADDSTRING, 0, (LPARAM)ScreenSaverItem->szDisplayName); SendMessage(hwndScreenSavers, CB_SETITEMDATA, i, (LPARAM)ScreenSaverCount); ScreenSaverCount++; } if (!FindNextFile(hFind, &fd)) break; } FindClose(hFind); pData->ScreenSaverCount = ScreenSaverCount; }
/* * Delete AFS symlinks. Variables are used as follows: * tbuffer: Set to point to the null-terminated directory name of the * symlink (or ``.'' if none is provided) * tp: Set to point to the actual name of the symlink to nuke. */ static int RemoveLinkCmd(struct cmd_syndesc *as, void *arock) { afs_int32 code=0; struct ViceIoctl blob; struct cmd_item *ti; char tbuffer[1024]; char lsbuffer[1024]; char *tp; for(ti=as->parms[0].items; ti; ti=ti->next) { /* once per file */ tp = (char *) strrchr(ti->data, '\\'); if (!tp) tp = (char *) strrchr(ti->data, '/'); if (tp) { strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */ tbuffer[code] = 0; tp++; /* skip the slash */ if (!fs_InAFS(tbuffer)) { const char * nbname = fs_NetbiosName(); int len = (int)strlen(nbname); if (tbuffer[0] == '\\' && tbuffer[1] == '\\' && tbuffer[len+2] == '\\' && tbuffer[len+3] == '\0' && !strnicmp(nbname,&tbuffer[2],len)) { if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "\\\\%s\\all\\", nbname))) { fprintf( stderr, "tbuffer cannot be populated\n"); exit(1); } } else { fprintf(stderr,"'%s' is not in AFS.\n", tbuffer); code = 1; continue; } } } else { fs_ExtractDriveLetter(ti->data, tbuffer); if( FAILED(StringCbCat(tbuffer, sizeof(tbuffer), "."))) { fprintf (stderr, "tbuffer - not enough space"); exit(1); } tp = ti->data; fs_StripDriveLetter(tp, tp, strlen(tp) + 1); } blob.in = tp; blob.in_size = (int)strlen(tp)+1; blob.out = lsbuffer; blob.out_size = sizeof(lsbuffer); code = pioctl_utf8(tbuffer, VIOC_LISTSYMLINK, &blob, 0); if (code) { if (errno == EINVAL) fprintf(stderr,"symlink: '%s' is not a symlink.\n", ti->data); else { fs_Die(errno, ti->data); } continue; /* don't bother trying */ } if ( fs_IsFreelanceRoot(tbuffer) && !fs_IsAdmin() ) { fprintf(stderr,"symlink: Only AFS Client Administrators may alter the root.afs volume\n"); code = 1; continue; /* skip */ } blob.out_size = 0; blob.in = tp; blob.in_size = (long)strlen(tp)+1; code = pioctl_utf8(tbuffer, VIOC_DELSYMLINK, &blob, 0); if (code) { fs_Die(errno, ti->data); } } return code; }
static INT_PTR on_browse(HWND hwnd) { OPENFILENAME ofn; wchar_t path[MAX_PATH] = L""; wchar_t filter[128]; wchar_t title[64]; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.hInstance = hResModule; ofn.lpstrFilter = filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = path; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = title; ofn.Flags = OFN_DONTADDTORECENT | OFN_NOREADONLYRETURN; ofn.lpstrDefExt = L"keystore"; GetDlgItemText(hwnd, IDC_PATH, path, ARRAYLENGTH(path)); LoadString(hResModule, IDS_NC_BROW_TITLE, title, ARRAYLENGTH(title)); LoadString(hResModule, IDS_NC_BROW_FILTER, filter, ARRAYLENGTH(filter)); { wchar_t * c = filter; for (; *c; c++) { if (*c == L'%') *c = L'\0'; } } if (GetOpenFileName(&ofn)) { keystore_t * ks = NULL; wchar_t fpath[MAX_PATH+5]; SetDlgItemText(hwnd, IDC_PATH, path); if (PathFileExists(path)) { StringCbCopy(fpath, sizeof(fpath), L"FILE:"); StringCbCat(fpath, sizeof(fpath), path); ks = create_keystore_from_location(fpath, NULL); if (ks) { wchar_t buf[KCDB_MAXCCH_SHORT_DESC]; khm_size cb; cb = sizeof(buf); if (KHM_SUCCEEDED(ks_keystore_get_string(ks, KCDB_RES_DISPLAYNAME, buf, &cb))) { SetDlgItemText(hwnd, IDC_NAME, buf); } if (KHM_SUCCEEDED(ks_keystore_get_string(ks, KCDB_RES_DESCRIPTION, buf, &cb))) { SetDlgItemText(hwnd, IDC_DESCRIPTION, buf); } ks_keystore_release(ks); } } } return TRUE; }
static int ListLinkCmd(struct cmd_syndesc *as, void *arock) { afs_int32 code; struct ViceIoctl blob; int error; struct cmd_item *ti; char orig_name[1024]; /* Original name */ char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/ char parent_dir[1024]; /*Parent directory of true name*/ char *last_component; /*Last component of true name*/ cm_ioctlQueryOptions_t options; error = 0; for(ti=as->parms[0].items; ti; ti=ti->next) { cm_fid_t fid; afs_uint32 filetype; /* once per file */ if( FAILED(StringCbCopy(orig_name, sizeof(orig_name), ti->data))) { fprintf (stderr, "ListLinkCmd - input path too long"); error = 1; continue; } if( FAILED(StringCbCopy(true_name, sizeof(true_name), ti->data))) { fprintf (stderr, "ListLinkCmd - input path too long"); error = 1; continue; } /* * Find rightmost slash, if any. */ last_component = (char *) strrchr(true_name, '\\'); if (!last_component) last_component = (char *) strrchr(true_name, '/'); if (last_component) { /* * Found it. Designate everything before it as the parent directory, * everything after it as the final component. (explicitly relying * on behavior of strncpy in this case.) */ strncpy(parent_dir, true_name, last_component - true_name + 1); parent_dir[last_component - true_name + 1] = 0; last_component++; /*Skip the slash*/ /* * The following hack converts \\afs\foobar to \\afs\all\foobar. * However, this hack should no longer be required as the pioctl() * interface handles this conversion for us. */ if (!fs_InAFS(parent_dir)) { const char * nbname = fs_NetbiosName(); size_t len = strlen(nbname); if (parent_dir[0] == '\\' && parent_dir[1] == '\\' && parent_dir[len+2] == '\\' && parent_dir[len+3] == '\0' && !strnicmp(nbname,&parent_dir[2],len)) { if( FAILED(StringCbPrintf(parent_dir, sizeof(parent_dir), "\\\\%s\\all\\", nbname))) { fprintf(stderr, "parent_dir cannot be populated"); error = 1; continue; } } else { fprintf(stderr,"'%s' is not in AFS.\n", parent_dir); error = 1; continue; } } } else { /* * No slash appears in the given file name. Set parent_dir to the current * directory, and the last component as the given name. */ fs_ExtractDriveLetter(true_name, parent_dir); if( FAILED(StringCbCat(parent_dir, sizeof(parent_dir), "."))) { fprintf (stderr, "parent_dir - not enough space"); exit(1); } last_component = true_name; fs_StripDriveLetter(true_name, true_name, sizeof(true_name)); } if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n", pn); fprintf(stderr,"%s: of a name in the 'symlink list' command.\n", pn); error = 1; continue; } /* Check the object type */ memset(&fid, 0, sizeof(fid)); memset(&options, 0, sizeof(options)); filetype = 0; options.size = sizeof(options); options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL; options.literal = 1; blob.in_size = options.size; /* no variable length data */ blob.in = &options; blob.out_size = sizeof(cm_fid_t); blob.out = (char *) &fid; if (0 == pioctl_utf8(orig_name, VIOCGETFID, &blob, 1) && blob.out_size == sizeof(cm_fid_t)) { options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID; options.fid = fid; } else { fs_Die(errno, ti->data); error = 1; continue; } blob.out_size = sizeof(filetype); blob.out = &filetype; code = pioctl_utf8(orig_name, VIOC_GETFILETYPE, &blob, 1); if (code || blob.out_size != sizeof(filetype)) { fs_Die(errno, ti->data); error = 1; continue; } if (filetype != 3 /* symlink */) { fprintf(stderr,"'%s' is a %s not a Symlink.\n", orig_name, fs_filetypestr(filetype)); error = 1; continue; } blob.in = last_component; blob.in_size = (long)strlen(last_component)+1; /* Now determine the symlink target */ blob.out_size = AFS_PIOCTL_MAXSIZE; blob.out = space; memset(space, 0, AFS_PIOCTL_MAXSIZE); code = pioctl_utf8(parent_dir, VIOC_LISTSYMLINK, &blob, 1); if (code == 0) printf("'%s' is a symlink to '%.*s'\n", orig_name, blob.out_size, space); else { error = 1; if (errno == EINVAL) fprintf(stderr,"'%s' is not a symlink.\n", ti->data); else { fs_Die(errno, (ti->data ? ti->data : parent_dir)); } } } return error; }
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F Function: DllRegisterServer Summary: The standard exported function that can be called to command this DLL server to register itself in the system registry. Args: void. Returns: HRESULT NOERROR F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/ STDAPI DllRegisterServer(void) { HRESULT hr = NOERROR; TCHAR szID[GUID_SIZE+1]; TCHAR szCLSID[GUID_SIZE+1]; TCHAR szModulePath[MAX_PATH]; // Obtain the path to this module's executable file for later use. GetModuleFileName( g_pServer->m_hDllInst, szModulePath, sizeof(szModulePath)/sizeof(TCHAR)); /*------------------------------------------------------------------------- Create registry entries for the DllBall Component. -------------------------------------------------------------------------*/ // Create some base key strings. StringFromGUID2(CLSID_Ball, szID, GUID_SIZE); hr = StringCbCopy(szCLSID, sizeof(szCLSID), TEXT("CLSID\\")); assert(hr == S_OK); hr = StringCbCat(szCLSID, sizeof(szCLSID), szID); assert(hr == S_OK); // Create ProgID keys. SetRegKeyValue( TEXT("DllBall1.0"), NULL, TEXT("DllBall Component - FRESERVE Code Sample")); SetRegKeyValue( TEXT("DllBall1.0"), TEXT("CLSID"), szID); // Create VersionIndependentProgID keys. SetRegKeyValue( TEXT("DllBall"), NULL, TEXT("DllBall Component - FRESERVE Code Sample")); SetRegKeyValue( TEXT("DllBall"), TEXT("CurVer"), TEXT("DllBall1.0")); SetRegKeyValue( TEXT("DllBall"), TEXT("CLSID"), szID); // Create entries under CLSID. SetRegKeyValue( szCLSID, NULL, TEXT("DllBall Component - FRESERVE Code Sample")); SetRegKeyValue( szCLSID, TEXT("ProgID"), TEXT("DllBall1.0")); SetRegKeyValue( szCLSID, TEXT("VersionIndependentProgID"), TEXT("DllBall")); SetRegKeyValue( szCLSID, TEXT("NotInsertable"), NULL); SetRegKeyValue( szCLSID, TEXT("InprocServer32"), szModulePath); AddRegNamedValue( szCLSID, TEXT("InprocServer32"), TEXT("ThreadingModel"), TEXT("Free")); return hr; }
int spawn_kids(int argc, _TCHAR *argv[]) { PROCESS_INFORMATION procinfo; STARTUPINFO startinfo; TCHAR cmd_line[MAX_PATH]; size_t len; StringCbCopy(cmd_line, sizeof(cmd_line), _T("\"")); StringCbCat(cmd_line, sizeof(cmd_line), argv[0]); StringCbCat(cmd_line, sizeof(cmd_line), _T("\"")); StringCbCat(cmd_line, sizeof(cmd_line), _T(" -child")); if(!tst_read_write) StringCbCat(cmd_line, sizeof(cmd_line), _T(" -nr")); StringCbLength(test_dir, sizeof(test_dir), &len); if(len > 0) { StringCbCat(cmd_line, sizeof(cmd_line), _T(" -d ")); StringCbCat(cmd_line, sizeof(cmd_line), test_dir); //_tcscat(cmd_line, _T("\"")); } if (tst_wlock_single) StringCbCat(cmd_line, sizeof(cmd_line), _T(" -wS ")); if (tst_wlock_child) StringCbCat(cmd_line, sizeof(cmd_line), _T(" -wC ")); startinfo.cb = sizeof(startinfo); startinfo.lpReserved = NULL; startinfo.lpDesktop = NULL; startinfo.lpTitle = NULL; startinfo.dwFlags = 0; startinfo.cbReserved2 = 0; cerr << "PARENT: Process ID:" << GetCurrentProcessId() << "\n"; cerr << "PARENT: Spawning child process: " << cmd_line << "\n"; if(!CreateProcess( NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &startinfo, &procinfo)) return 1; h_child = procinfo.hProcess; if(procinfo.hThread) CloseHandle(procinfo.hThread); cerr << "PARENT: Waiting for child process...\n"; cerr.flush(); WaitForSingleObject(event_parent, INFINITE); cerr << "PARENT: Done.\n"; cerr << "PARENT: Created child process ID: " << procinfo.dwProcessId << "\n"; cerr.flush(); return 0; }
STDAPI DllRegisterServer(void) { char szID[128]; WCHAR wcID[128]; char szCLSID[128]; TCHAR szModule[MAX_PATH + 1]; char * pName = "WMI Method Provider Test"; char * pModel; size_t * intReturnValue = NULL; HKEY hKey1, hKey2; // Normally we want to use "Both" as the threading model since // the DLL is free threaded, but NT 3.51 Ole doesnt work unless // the model is "Aparment" if(Is4OrMore()) pModel = "Both"; else pModel = "Apartment"; // Create the path. memset(wcID, NULL, sizeof(wcID)); memset(szID, NULL, sizeof(szID)); StringFromGUID2(CLSID_methodprovider, wcID, sizeof(wcID)/sizeof(WCHAR) - 1); wcstombs_s(intReturnValue, szID, sizeof(szID), wcID, sizeof(szID)); StringCbCopy(szCLSID, sizeof(szCLSID), "Software\\classes\\CLSID\\"); StringCbCat(szCLSID, sizeof(szCLSID), (LPCTSTR)szID); // Create entries under CLSID LONG lRet = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szCLSID, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey1, NULL ); if (lRet != ERROR_SUCCESS) { return E_FAIL; } lRet = RegSetValueEx(hKey1, NULL, 0, REG_SZ, (BYTE *)pName, strlen(pName)+1); if (lRet != ERROR_SUCCESS) { RegCloseKey(hKey1); return E_FAIL; } lRet = RegCreateKeyEx( hKey1, "InprocServer32", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey2, NULL ); if (lRet != ERROR_SUCCESS) { RegCloseKey(hKey1); return E_FAIL; } memset(&szModule, NULL, sizeof(szModule)); GetModuleFileName(ghModule, szModule, sizeof(szModule)/sizeof(TCHAR) - 1); lRet = RegSetValueEx(hKey2, NULL, 0, REG_SZ, (BYTE *)szModule, strlen(szModule)+1); if (lRet != ERROR_SUCCESS) { RegCloseKey(hKey2); RegCloseKey(hKey1); return E_FAIL; } lRet = RegSetValueEx(hKey2, "ThreadingModel", 0, REG_SZ, (BYTE *)pModel, strlen(pModel)+1); if (lRet != ERROR_SUCCESS) { RegCloseKey(hKey2); RegCloseKey(hKey1); return E_FAIL; } RegCloseKey(hKey1); RegCloseKey(hKey2); return NOERROR; }
/* Makes sure that each top level configuration node has a corresponding menu item in the 'Options' menu.*/ static void refresh_config_menu_items(void) { khui_menu_def * omenu; khm_boolean refresh_menu = FALSE; khui_config_node cfg_r = NULL; omenu = khui_find_menu(KHUI_MENU_OPTIONS); if (omenu == NULL) { #ifdef DEBUG assert(FALSE); #endif return; } khui_action_lock(); for (khui_cfg_get_first_child(NULL, &cfg_r); cfg_r != NULL; khui_cfg_get_next_release(&cfg_r)) { khm_int32 flags; khui_action * paction; wchar_t cname[KHUI_MAXCCH_NAME]; khm_size cb; flags = khui_cfg_get_flags(cfg_r); if (flags & KHUI_CNFLAG_SYSTEM) continue; cb = sizeof(cname); if (KHM_FAILED(khui_cfg_get_name(cfg_r, cname, &cb))) { #ifdef DEBUG assert(FALSE); #endif continue; } paction = khui_find_named_action(cname); if (!paction) { khm_handle sub; khui_config_node_reg reg; wchar_t wshort[KHUI_MAXCCH_SHORT_DESC]; khm_int32 action; khui_cfg_get_reg(cfg_r, ®); kmq_create_hwnd_subscription(khm_hwnd_main, &sub); StringCbCopy(wshort, sizeof(wshort), reg.short_desc); StringCbCat(wshort, sizeof(wshort), L" ..."); action = khui_action_create(cname, wshort, reg.long_desc, (void *) CFGACTION_MAGIC, KHUI_ACTIONTYPE_TRIGGER, sub); if (action == 0) { #ifdef DEBUG assert(FALSE); #endif continue; } khui_menu_insert_action(omenu, (khm_size) -1, action, 0); refresh_menu = TRUE; } } khui_action_unlock(); if (refresh_menu) { khui_refresh_actions(); } }