Example #1
0
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;
}
Example #2
0
/****************************************************************************
 *                                                                          *
 *  FUNCTION   : CreateConv()   AE: Taken from DDEML sample app             *
 *                                                                          *
 *  PURPOSE    :                                                            *
 *                                                                          *
 *  RETURNS    :                                                            *
 *                                                                          *
 ****************************************************************************/
HCONV CConv::CreateConv(DWORD idInst,HSZ hszApp,HSZ hszTopic,BOOL fList,WORD *pError)
{
    HCONV hConv;
    HWND hwndConv = 0;
    CONVINFO ci;

    hConv = DdeConnect(idInst, hszApp, hszTopic, 0);
    if (hConv) {
        if (fList) {
            ci.hszSvcPartner = hszApp;
            ci.hszTopic = hszTopic;
        } else {
            ci.cb = sizeof(CONVINFO);
        DdeQueryConvInfo(hConv, (DWORD)QID_SYNC, &ci);
        }
 //       hwndConv = AddConv(ci.hszSvcPartner, ci.hszTopic, hConv, fList);
        // HSZs get freed when window dies.
    }
/*    if (!hwndConv) {
        if (pError != NULL) {
            *pError = DdeGetLastError(m_idInst);
        }
    }*/
    return(hConv);
}
Example #3
0
CDDEConnection *CDDEClient::MakeConnection(const CString& /* host */, const CString& server_name, const CString& topic)
{
    HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (const char *)server_name, CP_WINANSI);
    HSZ topic_atom = DdeCreateStringHandle(DDEIdInst, (const char *)topic, CP_WINANSI);

    HCONV hConv = DdeConnect(DDEIdInst, serviceName, topic_atom, (PCONVCONTEXT)NULL);
    BOOL rt = DdeFreeStringHandle(DDEIdInst, serviceName);
    rt = DdeFreeStringHandle(DDEIdInst, topic_atom);
    if (hConv == NULL)
        return NULL;
    else
    {
        CDDEConnection *connection = OnMakeConnection();
        if (connection)
        {
            connection->hConv = hConv;
            connection->topic_name = topic;
            connection->client = this;
            connections.AddTail(connection);
//	  bDisconnected = true;
            return connection;
        }
        else return NULL;
    }
}
Example #4
0
DDEconversation::DDEconversation(const char *_server, const char *_topic)
        : hConv(NULL)
{
    DDEstring server(_server);
    DDEstring topic(_topic);
    hConv = DdeConnect(*DDEbase::base, server, topic, NULL);
}
word
pl_open_dde_conversation(term_t service, term_t topic, term_t handle)
{ UINT i;
  HSZ Hservice, Htopic;

  if ( !dde_initialise() )
    fail;

  if ( !get_hsz(service, &Hservice) ||
       !get_hsz(topic, &Htopic) )
    fail;

  /* Establish a connection and get a handle for it */
  for (i=0; i < MAX_CONVERSATIONS; i++)   /* Find an open slot */
  { if (conv_handle[i] == (HCONV)NULL)
      break;
  }
  if (i == MAX_CONVERSATIONS)
    return PL_error(NULL, 0, NULL, ERR_RESOURCE, ATOM_max_dde_handles);

  if ( !(conv_handle[i] = DdeConnect(ddeInst, Hservice, Htopic, 0)) )
    fail;

  DdeFreeStringHandle(ddeInst, Hservice);
  DdeFreeStringHandle(ddeInst, Htopic);

  return PL_unify_integer(handle, i);
}
Example #6
0
bool WdeDDEStartConversation( void )
{
    if( IdInst == 0 ) {
        return( FALSE );
    }

    hService = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
    if( hService == (HSZ)NULL ) {
        return( FALSE );
    }

    hTopic = DdeCreateStringHandle( IdInst, WRE_DIALOG_TOPIC, CP_WINANSI );
    if( hTopic == (HSZ)NULL ) {
        return( FALSE );
    }

    WdeClientConv = DdeConnect( IdInst, hService, hTopic, (LPVOID)NULL );
    if( WdeClientConv == (HCONV)NULL ) {
        return( FALSE );
    }

    if( !WdeStartDDEEditSession() ) {
        return( FALSE );
    }

    return( TRUE );
}
Example #7
0
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;
}
Example #8
0
//Connect to DDE Server
int connectDDE(char* ServiceName, char* TopicName)
{

    //DDE requires special handles to Strings
    HSZ ServiceHSZ = DdeCreateStringHandle(Inst, ServiceName, 0);
    HSZ TopicHSZ = DdeCreateStringHandle(Inst, TopicName, 0);

    //Setup the connection between DDE client and server
    Conversation = DdeConnect(Inst, ServiceHSZ, TopicHSZ, NULL);

    DdeFreeStringHandle(Inst, ServiceHSZ);
    DdeFreeStringHandle(Inst, TopicHSZ);

    //If we recieve a handle then connection atempt was sucessul
    if (Conversation == NULL)
    {
        printf("Failed to Connect to DDE Server. Instance %d \n", Inst);
        DDEError(DdeGetLastError(Inst));
        return 1;
    }
    else
    {
        #ifdef _ddedebug
        printf("Connected DDE\n");
        #endif
        return 0;
    }
}
Example #9
0
//------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 );
}
Example #10
0
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 );
  }
