コード例 #1
0
ファイル: WinRun4J.cpp プロジェクト: karlvr/winrun4j
int main(int argc, char* argv[])
{
	HINSTANCE hInstance = (HINSTANCE) GetModuleHandle(NULL);
	LPSTR lpCmdLine = StripArg0(GetCommandLine());
#else
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int /*nCmdShow*/) 
{
	lpCmdLine = StripArg0(GetCommandLine());
#endif

	// Initialise the logger using std streams
	Log::Init(hInstance, NULL, NULL, NULL);

#if WINRUN4J_ALLOW_BUILTIN_COMMANDS
	// Check for Builtin commands
	if(IsBuiltInCommand(lpCmdLine)) {
		int res = WinRun4J::DoBuiltInCommand(hInstance, lpCmdLine);
		Log::Close();
		return res;
	}
#endif

	// Load the INI file based on module name
	dictionary* ini = WinRun4J::LoadIniFile(hInstance);
	if(ini == NULL) {
		return 1;
	}
	
	return WinRun4J::ExecuteINI(hInstance, ini, lpCmdLine);
}
コード例 #2
0
ファイル: DDE.cpp プロジェクト: revolsys/winlaunchj
bool DDE::NotifySingleInstance(dictionary* ini)
{
	g_ini = ini;

	// Startup DDE library
	UINT result = DdeInitialize(&g_pidInst, (PFNCALLBACK) &DdeCallback, 0, 0);
	if(result != DMLERR_NO_ERROR) {
		Log::Error("Unable to initialize DDE: %d", result);
		return false;
	}

	// Check for app/topic override
	char* appName = iniparser_getstr(g_ini, DDE_SERVER_NAME);
	char* topic = iniparser_getstr(g_ini, DDE_TOPIC);

	g_serverName = DdeCreateStringHandle(g_pidInst, appName == NULL ? "WinRun4J" : appName, CP_WINANSI);
	g_topic = DdeCreateStringHandle(g_pidInst, topic == NULL ? "system" : topic, CP_WINANSI);

	HCONV conv = DdeConnect(g_pidInst, g_serverName, g_topic, NULL);
	if (conv != NULL) {
		LPSTR cmdline = StripArg0(GetCommandLine());
		char* activate = (char*) malloc(strlen(DDE_EXECUTE_ACTIVATE) + strlen(cmdline) + 2);
		strcpy(activate, DDE_EXECUTE_ACTIVATE);
		strcat(activate, " ");
		strcat(activate, cmdline);
		HDDEDATA result = DdeClientTransaction((LPBYTE)activate, strlen(activate) + 1, conv, NULL, 0, XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
		if (result == 0) {
			Log::Error("Failed to send DDE single instance notification");
			return false;
		}
	} else{
		Log::Error("Unable to create DDE conversation");
	}

	DDE::Uninitialize();
	return true;
}