DdeInitiate

DdeInitiate initiates a DDE conversation between UniPlot and another application.

hConv = DdeInitiate(ssService, ssTopic)

Return Value

hConv is the channel number (handle) which is used with other UniPlot DDE functions. If an error occurred, the function returns 0.

Parameters

ssService

ssService is a service name. Normally, ssService is the name of an EXE file without the extension. The service name for UniPlot is "UniPlotSL".

ssTopic

ssTopic is the topic of the conversation. For most applications the names of already open documents are allowed topics. Most applications support the topic “system”.

Comment

A list of all open DDE channels can be received by calling the function ObjShow.

Example

The following DDE conversation starts Excel and inserts the numbers 1,2,3,4 into an Excel spreadsheet.

At first the function system starts Excel. The value 0 of the third parameter causes the function to return immediately.

def FindApp(ssApp)
{
    RegConnect("HKEY_LOCAL_MACHINE")
    b = RegOpen("Software\Classes\" + ssApp + "\CLSID");
    s = RegGetValue("");
    RegOpen("Software\Classes\CLSID\" + s + "\LocalServer32")
    return RegGetValue("");
}
s = FindApp("Excel.Application");
if (s == "") {
    MessageBoxError("Excel not found");
    return;
}
system(s, SW_SHOW, 0);

The following function call opens a channel to the topic "System".

hConv = DdeInitiate("Excel", "System");

DdeRequest requests the system topics.

ssTopics = DdeRequest(hConv, "Topics");

The following function call opens a channel to the first topic (the first Excel spread sheet).

hConvTable = DdeInitiate("Excel", strtok(ssTopics, "\t")[1]);

The function DdePoke writes the numbers 1,2,3,4 into the first Excel spread sheet. In the English Excel version, cell range is specified as R1C1:R2C2 (Row/Column) In the German Excel version, cell range is specified as Z1S1:Z2S2 (Row/Column). The numbers in a row are separated by tab characters ("\t"), rows are separated by the character sequence "\r\n".

DdePoke(hConvTable, "R1C1:R2C2", "1\t2\r\n3\t4")

When the conversation is finished, all channels should be closed.

DdeTerminate(hConvTable);
DdeTerminate(hConv);

Example

// HKEY_CURRENT_USER\Software\Classes\CLSID\{F0C8D974-51B6-11D0-BE90-008048AA0191}\LocalServer32
def FindUniPlot()
{
    RegConnect("HKEY_CURRENT_USER")
    b = RegOpen("Software\\Classes\\UniPlot.Application\\CLSID");
    s = RegGetValue("");
    RegOpen("Software\\Classes\\CLSID\\" + s + "\\LocalServer32")
    return RegGetValue("");
}


def FindApp(ssApp)
{
    RegConnect("HKEY_LOCAL_MACHINE")
    b = RegOpen("Software\\Classes\\" + ssApp + "\\CLSID");
    s = RegGetValue("");
    RegOpen("Software\\Classes\\CLSID\\" + s + "\\LocalServer32")
    return RegGetValue("");
}

def test_DdeExecute()
{
    s = FindApp("Excel.Application");
    if (s == "") {
        MessageBoxError("Excel not found");
        return;
    }
    system(s, SW_HIDE, 0);
    hConv = DdeInitiate("Excel", "System");
    DdeExecute(hConv, "[OPEN(\"" + GetRootDirectory() + "samples\\map-data.xls\")]")
    hconvTab = DdeInitiate("Excel", "map-data.xls");
    ssData = DdeRequest(hconvTab, "z1s1:z16384s255");
    ssData = strfindreplace(ssData, ",", ".");
    DdeExecute(hConv, "[CLOSE()]");
    DdeExecute(hConv, "[QUIT()]");
    DdeTerminateAll();

    hedit = EdCreate();
    EdSetText(hedit, ssData);
}

test_DdeExecute();

id-1361586