//--------------------
//
BOOL	DDEIntegratorClient::ConnectToServer ()
{
	Disconnect();
	m_hConv = 
		DdeConnect( gDDEClientId, ghszIntegratorService, m_hszClientTopic, (PCONVCONTEXT)NULL );
	
	if ( m_hConv )
		gbServerConnected = TRUE;
	return (BOOL)m_hConv;
}
Example #12
0
/*****************************************************************
 *            DdeConnect   (DDEML.7)
 */
HCONV WINAPI DdeConnect16(DWORD idInst, HSZ hszService, HSZ hszTopic,
                          LPCONVCONTEXT16 pCC16)
{
    CONVCONTEXT	        cc;
    CONVCONTEXT*	pCC = NULL;

    if (pCC16)
        map1632_conv_context(pCC = &cc, pCC16);
    return DdeConnect(idInst, hszService, hszTopic, pCC);
}
Example #13
0
bool WEXPORT WClient::connect( const char *service, const char *topic ) {
/***********************************************************************/

    _service = DdeCreateStringHandle( _procid, (char *)service, CP_WINANSI );
    _topic = DdeCreateStringHandle( _procid, (char *)topic, CP_WINANSI );
    _hconv = DdeConnect( _procid, _service, _topic, NULL );
    if( _hconv != NULL ) {
        _convMap.setThis( this, (WHANDLE)_hconv );
        _connected = true;
        return( true );
    }
    DdeGetLastError( _procid );
    return( false );
}
Example #14
0
/*
 * IEDDEDumpConversation
 */
BOOL IEDDEDumpConversation( HINSTANCE inst )
{
    HCONV       hconv;
    HSZ         hservice;
    HSZ         htopic;
    BOOL        ok;

    ok = IEDDEStart( inst );

    if( ok ) {
        hservice = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
        ok = (hservice != (HSZ)NULL);
    }

    if( ok ) {
        htopic = DdeCreateStringHandle( IdInst, WRE_IMAGE_DUMP, CP_WINANSI );
        ok = (htopic != (HSZ)NULL);
    }

    if( ok ) {
        // We expect the server to reject this connect attempt.
        // If it doesn't, then we terminate the conversation.
        hconv = DdeConnect( IdInst, hservice, htopic, (LPVOID)NULL );
        if( hconv != (HCONV)NULL ) {
            DdeDisconnect( hconv );
        }
    }

    if( hservice != (HSZ)NULL ) {
        DdeFreeStringHandle( IdInst, hservice );
    }

    if( htopic != (HSZ)NULL ) {
        DdeFreeStringHandle( IdInst, htopic );
    }

    IEDDEEnd();

    if( !ok ) {
        IEDisplayErrorMsg( WIE_DDEINITTITLE, WIE_DDETERMINATIONMSG,
                           MB_OK | MB_ICONINFORMATION );
    }

    return( ok );

} /* IEDDEDumpConversation */
Example #15
0
JNIEXPORT jint JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_Connect
  (JNIEnv *env, jclass cls, jint idInst, jstring jhszService, jstring jhszTopic, jobject pCC)
{
	HSZ hszService = UtilCreateStringHandle(env, idInst, jhszService);
	HSZ hszTopic = UtilCreateStringHandle(env, idInst, jhszTopic);

	HCONV hConv = DdeConnect(
			idInst,					// instance identifier
			hszService,				// service name string handle
			hszTopic,				// topic string handle
			(PCONVCONTEXT) NULL);	// use default context

	UtilFreeStringHandle(idInst, hszService);
	UtilFreeStringHandle(idInst, hszTopic);

	return (UINT) hConv;
}
Example #16
0
void Senddde(char* tempstr)
{
  try
  {
    //Connect to the service and request the topic
    if ((hcnv = DdeConnect(idInst, hszService, hszTopic, NULL)) == 0)
    {
      ColorStop();
      return;
    }

    //Start a DDE transaction
    if (DdeClientTransaction((LPBYTE)tempstr, strlen(tempstr)+1,
          hcnv, hszItem, CF_TEXT, XTYP_POKE, 5000, &dwResult) == 0)
    {
      UINT result = DdeGetLastError(idInst);
      switch (result)
      {
        case DMLERR_ADVACKTIMEOUT:
        case DMLERR_BUSY:
        case DMLERR_DATAACKTIMEOUT:
        case DMLERR_DLL_NOT_INITIALIZED:
        case DMLERR_EXECACKTIMEOUT:
        case DMLERR_INVALIDPARAMETER:
        case DMLERR_MEMORY_ERROR:
        case DMLERR_NO_CONV_ESTABLISHED:
        case DMLERR_NO_ERROR:
        case DMLERR_NOTPROCESSED:
        case DMLERR_POKEACKTIMEOUT:
        case DMLERR_POSTMSG_FAILED:
        case DMLERR_REENTRANCY:
        case DMLERR_SERVER_DIED:
        case DMLERR_UNADVACKTIMEOUT:
        default:
          ColorStop();
      }
    }

    //Free DDE
    DdeDisconnect(hcnv);
  }
  catch(...)
  {
    ErrorHandler("Exception thrown in Senddde()!");
  }
}
Example #17
0
bool WdeDDEDumpConversation( HINSTANCE inst )
{
    HCONV       hconv;
    HSZ         hservice;
    HSZ         htopic;
    bool        ok;

    ok = WdeDDEStart( inst );

    if( ok ) {
        hservice = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
        ok = (hservice != (HSZ)NULL);
    }

    if( ok ) {
        htopic = DdeCreateStringHandle( IdInst, WRE_DIALOG_DUMP, CP_WINANSI );
        ok = (htopic != (HSZ)NULL);
    }

    if( ok ) {
        // We expect the server to reject this connect attempt.
        // If it doesn't, then we terminate the conversation.
        hconv = DdeConnect( IdInst, hservice, htopic, (LPVOID)NULL );
        if( hconv != (HCONV)NULL ) {
            DdeDisconnect( hconv );
        }
    }

    if( hservice != (HSZ)NULL ) {
        DdeFreeStringHandle( IdInst, hservice );
    }

    if( htopic != (HSZ)NULL ) {
        DdeFreeStringHandle( IdInst, htopic );
    }

    WdeDDEEnd();

    if( !ok ) {
        WdeDisplayErrorMsg( WDE_DDEDEATHMSG );
    }

    return( ok );
}
Example #18
0
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);
}
Example #19
0
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;
}
Example #20
0
File: ms1.cpp Project: nrnhines/nrn
int start() {
HandleOutput("hel2mos start-\n");
	if (!idInst) {
		MessageBox(NULL, "idInst is 0", "ochelp start", MB_OK);
		return 0;
	}
		hszService = DdeCreateStringHandle ( idInst, "NETSCAPE", CP_WINANSI );
		hszTopic = DdeCreateStringHandle ( idInst, "WWW_OpenURL", CP_WINANSI );
		hszItem = DdeCreateStringHandle ( idInst, "NetscapeData", CP_WINANSI );
		hConvExtra = DdeConnect ( idInst, hszService, hszTopic,
					(PCONVCONTEXT) NULL );
		if (!hConvExtra) {
			MessageBox(NULL, "Conversation not established with NETSCAPE",
				"ochelp start", MB_OK);
			return 0;
		}
HandleOutput("Conversation established with NETSCAPE\n");
		return 1;
}
Example #21
0
File: dde.c Project: Madzi/POW
BOOL DdeSendCommand (LPSTR service,LPSTR topic,LPSTR command)
{
    DWORD result;
    HCONV hconv;                
    HSZ hservice,htopic;
    BOOL done;

    done=FALSE;
    hservice=DdeCreateStringHandle(ddeInstId,(LPSTR)service,CP_WINANSI);
    htopic=DdeCreateStringHandle(ddeInstId,(LPSTR)topic,CP_WINANSI);

    if (hconv=DdeConnect(ddeInstId,hservice,htopic,0)) {
        if (DdeClientTransaction(command,lstrlen(command)+1,hconv,0,CF_TEXT,XTYP_EXECUTE,10000l,(DWORD FAR *)&result))
            done=TRUE;
        DdeDisconnect(hconv); 
    }
    
    DdeFreeStringHandle(ddeInstId,hservice);
    DdeFreeStringHandle(ddeInstId,htopic);

    return done;
}
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
}
Example #23
0
/*
 * IEDDEStartConversation
 */
