DdeConnect

3.1

  #include <ddeml.h>    

  HCONV DdeConnect(idInst, hszService, hszTopic, pCC)    
  DWORD idInst; /* instance identifier, */  
  HSZ hszService; /* handle of service-name string */
  HSZ hszTopic; /* handle of topic-name string */
  CONVCONTEXT FAR* pCC; /* address of structure with context data */

The DdeConnect function establishes a conversation with a server application that supports the specified service name and topic name pair. If more than one such server exists, the system selects only one.

Parameters

idInst

Specifies the application-instance identifier obtained by a previous call to the DdeInitialize function.

hszService

Identifies the string that specifies the service name of the server application with which a conversation is to be established. This handle must have been created by a previous call to the DdeCreateStringHandle function. If this parameter is NULL, a conversation will be established with any available server.

hszTopic

Identifies the string that specifies the name of the topic on which a conversation is to be established. This handle must have been created by a previous call to the DdeCreateStringHandle function. If this parameter is NULL, a conversation on any topic supported by the selected server will be established.

pCC

Points to the CONVCONTEXT structure that contains conversation-context information. If this parameter is NULL, the server receives the default CONVCONTEXT structure during the XTYP_CONNECT or XTYP_WILDCONNECT transaction.

The CONVCONTEXT structure has the following form:

#include <ddeml.h>

typedef struct tagCONVCONTEXT { /* cc                         */
    UINT        cb;
    UINT        wFlags;
    UINT        wCountryID;
    int         iCodePage;
    DWORD       dwLangID;
    DWORD       dwSecurity;
} CONVCONTEXT;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value is the handle of the established conversation if the function is successful. Otherwise, it is NULL.

Errors

Use the DdeGetLastError function to retrieve the error value, which may be one of the following:

DMLERR_DLL_NOT_INITIALIZED
DMLERR_INVALIDPARAMETER
DMLERR_NO_CONV_ESTABLISHED
DMLERR_NO_ERROR

Comments

The client application should not make assumptions regarding which server will be selected. If an instance-specific name is specified in the hszService parameter, a conversation will be established only with the specified instance. Instance-specific service names are passed to an application's dynamic data exchange callback function during the XTYP_REGISTER and XTYP_UNREGISTER transactions.

All members of the default CONVCONTEXT structure are set to zero except cb, which specifies the size of the structure, and iCodePage, which specifies CP_WINANSI (the default code page).

Example

The following example creates a service-name string handle and a topic-name string handle, then attempts to establish a conversation with a server that supports the service name and topic name. If the attempt fails, the example retrieves an error value identifying the reason for the failure.

DWORD idInst = 0L;
HSZ hszClock;
HSZ hszTime;
HCONV hconv;
UINT uError;

hszClock = DdeCreateStringHandle(idInst, "Clock", CP_WINANSI);
hszTime = DdeCreateStringHandle(idInst, "Time", CP_WINANSI);

if ((hconv = DdeConnect(
    idInst,                  /* instance identifier                */
    hszClock,                /* server's service name              */
    hszTime,                 /* topic name                         */
    NULL)) == NULL) {        /* use default CONVCONTEXT            */
    uError = DdeGetLastError(idInst);
}

See Also

DdeConnectList, DdeCreateStringHandle, DdeDisconnect, DdeDisconnectList, DdeInitialize