コード例 #1
0
ファイル: cfgscr.cpp プロジェクト: ancientlore/hermit
void ConfigScroller::unregisterServer ()
{
    int exitCode = KB_ESC;
    char dllpath[512];
    *dllpath = 0;
    {
	InputDialog dlg (myScreen, "Unregister DLL Server", "Enter the DLL pathname:",
			 dllpath, 511, &mDllHist);
	dlg.run ();
	exitCode = dlg.getExitCode ();
    }
    if (exitCode != KB_ESC) {

	HINSTANCE hInst = LoadLibrary (dllpath);
	if (hInst == NULL) {
	    myScreen.sendWinErrStatusMsg ("Cannot load DLL");
	    return;
	}

	FARPROC dllEntryPoint;
	dllEntryPoint = GetProcAddress (hInst, "DllUnregisterServer");
	if (dllEntryPoint == NULL) {
	    myScreen.sendWinErrStatusMsg ("Cannot load DllUnregisterServer");
	    FreeLibrary (hInst);
	    return;
	}

	if (FAILED ((*dllEntryPoint) ()))
	    myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "The unregistration function failed."));
	else
	    myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "Server unregistered!"));

	FreeLibrary (hInst);
    }
}
コード例 #2
0
ファイル: cfgscr.cpp プロジェクト: ancientlore/hermit
void ConfigScroller::importReg ()
{
    int exitCode = KB_ESC;
    char path[512];
    *path = 0;
    {
	InputDialog dlg (myScreen, "Import Custom Commands", "Enter the pathname:",
			 path, 511, &mRegHist);
	dlg.run ();
	exitCode = dlg.getExitCode ();
    }
    if (exitCode != KB_ESC) {
	myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) importCommands (path)));
    }
}
コード例 #3
0
ファイル: cfgscr.cpp プロジェクト: ancientlore/hermit
void ConfigScroller::exportReg ()
{
    int exitCode = KB_ESC;
    char path[512];
    *path = 0;
    {
	InputDialog dlg (myScreen, "Export Custom Commands", "Enter the pathname:",
			 path, 511, &mRegHist);
	dlg.run ();
	exitCode = dlg.getExitCode ();
    }
    if (exitCode != KB_ESC) {

	if (_access (path, 0) == 0)
	    if (myScreen.ask ("Confirm File Replace", "Overwrite the existing file?") == 0)
		return;

	FILE *file = fopen (path, "w");
	if (file == NULL) {
	    myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "Could not create file."));
	    return;
	}

	for (int i = 0; i < 2; i++) {
	    int st, fn;
	    if (i == 0) {
		st = 'A';
		fn = 'Z';
	    }
	    else if (i == 1) {
		st = '0';
		fn = '9';
	    }

	    for (char c = st; c <= fn; c++) {
		try {
		    // Open registry key
		    RegistryKey k (HKEY_CURRENT_USER, HKCU_SUBKEY_HERMIT "\\Commands", KEY_READ);

		    char valname[2];
		    valname[0] = c;
		    valname[1] = '\0';
		    // try to read the current value
		    char *value = 0;
		    DWORD type;
		    try {
			value = k.queryValue (valname, type);
			if (type == REG_SZ  &&  value != 0  &&  value[0] != '\0') {
			    fprintf (file, "%c,%s\n", c, value);
			}
			delete [] value;
		    }
		    catch (const std::exception&) {
		    }
		}
		catch (const std::exception&) {
		}
	    }
	}
	fclose (file);
	myScreen.sendEvent (Event(EV_STATUS_MSG, (DWORD) "Commands exported."));
    }
}