BOOL IEDDEStartConversation( void )
{
    if( IdInst == 0 ) {
        return( FALSE );
    }

    hService = DdeCreateStringHandle( IdInst, WRE_SERVICE_NAME, CP_WINANSI );
    if( hService == (HSZ)NULL ) {
        return( FALSE );
    }

    IEClientConv = DdeConnect( IdInst, hService, (HSZ)NULL, (LPVOID)NULL );
    if( IEClientConv == (HCONV)NULL ) {
        return( FALSE );
    }

    if( !IEStartDDEEditSession() ) {
        return( FALSE );
    }

    return( TRUE );

} /* IEDDEStartConversation */
Example #24
0
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);
}
Example #25
0
File: gvwdde2.c Project: 131/gsview
/* Assume dde_initialise has already been called */
BOOL
dde_execute(char *str)
{
HSZ hszServName;
HSZ hszTopicName;
HCONV hConv;
DWORD dwResult = DDE_FNOTPROCESSED;

    /* Make connection to server */
    hszServName = DdeCreateStringHandleA(idInst, (LPSTR)szServiceName, 
	CP_WINANSI);
    hszTopicName = DdeCreateStringHandleA(idInst, (LPSTR)szTopicName, 
	CP_WINANSI);
    hConv = DdeConnect(idInst, hszServName, hszTopicName, (PCONVCONTEXT)NULL);
    if (hConv == NULL) {
	DdeFreeStringHandle(idInst, hszServName);
	DdeFreeStringHandle(idInst, hszTopicName);
	if (debug)
	    gs_addmess("DdeConnect failed\r\n");
	return FALSE;
    }

    /* send command */
    DdeClientTransaction((LPBYTE)str, strlen(str)+1, hConv,
	NULL, CF_TEXT, XTYP_EXECUTE, 10000, &dwResult);

    /* Disconnect from server */
    DdeDisconnect(hConv);
    DdeFreeStringHandle(idInst, hszServName);
    DdeFreeStringHandle(idInst, hszTopicName);
    if (debug) {
	gs_addmess("Sent XTYP_EXECUTE: ");
	gs_addmess(str);
	gs_addmess("\r\n");
    }
    return (dwResult == DDE_FACK);
}
Example #26
0
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;
}
Example #27
0
int
main (int argc, char *argv[])
{
  char start_folder[MAX_PATH + 1];
  int shortcuts_created = 0;
  int com_available = 1;
  char modname[MAX_PATH];
  const char *prog_name;
  const char *emacs_path;
  char *p;
  int quiet = 0;
  HRESULT result;
  IShellLinkA *shortcut;

  /* If no args specified, use our location to set emacs_path.  */

  if (argc > 1
      && (argv[1][0] == '/' || argv[1][0] == '-')
      && argv[1][1] == 'q')
    {
      quiet = 1;
      --argc;
      ++argv;
    }

  if (argc > 1)
    emacs_path = argv[1];
  else
    {
      if (!GetModuleFileName (NULL, modname, MAX_PATH) ||
	  (p = strrchr (modname, '\\')) == NULL)
	{
	  fprintf (stderr, "fatal error");
	  exit (1);
	}
      *p = 0;

      /* Set emacs_path to emacs_dir if we are in "%emacs_dir%\bin".  */
      if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0)
	{
	  *p = 0;
	  emacs_path = modname;
	}
      else
	{
	  fprintf (stderr, "usage: addpm emacs_path\n");
	  exit (1);
	}

      /* Tell user what we are going to do.  */
      if (!quiet)
	{
	  int result;

	  char msg[ MAX_PATH ];
	  sprintf (msg, "Install Emacs at %s?\n", emacs_path);
	  result = MessageBox (NULL, msg, "Install Emacs",
			       MB_OKCANCEL | MB_ICONQUESTION);
	  if (result != IDOK)
	    {
	      fprintf (stderr, "Install cancelled\n");
	      exit (1);
	    }
	}
    }

  add_registry (emacs_path);
  prog_name =  "runemacs.exe";

  /* Try to install globally.  */

  if (!SUCCEEDED (CoInitialize (NULL))
      || !SUCCEEDED (CoCreateInstance (&CLSID_ShellLink, NULL,
					CLSCTX_INPROC_SERVER, &IID_IShellLinkA,
					(void **) &shortcut)))
    {
      com_available = 0;
    }

  if (com_available
      && SHGetSpecialFolderPath (NULL, start_folder, CSIDL_COMMON_PROGRAMS, 0))
    {
      if (strlen (start_folder) < (MAX_PATH - 20))
	{
	  strcat (start_folder, "\\Gnu Emacs");
	  if (CreateDirectory (start_folder, NULL)
	      || GetLastError () == ERROR_ALREADY_EXISTS)
	    {
	      char full_emacs_path[MAX_PATH + 1];
	      IPersistFile *lnk;
	      strcat (start_folder, "\\Emacs.lnk");
	      sprintf (full_emacs_path, "%s\\bin\\%s", emacs_path, prog_name);
	      IShellLinkA_SetPath (shortcut, full_emacs_path);
	      IShellLinkA_SetDescription (shortcut, "GNU Emacs");
	      result = IShellLinkA_QueryInterface (shortcut, &IID_IPersistFile,
						   (void **) &lnk);
	      if (SUCCEEDED (result))
		{
		  wchar_t unicode_path[MAX_PATH];
		  MultiByteToWideChar (CP_ACP, 0, start_folder, -1,
				       unicode_path, MAX_PATH);
		  if (SUCCEEDED (IPersistFile_Save (lnk, unicode_path, TRUE)))
		    shortcuts_created = 1;
		  IPersistFile_Release (lnk);
		}
	    }
	}
    }

  if (!shortcuts_created && com_available
      && SHGetSpecialFolderPath (NULL, start_folder, CSIDL_PROGRAMS, 0))
    {
      /* Ensure there is enough room for "...\GNU Emacs\Emacs.lnk".  */
      if (strlen (start_folder) < (MAX_PATH - 20))
	{
	  strcat (start_folder, "\\Gnu Emacs");
	  if (CreateDirectory (start_folder, NULL)
	      || GetLastError () == ERROR_ALREADY_EXISTS)
	    {
	      char full_emacs_path[MAX_PATH + 1];
	      IPersistFile *lnk;
	      strcat (start_folder, "\\Emacs.lnk");
	      sprintf (full_emacs_path, "%s\\bin\\%s", emacs_path, prog_name);
	      IShellLinkA_SetPath (shortcut, full_emacs_path);
	      IShellLinkA_SetDescription (shortcut, "GNU Emacs");
	      result = IShellLinkA_QueryInterface (shortcut, &IID_IPersistFile,
						   (void **) &lnk);
	      if (SUCCEEDED (result))
		{
		  wchar_t unicode_path[MAX_PATH];
		  MultiByteToWideChar (CP_ACP, 0, start_folder, -1,
				       unicode_path, MAX_PATH);
		  if (SUCCEEDED (IPersistFile_Save (lnk, unicode_path, TRUE)))
		    shortcuts_created = 1;
		  IPersistFile_Release (lnk);

		}
	    }
	}
    }

  if (com_available)
    IShellLinkA_Release (shortcut);

  /* Need to call uninitialize, even if ComInitialize failed.  */
  CoUninitialize ();

  /* Fallback on old DDE method if the above failed.  */
  if (!shortcuts_created)
    {
      DWORD dde = 0;
      HCONV conversation;
      HSZ progman;
      char add_item[MAX_PATH*2 + 100];

      DdeInitialize (&dde, (PFNCALLBACK) DdeCallback, APPCMD_CLIENTONLY, 0);
      progman = DdeCreateStringHandle (dde, "PROGMAN", CP_WINANSI);
      conversation = DdeConnect (dde, progman, progman, NULL);
      if (conversation)
	{
	  DdeCommand ("[CreateGroup (\"Gnu Emacs\")]");
	  DdeCommand ("[ReplaceItem (Emacs)]");
	  sprintf (add_item, "[AddItem (\"%s\\bin\\%s\", Emacs)]",
		   emacs_path, prog_name);
	  DdeCommand (add_item);

	  DdeDisconnect (conversation);
	}

      DdeFreeStringHandle (dde, progman);
      DdeUninitialize (dde);
   }

  return 0;
}
Example #28
0
HXBOOL BrowserOpenURL(const char* pszUrl, const char* pszTarget, const char* pszDefBrowser) 
{
    HX_TRACE("BrowserOpenURL()\r\n");

    HXBOOL	result = TRUE;
    DWORD	dwResult = 0;
    HDDEDATA	hOpenRetVal = NULL;
    HSZ		hszOpenTopic = NULL;
    HSZ		hszOpenItem = NULL;
    HCONV	hOpenConv = NULL;
    HDDEDATA	hActivateRetVal = NULL;
    HSZ		hszActivateTopic = NULL;
    HSZ		hszActivateItem = NULL;
    HCONV	hActivateConv = NULL;
    UINT16	i = 0;
    UINT16	nNumberOfBrowsers = 0;
    char*	pMessage = NULL;
    DWORD	dwWindowID = 0xFFFFFFFF;	    // -1 = last active window
    DWORD	dwLockTimeout = 0;
    HXBOOL	bForceBroswserToForeground = FALSE;
    HXVERSIONINFO versionInfo;

    if (!pszUrl)
    {
	result = FALSE;
	goto cleanup;
    }

    pMessage = new char[strlen(pszUrl)+48];
    if (!pMessage)
    {
	result = FALSE;
	goto cleanup;
    }

    // handle pszTarget parameter according to:
    // https://common.helixcommunity.org/nonav/2003/HCS_SDK_r5/htmfiles/HyperNavigate.htm
    if (pszTarget && (0 == strcmp(pszTarget, "_new") || 0 == strcmp(pszTarget, "_blank")))
    {
        dwWindowID = 0;
    }

    ZeroInit(&versionInfo);
    HXGetWinVer(&versionInfo);
    bForceBroswserToForeground = ((versionInfo.dwPlatformId == HX_PLATFORM_WIN98) || (versionInfo.dwPlatformId == HX_PLATFORM_WINNT && versionInfo.wMajorVersion > 4));
    
    DDEStartup();

    // establish browser
    if (NULL == g_hszWWWService)
    {
	hszOpenTopic = DdeCreateStringHandle(g_dwIdInst, "WWW_OpenURL", CP_WINANSI);
	if (hszOpenTopic)
	{
	    nNumberOfBrowsers = sizeof(g_BrowsersSupportingDDE)/sizeof(DDE_Browsers);

	    // Look for a browser that supports DDE???
	    while (i < nNumberOfBrowsers)
	    {
		g_hszWWWService = DdeCreateStringHandle(g_dwIdInst,
						        g_BrowsersSupportingDDE[i].szDDEName,
							CP_WINANSI);

		hOpenConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszOpenTopic, NULL);
		if (hOpenConv)
		{
		    break;
		}

		if(g_hszWWWService)
		{
		    DdeFreeStringHandle(g_dwIdInst, g_hszWWWService);
		    g_hszWWWService = NULL;  
		}

		i++;
	    }
	}

	if (NULL == g_hszWWWService)
	{
	    result = FALSE;
	    goto cleanup;
	}
    }
    else
    {
	hszOpenTopic = DdeCreateStringHandle(g_dwIdInst,"WWW_OpenURL", CP_WINANSI);
	hOpenConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszOpenTopic, NULL);
    }

    if (!hOpenConv)
    {
	HX_TRACE("Conversation failed to start...\r\n");
	
	DdeFreeStringHandle(g_dwIdInst, g_hszWWWService);
	g_hszWWWService = NULL;

	result = FALSE;
	goto cleanup;
    }

    wsprintf(pMessage,"\"%s\",,%lu,0,,,,", pszUrl, dwWindowID); 
    hszOpenItem = DdeCreateStringHandle(g_dwIdInst, pMessage, CP_WINANSI);

    HX_TRACE("Conversation started, sending URL command...\r\n");

    // Request
    hOpenRetVal = DdeClientTransaction(NULL, 0, hOpenConv, hszOpenItem, CF_TEXT, XTYP_REQUEST, 60000, NULL);
    if (DDE_FNOTPROCESSED != hOpenRetVal)
    {
	DdeGetData(hOpenRetVal, (LPBYTE)&dwResult, sizeof(dwResult), 0);
	if (!dwResult)
	{
	    result = FALSE;
	    goto cleanup;
	}
    }

    // force the browser to the foreground then do it here.  This does not actually put the browser
    // in the foreground instead it enables the browser's call to SetForegroundWindow to bring the window to the
    // front instead of flashing it on the taskbar
    if (bForceBroswserToForeground)
    {
	// These are new flags that work on Win98 and WinNT5 ONLY.  First get the current foreground lock timeout and save
	// it off and then set it to 0.
	::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&dwLockTimeout,0);
	::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,0);
    }

    // activate the browser
    wsprintf(pMessage, "%lu,0", dwWindowID); 
    hszActivateItem = DdeCreateStringHandle(g_dwIdInst, pMessage, CP_WINANSI);
    hszActivateTopic = DdeCreateStringHandle(g_dwIdInst,"WWW_Activate", CP_WINANSI);

    // Connect to server
    if (hszActivateTopic && hszActivateItem)
    {
	hActivateConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszActivateTopic, NULL);
	if (hActivateConv)
	{
	    hActivateRetVal = DdeClientTransaction(NULL, 0, hActivateConv, hszActivateItem, CF_TEXT, XTYP_REQUEST, 10000, NULL);
	}
    }

    if (bForceBroswserToForeground)
    {
	// Restore the old foreground lock timeout
	::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)dwLockTimeout,0);
    }

