static int dde_initialise() { if ( ddeInst == (DWORD)NULL ) { if (DdeInitialize(&ddeInst, (PFNCALLBACK)DdeCallback, APPCLASS_STANDARD|CBF_FAIL_ADVISES|CBF_FAIL_POKES| CBF_SKIP_REGISTRATIONS|CBF_SKIP_UNREGISTRATIONS, 0L) != DMLERR_NO_ERROR) { ddeInst = (DWORD) -1; return dde_warning("initialise"); } MODULE_dde = lookupModule(PL_new_atom("win_dde")); FUNCTOR_dde_connect3 = lookupFunctorDef(PL_new_atom("$dde_connect"), 3); FUNCTOR_dde_connect_confirm3 = lookupFunctorDef(PL_new_atom("$dde_connect_confirm"), 3); FUNCTOR_dde_disconnect1 = lookupFunctorDef(PL_new_atom("$dde_disconnect"), 1); FUNCTOR_dde_request4 = lookupFunctorDef(PL_new_atom("$dde_request"), 4); FUNCTOR_dde_execute3 = lookupFunctorDef(PL_new_atom("$dde_execute"), 3); FUNCTOR_error1 = lookupFunctorDef(ATOM_error, 1); } succeed; }
JNIEXPORT jint JNICALL Java_de_walware_ecommons_io_win_DDEClient_ddeExecute( JNIEnv* env, jclass obj, jstring server, jstring topic, jstring command) { // Pull unicode strings from the java arguments const jchar *szServer = env->GetStringChars(server, 0); const jchar *szTopic = env->GetStringChars(topic, 0); const jchar *szCommand = env->GetStringChars(command, 0); // Init the DDEM Library DWORD idInst = 0; UINT iReturn = DdeInitialize(&idInst, (PFNCALLBACK) DdeCallback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 ); if (iReturn != DMLERR_NO_ERROR) { return 1; } // Connect to the DDE server HSZ hszServer = DdeCreateStringHandle(idInst, (WCHAR*) szServer, 0); HSZ hszTopic = DdeCreateStringHandle(idInst, (WCHAR*) szTopic, 0); HCONV hConv = DdeConnect(idInst, hszServer, hszTopic, NULL); // Free up some resources DdeFreeStringHandle(idInst, hszServer); env->ReleaseStringChars(server, szServer); DdeFreeStringHandle(idInst, hszTopic); env->ReleaseStringChars(topic, szTopic); // Make sure we're connected if (hConv == NULL) { DdeUninitialize(idInst); env->ReleaseStringChars(command, szCommand); return 2; } // Prepare data for transaction HDDEDATA hData = DdeCreateDataHandle(idInst, (LPBYTE) szCommand, (lstrlen((WCHAR*) szCommand) + 1) * sizeof(WCHAR), 0L, 0L, CF_UNICODETEXT, 0); env->ReleaseStringChars(command, szCommand); // Data is OK? if (hData == NULL) { DdeDisconnect(hConv); DdeUninitialize(idInst); return 3; } else { DdeClientTransaction((LPBYTE) hData, 0xFFFFFFFF, hConv, 0L, 0, XTYP_EXECUTE, TIMEOUT_ASYNC, NULL); } // Clean up DdeDisconnect(hConv); DdeUninitialize(idInst); return 0; }
WORD PASCAL _Cover_DdeInitialize( LPDWORD pidInst, PFNCALLBACK p, DWORD afCmd, DWORD ulRes) { return( DdeInitialize( pidInst, (PFNCALLBACK) SetProc( (FARPROC)p, GETPROC_DDEMLCALLBACK ), afCmd, ulRes ) ); }
BOOL StartUpDDE ( HWND hWnd ) { extern FARPROC lpDDEProc; extern HSZ hSZService; extern HSZ hSZItem; extern DWORD idInst; extern HCONV hConv; HMENU hMenu = GetMenu ( hWnd ); BOOL RtnValue = TRUE; UINT Flags = ( MF_BYCOMMAND | MF_ENABLED ); /*--------------------------------+ | Setup Client Editor Application | +--------------------------------*/ lpDDEProc = (FARPROC) DDECallBack; if ( DdeInitialize ((LPDWORD) &idInst, (PFNCALLBACK)lpDDEProc, APPCMD_CLIENTONLY,0L) ) { Flags = ( MF_BYCOMMAND | MF_GRAYED); RtnValue = FALSE; MessageBeep ( 0 ); MessageBox (NULL,"Can not Initialize DDEML", "DDEML ERROR", MB_ICONSTOP | MB_TASKMODAL ); } else { /*----------------------------+ | Check if CLIPS is available | +----------------------------*/ HSZ hSZTopic = DdeCreateStringHandle ( idInst, "LOAD", CP_WINANSI ); hSZItem = DdeCreateStringHandle ( idInst, "DDEData", CP_WINANSI ); hSZService = DdeCreateStringHandle ( idInst, "CLIPS", CP_WINANSI ); hConv = DdeConnect ( idInst, hSZService, hSZTopic, (PCONVCONTEXT)NULL); if ( hConv == NULL ) { Flags = ( MF_BYCOMMAND | MF_GRAYED); RtnValue = FALSE; } else { DdeDisconnect ( hConv ); } DdeFreeStringHandle ( idInst, hSZTopic ); } EnableMenuItem( hMenu, IDM_EDIT_COMPLETE, Flags); EnableMenuItem( hMenu, IDM_HELP_COMPLETE, Flags); EnableMenuItem( hMenu, IDM_BUFFER_LOAD, Flags); EnableMenuItem( hMenu, IDM_BUFFER_LBUF, Flags); EnableMenuItem( hMenu, IDM_BUFFER_BATCH, Flags); return ( RtnValue ); }
//------DDE経由で取得------------------------------------ bool GetUrlByDDE( CString browser, CString &URL ) { bool ret = false; DWORD idInst = 0; UINT result = DdeInitialize( &idInst, DdeCallback, APPCMD_CLIENTONLY, 0L ); URL = _T(""); if ( result == DMLERR_NO_ERROR ) { LPSTR lpszApplication = browser.GetBuffer(0); LPSTR lpszTopic = "WWW_GetWindowInfo"; HSZ hszApplication = DdeCreateStringHandle( idInst, lpszApplication, CP_WINANSI ); HSZ hszTopic = DdeCreateStringHandle( idInst, lpszTopic, CP_WINANSI ); HSZ hszItem = DdeCreateStringHandle( idInst, "-1", CP_WINANSI ); if ( hszApplication && hszTopic && hszItem ) { HCONV hConv = DdeConnect(idInst, hszApplication, hszTopic, NULL); if ( hConv ) { HDDEDATA hData = DdeClientTransaction( NULL, 0, hConv, hszItem, CF_TEXT, XTYP_REQUEST, 1000, NULL ); if ( hData ) { char *pStart = (char *)DdeAccessData( hData, NULL ); if ( pStart ) { while ( *pStart++ != '"' ) ; if ( *pStart ) { char *pEnd = pStart; while ( *pEnd != '"' ) pEnd++; *pEnd = NUL; URL = pStart; ret = true; } } } DdeDisconnect( hConv ); } } if ( hszItem ) DdeFreeStringHandle( idInst, hszItem ); if ( hszTopic ) DdeFreeStringHandle( idInst, hszTopic ); if ( hszApplication ) DdeFreeStringHandle( idInst, hszApplication ); DdeUninitialize( idInst ); } return ( ret ); }
static DWORD open_dde_conversation (LPCTSTR topic_name, const char *exename, const char *ddename, HCONV *convp) { DWORD session = 0; HCONV conversation = NULL; HSZ service, topic; UINT ret; int i, err = 0; ret = DdeInitialize(&session, (PFNCALLBACK) init_callback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0); if (ret != DMLERR_NO_ERROR) { fprintf(stderr, "DDE: couldn't initialize session\n"); return 0; } service = DdeCreateStringHandle(session, ddename, CP_WINANSI); topic = DdeCreateStringHandle(session, topic_name, CP_WINANSI); if (!service || !topic) { fprintf(stderr, "DDE: string creation failed\n"); DdeUninitialize(session); return 0; } conversation = DdeConnect(session, service, topic, 0); if (conversation == NULL) { err = start_dde_server(exename); if (!err) { /* try to connect */ for (i=0; i<5 && !conversation; i++) { Sleep(CONNECT_DELAY); conversation = DdeConnect(session, service, topic, 0); } } if (conversation == NULL && !err) { fprintf(stderr, "DDE: couldn't contact server %s\n", ddename); err = 1; } } DdeFreeStringHandle(session, service); DdeFreeStringHandle(session, topic); if (err) { DdeUninitialize(session); session = 0; } else { *convp = conversation; } return session; }
/* This should be during startup in WinMain */ BOOL dde_initialise() { lpDdeProc = MakeProcInstance((FARPROC)GSviewDdeCallback, phInstance); if (DdeInitialize(&idInst, (PFNCALLBACK)lpDdeProc, CBF_FAIL_POKES, 0L)) { return FALSE; } hszService = DdeCreateStringHandleA(idInst, (LPSTR)szServiceName, 0); hszTopic = DdeCreateStringHandleA(idInst, (LPSTR)szTopicName, 0); return TRUE; }
void DDEInitialize() { if (DDEIdInst)//DDEInitialized) return; //DDEInitialized = TRUE; // Should insert filter flags DdeInitialize(&DDEIdInst, (PFNCALLBACK)MakeProcInstance( (FARPROC)_DDECallback, AfxGetInstanceHandle()), APPCLASS_STANDARD, 0L); }
JNIEXPORT jint JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_Initialize (JNIEnv *env, jclass cls, jobject $idInst, jint afCmd) { DWORD idInst = 0; UINT initError = DdeInitialize( &idInst, // receives instance identifier (PFNCALLBACK) DdeCallback, // pointer to callback function afCmd, 0); SetObjectInPointer(env, $idInst, NewInteger(env, idInst)); return initError; }
void gcDDEManager::init() { if ( !m_bDDEInit ) { UINT rc = DdeInitialize(&m_hDDEIdInst, (PFNCALLBACK)_DDECallback, APPCLASS_STANDARD, 0L); if ( rc != DMLERR_NO_ERROR ) { printf("Failed to initialize DDE [%d]\n", rc); } else { m_bDDEInit = true; } } }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; /* Try to cooperate with other running instances of the application */ if (!hPrevInstance) if (!InitApplication(hInstance)) return(FALSE); /* initialize the specific instance */ if (!InitInstance(hInstance, nCmdShow)) return(FALSE); /* initialize DDEML */ /**** ought to check thisis available */ DdeInitialize(&ddeInst, NULL, APPCLASS_STANDARD | APPCMD_CLIENTONLY | CBF_SKIP_ALLNOTIFICATIONS, 0L); /* open an initial file if there is a command line argument */ #if defined(WIN32) && defined(__BORLANDC__) && (__BORLANDC__ <= 0x452) { int i; if (sscanf(lpCmdLine, "%128s%n", buf, &i) == 1) lpCmdLine += i; } #endif if (sscanf(lpCmdLine, "%128s", buf) == EOF) buf[0] = '\0'; OpenInitialFile(buf); /* process messages until a WM_QUIT message */ while (GetMessage(&msg, NULL, 0, 0)) { if (! TranslateAccelerator(hWnd, hAccTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } /* drop DDEML */ DdeUninitialize(ddeInst); return(msg.wParam); }
void FAR InitDDE (HWND powinstance) { ddeProc=MakeProcInstance((FARPROC)PowDdeServerProc,hInst); ddeInstId=0; // use window handle as topic to make it possible // to call specific instances of pow! wsprintf((LPSTR)topic,"%04X",powinstance); if (DdeInitialize((LPDWORD)&ddeInstId,(PFNCALLBACK)ddeProc,APPCLASS_STANDARD,0)==DMLERR_NO_ERROR) { ddeInstalled=TRUE; hService=DdeCreateStringHandle(ddeInstId,"pow",CP_WINANSI); hTopic=DdeCreateStringHandle(ddeInstId,(LPSTR)topic,CP_WINANSI); DdeNameService(ddeInstId,hService,0,DNS_REGISTER); } }
BOOL CDDEServer::Create() { USES_CONVERSION; DWORD dwFilterFlags = 0; UINT uiResult; uiResult = DdeInitialize( &m_hInstance, DDECallback, dwFilterFlags, 0 ); if ( uiResult != DMLERR_NO_ERROR ) return FALSE; m_hszService = DdeCreateStringHandle( m_hInstance, (LPCTSTR)m_sService, CP_WINUNICODE ); DdeNameService( m_hInstance, m_hszService, NULL, DNS_REGISTER ); return TRUE; }
//Initialize DDE int initDDE(int timeout) { //Improve this, check if Inst is 0 else uninitialize first if (DdeInitialize(&Inst, (PFNCALLBACK)DdeCallback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0) == DMLERR_NO_ERROR) { #ifdef _ddedebug printf("Initialized DDE\n"); #endif Timeout = timeout; return 0; } else { printf("Failed to initiliaze DDE\n"); return 1; } }
BOOL StartUpDDE(void) { if (DdeInitialize(&idInst, (PFNCALLBACK) DDECallBack, APPCLASS_STANDARD, 0) != DMLERR_NO_ERROR) { return(FALSE); } hszService = DdeCreateStringHandle(idInst,"CLIPS",CP_WINANSI ); hszCommand = DdeCreateStringHandle(idInst,"COMMAND",CP_WINANSI ); hszResult = DdeCreateStringHandle(idInst,"RESULT",CP_WINANSI ); if (! DdeNameService(idInst,hszService,0L,DNS_REGISTER)) { return(FALSE); } return(TRUE); }
WEXPORT WClient::WClient( WObject *owner, cbc notify ) : _service( 0 ) , _topic( 0 ) , _owner( owner ) , _notify( notify ) , _procid( 0 ) , _hconv( 0 ) , _ok( false ) , _timeout( 5000 ) , _connected( false ) { /*************************/ _procInst = MakeProcInstance( (FARPROC)clientCallback, GUIMainHInst ); if( !DdeInitialize( &_procid, (PFNCALLBACK)_procInst, INITFLAGS, 0L ) ) { _ok = true; } }
void DDEExecute(const WCHAR* server, const WCHAR* topic, const WCHAR* command) { unsigned long inst = 0; HSZ hszServer = NULL, hszTopic = NULL; HCONV hconv = NULL; HDDEDATA hddedata = NULL; #ifdef _WIN64 CrashIf(str::Len(command) >= (DWORD)-1); if (str::Len(command) >= (DWORD)-1) return; #endif UINT result = DdeInitialize(&inst, &DdeCallback, APPCMD_CLIENTONLY, 0); if (result != DMLERR_NO_ERROR) goto Exit; hszServer = DdeCreateStringHandle(inst, server, CP_WINNEUTRAL); if (!hszServer) goto Exit; hszTopic = DdeCreateStringHandle(inst, topic, CP_WINNEUTRAL); if (!hszTopic) goto Exit; hconv = DdeConnect(inst, hszServer, hszTopic, 0); if (!hconv) goto Exit; DWORD cbLen = ((DWORD)str::Len(command) + 1) * sizeof(WCHAR); hddedata = DdeCreateDataHandle(inst, (BYTE*)command, cbLen, 0, 0, CF_UNICODETEXT, 0); if (!hddedata) goto Exit; HDDEDATA answer = DdeClientTransaction((BYTE*)hddedata, (DWORD)-1, hconv, 0, 0, XTYP_EXECUTE, 10000, 0); if (answer) DdeFreeDataHandle(answer); Exit: if (hddedata) DdeFreeDataHandle(hddedata); if (hconv) DdeDisconnect(hconv); if (hszTopic) DdeFreeStringHandle(inst, hszTopic); if (hszServer) DdeFreeStringHandle(inst, hszServer); DdeUninitialize(inst); }
bool DDEExecute(const WCHAR* server, const WCHAR* topic, const WCHAR* command) { DWORD inst = 0; HSZ hszServer = NULL, hszTopic = NULL; HCONV hconv = NULL; bool ok = false; CrashIf(str::Len(command) >= INT_MAX - 1); if (str::Len(command) >= INT_MAX - 1) return false; UINT result = DdeInitialize(&inst, DdeCallback, APPCMD_CLIENTONLY, 0); if (result != DMLERR_NO_ERROR) return false; hszServer = DdeCreateStringHandle(inst, server, CP_WINNEUTRAL); if (!hszServer) goto Exit; hszTopic = DdeCreateStringHandle(inst, topic, CP_WINNEUTRAL); if (!hszTopic) goto Exit; hconv = DdeConnect(inst, hszServer, hszTopic, NULL); if (!hconv) goto Exit; DWORD cbLen = ((DWORD)str::Len(command) + 1) * sizeof(WCHAR); HDDEDATA answer = DdeClientTransaction((BYTE *)command, cbLen, hconv, 0, CF_UNICODETEXT, XTYP_EXECUTE, 10000, NULL); if (answer) { DdeFreeDataHandle(answer); ok = true; } Exit: if (hconv) DdeDisconnect(hconv); if (hszTopic) DdeFreeStringHandle(inst, hszTopic); if (hszServer) DdeFreeStringHandle(inst, hszServer); DdeUninitialize(inst); return ok; }
/* * DDEInit - set up to do dde */ bool DDEInit( void ) { FARPROC fp; if( UseDDE ) { return( true ); } fp = MakeFnCallbackProcInstance( DDECallback, InstanceHandle ); if( DdeInitialize( &DDEInstId, (PFNCALLBACK)fp, CBF_FAIL_EXECUTES | CBF_FAIL_ADVISES | CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS, 0L ) ) { return( false ); } UseDDE = true; return( true ); } /* DDEInit */
/* * DDEInit - set up to do dde */ bool DDEInit( void ) { PFNCALLBACK fp; if( UseDDE ) { return( TRUE ); } fp = (PFNCALLBACK)MakeProcInstance( (FARPROC)DDECallback, InstanceHandle ); if( DdeInitialize( &DDEInstId, fp, CBF_FAIL_EXECUTES | CBF_FAIL_ADVISES | CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS, 0L ) ) { return( FALSE ); } UseDDE = TRUE; return( TRUE ); } /* DDEInit */
bool DDEService::_DoStart() { bool bReturn = false; if (!m_dwDDEInst) { CoInitialize(NULL); UINT uInitReturn = DdeInitialize(&m_dwDDEInst, (PFNCALLBACK)DdeCallback, APPCLASS_STANDARD | CBF_FAIL_POKES | CBF_FAIL_SELFCONNECTIONS | CBF_SKIP_ALLNOTIFICATIONS, 0L); if (uInitReturn == DMLERR_NO_ERROR) { bReturn = SUCCEEDED(_RegisterDDE()); } } return bReturn; }
bool DDE::RegisterDDE() { // 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); // Register the server DdeNameService(g_pidInst, g_serverName, NULL, DNS_REGISTER); return true; }
WEXPORT WServer::WServer( const char *service, const char *topic, WObject* owner, sbc notify ) : _procid( 0 ) , _service( 0 ) , _topic( 0 ) , _ok( false ) { /**********************/ if( _server == NULL ) { _server = this; _owner = owner; _notify = notify; _procInst = MakeProcInstance( (FARPROC)serverCallback, GUIMainHInst ); if( !DdeInitialize( &_procid, (PFNCALLBACK)_procInst, INITFLAGS, 0L ) ) { _service = DdeCreateStringHandle( _procid, (char *)service, CP_WINANSI ); _topic = DdeCreateStringHandle( _procid, (char *)topic, CP_WINANSI ); if( DdeNameService( _procid, _service, 0, DNS_REGISTER ) ) { _ok = true; } } } }
HXBOOL DDEStartup() { HX_TRACE("DDEStartup()\r\n"); HX_ASSERT(g_dwNumInstances == 0 || g_dwIdInst); if (g_dwIdInst > 0) { goto exit; } if (DMLERR_NO_ERROR != DdeInitialize(&g_dwIdInst, DdeCallback, CBF_SKIP_ALLNOTIFICATIONS, 0)) { return FALSE; } exit: g_dwNumInstances++; return TRUE; }
bool DDEClientTransactionManager::Initialize() { ATLTRACE( _T("Initializing DDE\n") ); UINT uRes = DdeInitialize(&m_idInst, // receives instance identifier (PFNCALLBACK)DDEClientTransactionManagerDispatcher::DdeClientCallback, // pointer to callback function APPCMD_CLIENTONLY |MF_SENDMSGS | MF_POSTMSGS | APPCMD_FILTERINITS, 0); #ifdef _DEBUG if (DMLERR_NO_ERROR != uRes) { ATLTRACE( _T("Cannot initialize DDE: 0x%X\n"), uRes ); } else { ATLTRACE( _T("DDE was initialized: idInst=0x%X\n"), m_idInst ); } #endif // _DEBUG return DMLERR_NO_ERROR == uRes; }
BOOL CFileExecutor::DisplayURL(LPCTSTR pszURL) { ShellExecute( AfxGetMainWnd()->GetSafeHwnd(), _T("open"), pszURL, NULL, NULL, SW_SHOWNORMAL ); return TRUE; #if 0 DWORD dwFilterFlags = 0; BOOL bSuccess = FALSE; DWORD hInstance = 0; UINT uiResult = DdeInitialize( &hInstance, DDECallback, dwFilterFlags, 0 ); if ( uiResult != DMLERR_NO_ERROR ) return FALSE; HSZ hszService = DdeCreateStringHandle( hInstance, L"IExplore", CP_WINUNICODE ); HSZ hszTopic = DdeCreateStringHandle( hInstance, L"WWW_OpenURL", CP_WINUNICODE ); if ( HCONV hConv = DdeConnect( hInstance, hszService, hszTopic, NULL ) ) { CString strCommand; USES_CONVERSION; strCommand.Format( _T("\"%s\",,0"), pszURL ); LPCSTR pszCommand = T2CA( (LPCTSTR)strCommand ); DdeClientTransaction( (LPBYTE)pszCommand, pszCommand, hConv, 0, 0, XTYP_EXECUTE, 4000, NULL ); DdeDisconnect( hConv ); } DdeFreeStringHandle( hInstance, hszTopic ); DdeFreeStringHandle( hInstance, hszService ); DdeUninitialize( hInstance ); return bSuccess; #endif }
void DDEIntegratorClient::DDEIntegratorClientInit (char* pszService) { m_hszClientTopic= NULL; m_hConv = NULL; if ( gnClientCount == 0 ) { glpIDEClientCallBack = MakeProcInstance( (FARPROC)DDEIntegratorClientCallBack, GetModuleHandle(NULL) ); if ( DdeInitialize( (LPDWORD)&gDDEClientId, (PFNCALLBACK)glpIDEClientCallBack, APPCMD_CLIENTONLY | APPCMD_FILTERINITS | CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS, 0L) ) return; ghszIntegratorService = DdeCreateStringHandle( gDDEClientId, (LPSTR)pszService, CP_WINANSI ); ghszDebugMessageItem = DdeCreateStringHandle( gDDEClientId, (LPSTR)DDE_ITEM_DEBUGMESSAGE, CP_WINANSI ); ghszCommandItem = DdeCreateStringHandle( gDDEClientId, (LPSTR)DDE_ITEM_COMMAND, CP_WINANSI ); } gnClientCount++; }
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; }
int main (int argc, char *argv[]) { DWORD idDde = 0; HCONV HConversation; HSZ Server; HSZ Topic = 0; char command[1024]; if (argc < 2) { fprintf (stderr, "usage: ddeclient server [topic]\n"); exit (1); } DdeInitialize (&idDde, (PFNCALLBACK)DdeCallback, APPCMD_CLIENTONLY, 0); Server = DdeCreateStringHandle (idDde, argv[1], CP_WINANSI); if (argc > 2) Topic = DdeCreateStringHandle (idDde, argv[2], CP_WINANSI); HConversation = DdeConnect (idDde, Server, Topic, NULL); if (HConversation != 0) { while (fgets (command, sizeof(command), stdin) != NULL) DdeCommand (command); DdeDisconnect (HConversation); } DdeFreeStringHandle (idDde, Server); if (Topic) DdeFreeStringHandle (idDde, Topic); DdeUninitialize (idDde); return (0); }
/* Windows main routine */ int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { MSG msg; WNDCLASS wndclass; FARPROC pfnDdeCallback; UINT ddeerror; int argc = 3; char *argv[] = {"xsb","-i","-n"}; if (hPrevInstance) return FALSE; wndclass.style = 0; wndclass.lpfnWndProc = xsbProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; RegisterClass(&wndclass); hwnd = CreateWindow(szAppName,"XSB DDE Server",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, // x,y position CW_USEDEFAULT,CW_USEDEFAULT, // 200,100, // x,y size NULL,NULL,hInstance,NULL); ShowWindow(hwnd,nCmdShow); // nCmdShow UpdateWindow(hwnd); /* Initialize for DDE */ pfnDdeCallback = MakeProcInstance((FARPROC)DdeCallback,hInstance); idInst = 0; ddeerror = DdeInitialize(&idInst, (PFNCALLBACK)pfnDdeCallback, CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS, 0L); if (ddeerror) { sprintf(tempstring,"Could not initialize server!\n rc=%x, idInst=%x",ddeerror,idInst); MessageBox(hwnd,tempstring,szAppName, MB_ICONEXCLAMATION|MB_OK); DestroyWindow(hwnd); return FALSE; } freopen("xsblog","w",stdout); freopen("xsblog","a",stderr); /* Initialize xsb */ xsb_init(argc,argv); /* This seems necessary??? huh??? rcode = xsb_query_string("true."); while (!rcode) {rcode = xsb_next();} */ hszService = DdeCreateStringHandle(idInst,szAppName,0); DdeNameService(idInst,hszService,NULL,DNS_REGISTER); /* sprintf(tempstring,"XSB INITIALIZED!\n rc=%x, idInst=%x",ddeerror,idInst); MessageBox(hwnd,tempstring,szAppName, MB_ICONEXCLAMATION|MB_OK); */ while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } /* Close XSB connection */ xsb_close(); /* terminate DDE */ (void) DdeFreeStringHandle(idInst,hszService); FreeProcInstance(pfnDdeCallback); DdeUninitialize(idInst); return msg.wParam; }