cleanup:

    if (hOpenRetVal)
	DdeFreeDataHandle(hOpenRetVal);
    if (hActivateRetVal)
	DdeFreeDataHandle(hActivateRetVal);

    if (hszOpenTopic)
	DdeFreeStringHandle(g_dwIdInst, hszOpenTopic);    
    if (hszActivateTopic)
	DdeFreeStringHandle(g_dwIdInst, hszActivateTopic);    

    if (hszOpenItem)    
	DdeFreeStringHandle(g_dwIdInst, hszOpenItem);
    if (hszActivateItem)    
	DdeFreeStringHandle(g_dwIdInst, hszActivateItem);

    if (hOpenConv)
	DdeDisconnect(hOpenConv);
    if (hActivateConv)
	DdeDisconnect(hActivateConv);

    HX_VECTOR_DELETE(pMessage);
    
    DDEShutdown();

    return result;
}
Example #29
0
LONG WINAPI MainWndProc(HWND hWnd, UINT message, WPARAM wPrm, LONG lPrm)
{
  DLGPROC lpProcAbout;
  FILE *fp;

  switch(message) {
  case WM_COMMAND:
    switch (GET_WM_COMMAND_ID(wPrm, lPrm)) {
    case IDM_ABOUT:
      lpProcAbout = (DLGPROC) MakeProcInstance((FARPROC) About, hInst);
      DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
      (void) FreeProcInstance((FARPROC) lpProcAbout);
      break;
    case IDM_NEW:
      if (! QuerySaveFile()) return(FALSE);
      bChanges = FALSE;
      FileName[0] = 0;
      SetNewBuffer(NULL, Untitled);
      break;
    case IDM_OPEN:
      if (! QuerySaveFile())
        return FALSE;
      if (! OpenDlg() || (fp = fopen(FileName, "r")) == NULL)
        return FALSE;
      ReanInFile(fp);
      return FALSE;
    case IDM_SAVE:
      if (! FileName[0]) goto saveas;
      if (bChanges) SaveFile();
      break;
    case IDM_SAVEAS:
saveas:
      if (SaveAsDlg()) {
	sprintf(buf, "LSPEdit - %s", FileName);
	if (SaveFile())
          SetWindowText(hWnd, buf);
        else {
          FileName[0] = 0;
          SetWindowText(hWnd, Untitled);
        }
      }
      break;
    case IDM_PRINT:
      WarningBox("Command Not Implemented");
      break;
    case IDM_EXIT:
      if (! QuerySaveFile()) return FALSE;
      DestroyWindow(hWnd);
      break;
    case IDM_UNDO:
      WarningBox("Command Not Implemented");
      break;
    case IDM_CUT:
      TTYSelToClip();
      TTYClearSel();
      break;
    case IDM_COPY:
      TTYSelToClip();
      break;
    case IDM_PASTE:
      TTYPasteFromClip();
      break;
    case IDM_CLEAR:
      TTYClearSel();
      break;
    case IDM_EVAL:
      {
        HSZ service, topic;
        HCONV hconv;

        service = DdeCreateStringHandle(ddeInst, "XLISP-STAT", CP_WINANSI);
        topic = DdeCreateStringHandle(ddeInst, "XLISP-STAT", CP_WINANSI);
        if ((hconv = DdeConnect(ddeInst, service, topic, NULL)) == NULL)
          WarningBox("Can't connect to XLISP-STAT");
        else {
          /**** switch to allocated buffer? */
          char *data = TTYSelectionStr();
          if (! DdeClientTransaction((LPVOID) data, strlen(data) + 1,
                                     hconv, NULL, CF_TEXT, XTYP_EXECUTE,
                                     60000L, NULL))
            WarningBox("Transaction failed");
          DdeDisconnect(hconv);
        }
        DdeFreeStringHandle(ddeInst, service);
        DdeFreeStringHandle(ddeInst, topic);
      }
      break;
    case IDC_EDIT:
      if (GET_WM_COMMAND_CMD(wPrm, lPrm) == EN_ERRSPACE) {
	WarningBox("Out of memory");
      }
      if (GET_WM_COMMAND_CMD(wPrm, lPrm) == EN_CHANGE) bChanges = TRUE;
      break;
    default: return(DefWindowProc(hWnd, message, wPrm, lPrm));
    }
    break;
  case WM_SETFOCUS:
    SetFocus(hEditWnd);
    break;
  case WM_SIZE:
    MoveWindow(hEditWnd, 0, 0, LOWORD(lPrm), HIWORD(lPrm), TRUE);
    break;
  case WM_QUERYENDSESSION:
    return(QuerySaveFile());
  case WM_CLOSE:
    if (QuerySaveFile()) DestroyWindow(hWnd);
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  default:
    return(DefWindowProc(hWnd, message, wPrm, lPrm));
  }
  return FALSE;
}
Example #30
0
File: gvwdde.c Project: 131/gsview
int
gsview_progman(char *groupname, char *gsviewpath, int gsver, char *gspath, char *gsargs)
{
DWORD idInst = 0L;
FARPROC lpDdeProc;
HSZ hszServName;
HSZ hszSysTopic;
HSZ hszGroupsItem;
HCONV hConv;
HDDEDATA hdata = NULL;
char setup[MAXSTR+MAXSTR];
DWORD dwResult;
char groupfile[MAXSTR];
int i;
char *s, *d;
FILE *ddefile;
char gspathbuf[MAXSTR];
char gsviewpathbuf[MAXSTR];
char gsdocbuf[MAXSTR];

    strncpy(gspathbuf, gspath, sizeof(gspathbuf)/sizeof(TCHAR));
    strncpy(gsdocbuf, gsargs, sizeof(gsdocbuf)/sizeof(TCHAR));
    d = strchr(gsdocbuf, ';');
    if (d)
       *d = '\0';
    if (gsver >= 593) {
	d = strrchr(gsdocbuf, '\\');
	if (d) {
	    d++;
	    strcpy(d, "doc\\");
	}
    }
    else {
	strcat(gsdocbuf, "\\");
    }
    strncpy(gsviewpathbuf, gsviewpath, sizeof(gsviewpathbuf));
    if (!is_win32s) {
	/* The DDE interface isn't reliable with long names */
	/* Convert everything to short names */
	GetShortPathNameA(gspath, gspathbuf, sizeof(gspathbuf));
	GetShortPathNameA(gsviewpath, gsviewpathbuf, sizeof(gsviewpathbuf));
    }

    /* Open ProgMan DDE undo file if it doesn't exist */
    strcpy(setup, gsviewpathbuf);
    strcat(setup, GSVIEW_ZIP);
    d = strrchr(setup, '.');
    strcpy(d, "dde.log");
    ddefile = fopen(setup, "r");
    if (ddefile != (FILE *)NULL) {
	/* We found a previous ProgMan DDE undo file. */
	/* Don't touch it since we want to keep the original record */
	/* of the ProgMan state before GSview was installed */ 
	fclose(ddefile);
	ddefile = (FILE *)NULL;
    }
    else {
        ddefile = fopen(setup, "w");
	/* If we fail to open the file for writing, the destination is probably 
	 * read only.  Don't worry, just don't write to the log file.
	 */
    }

    /* derive group filename from group name */
    for (i=0, s=groupname, d=groupfile; i<8 && *s; s++) {
	if (isalpha((int)(*s)) || isdigit((int)(*s))) {
	    *d++ = *s;
	    i++;
	} 
    }
    *d = '\0';
    if (strlen(groupfile)==0)
	strcpy(groupfile, "gstools");

    lpDdeProc = MakeProcInstance((FARPROC)DdeCallback, phInstance);
    if (DdeInitialize(&idInst, (PFNCALLBACK)lpDdeProc, CBF_FAIL_POKES, 0L)) {
	return 1;
    }
    hszServName = DdeCreateStringHandleA(idInst, "PROGMAN", CP_WINANSI);
    hszSysTopic = DdeCreateStringHandleA(idInst, "PROGMAN", CP_WINANSI);
    hConv = DdeConnect(idInst, hszServName, hszSysTopic, (PCONVCONTEXT)NULL);
    if (hConv == NULL) {
	DdeFreeStringHandle(idInst, hszServName);
	DdeFreeStringHandle(idInst, hszSysTopic);
	return 1;
    }

    if (ddefile) {
	/* Find out if group existed */
	hszGroupsItem = DdeCreateStringHandleA(idInst, groupname, CP_WINANSI);
	hdata = DdeClientTransaction((LPBYTE)NULL, 0, hConv,\
	    hszGroupsItem, CF_TEXT, XTYP_REQUEST, 5000, &dwResult);
	DdeFreeStringHandle(idInst, hszGroupsItem);
    }

#define DDEEXECUTE(str)\
    DdeClientTransaction((LPBYTE)str, strlen(str)+1, hConv,\
	NULL, CF_TEXT, XTYP_EXECUTE, 5000, &dwResult)

    sprintf(setup, "[CreateGroup(\042%s\042,%s.grp)][ShowGroup(\042%s\042,1)]",
	groupname, groupfile, groupname);  /* display, active */
    DDEEXECUTE(setup);
    if (ddefile)	/* display, no active */
        fprintf(ddefile, "[ShowGroup(\042%s\042,8)]\n",groupname);
    sprintf(setup, "[ReplaceItem(\042%s\042)]", GSVIEW_NAME);
    DDEEXECUTE(setup);
#ifdef _WIN64
#define GSVIEW_ICON "gsview64.ico"
#else
#define GSVIEW_ICON "gsview32.ico"
#endif
    if (!is_win4)
       sprintf(setup, "[AddItem(\042%s%s\042,\042%s\042, \042%s%s\042)]", 
	  gsviewpathbuf, GSVIEW_EXENAME, GSVIEW_NAME, gsviewpathbuf, 
	  GSVIEW_ICON);
    else
       sprintf(setup, "[AddItem(\042%s%s\042,\042%s\042)]", 
	  gsviewpathbuf, GSVIEW_EXENAME, GSVIEW_NAME);
    DDEEXECUTE(setup);
    if (ddefile)
        fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", GSVIEW_NAME);

/* Win3.1 documentation says you must put quotes around names */
/* with embedded spaces. */
/* In Win95, it appears you must put quotes around the EXE name */
/* and options separately */

    sprintf(setup, "[ReplaceItem(\042GSview README\042)]");
    DDEEXECUTE(setup);
#ifdef NOTUSED_IN_GSVIEW28
    if (!is_win4)
	sprintf(setup, "[AddItem(\042notepad.exe %sREADME.TXT\042,\042GSview README\042)]", 
	    gsviewpathbuf);
    else
	sprintf(setup, "[AddItem(\042notepad.exe\042 \042%sREADME.TXT\042,\042GSview README\042,\042notepad.exe\042,1)]", 
	    gsviewpathbuf);
#endif
    sprintf(setup, "[AddItem(\042%sReadme.htm\042,\042GSview README\042)]", 
	    gsviewpathbuf);
    DDEEXECUTE(setup);
    if (ddefile)
        fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "GSview README");

    sprintf(setup, "[ReplaceItem(\042Ghostscript\042)]");
    DDEEXECUTE(setup);
    if (!is_win4)
        sprintf(setup, "[AddItem(\042%s%s -I%s\042,\042Ghostscript\042, \042%sgstext.ico\042)]", 
	    gspathbuf, GS_EXENAME, gsargs, gspathbuf);
    else
        sprintf(setup, "[AddItem(\042%s%s\042 \042-I%s\042,\042Ghostscript\042)]", 
	    gspathbuf, GS_EXENAME, gsargs);
    DDEEXECUTE(setup);
    if (ddefile)
        fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "Ghostscript");

    sprintf(setup, "[ReplaceItem(\042Ghostscript README\042)]");
    DDEEXECUTE(setup);
    if (gsver >= 540) {
	    sprintf(setup, 
		"[AddItem(\042%sReadme.htm\042,\042Ghostscript README\042)]", 
		 gsdocbuf);
    }
    else {
	if (!is_win4)
	    sprintf(setup, "[AddItem(\042notepad.exe %sREADME.\042,\042Ghostscript README\042)]", 
		 gsdocbuf);
	else
	    sprintf(setup, "[AddItem(\042notepad.exe\042 \042%sREADME.\042,\042Ghostscript README\042, \042notepad.exe\042,1)]", 
		 gsdocbuf);
    }
    DDEEXECUTE(setup);
    if (ddefile)
        fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "Ghostscript README");


#undef DDEXECUTE

    /* Now remember the way things were */
    if (ddefile) {
      if (hdata) {
	DWORD dlen;
	BYTE FAR *lpData = DdeAccessData(hdata, &dlen);
	LPSTR p, q;
	/* skip first line */
	q = (LPSTR)lpData;
	while (*q && (*q != '\r') && (*q != '\n'))
	    q++;
	while (*q && ((*q == '\r') || (*q == '\n')))
	    q++;
	p = q;
	/* for each group item */
	while (*p) {
	    /* skip to end of line */
	    while (*q && (*q != '\r') && (*q != '\n'))
		q++;
	    strncpy(setup, p, (int)(q-p)+1);
	    add_group_item(ddefile, setup);
	    /* skip to start of next group name */
	    while (*q && ((*q == '\r') || (*q == '\n')))
		q++;
	    p = q;
	}
	if (ddefile)		/* display, no active */
	    fprintf(ddefile, "[ShowGroup(\042%s\042,8)]\n",groupname);
	DdeUnaccessData(hdata);
	DdeFreeDataHandle(hdata);
      }
      else {
	/* group didn't exist before, so delete it */
        fprintf(ddefile, "[DeleteGroup(\042%s\042)]\n", groupname);
      }
      fclose(ddefile);
    }

    DdeDisconnect(hConv);
    DdeFreeStringHandle(idInst, hszServName);
    DdeFreeStringHandle(idInst, hszSysTopic);
    DdeUninitialize(idInst);

    return 0;
}