National Instruments 320682C Musical Toy Instrument User Manual


 
Chapter 6 DDE Library
© National Instruments Corporation 6-5 LabWindows/CVI Standard Libraries
A DDE Library Example Using Microsoft Excel and LabWindows/CVI
LabWindows/CVI includes a sample program called ddedemo.prj that uses DDE to send data
to Microsoft Excel. The example program can be found in the samples\ddetcp directory.
The following discussion outlines the process required to open an Excel worksheet file, send data
over DDE, and setup a DDE link with one of the cells in the worksheet from a LabWindows/CVI
program. Start Excel and load the worksheet file called LWCVI.XLS. The sample program
performs the following operations.
1. Connects to the Microsoft Excel worksheet as a client.
The function, ConnectToDDEServer, with excel as the server name and LWCVI.XLS
as the topic name, establishes a connection with the worksheet. The Callback Function
Pointer, ClientCallback, identifies the function which will process the DDE
transactions generated from this particular conversation.
2. Establishes a DDE warm link with a particular cell in the Excel worksheet.
The function, SetUpDDEWarmLink, with the cell address (R5C2) as the item name,
establishes a DDE link between the cell in the worksheet. Thereafter, whenever the value of
cell B5 (row 5, column 2) changes, Excel sends information to LabWindows/CVI by
triggering the
clientCallbackFunction
.
3. Sends data to the Excel worksheet from LabWindows/CVI.
After the data is formatted as a string, it is sent to Excel using the ClientDDEWrite
function with the Excel cell region (R1C2:R50C2) as the item name, and the character
array, containing 50 elements, as the buffer pointer.
4. The callback function responds to DDE transactions from the Excel worksheet.
The callback function automatically returns the following information:
handle
—The conversation which triggered the callback (multiple DDE conversations can be
processed by the same callback function).
item name
—The cell(s) involved.
topic name
—The Excel system or file in Excel involved.
transaction type
—Either DDE_DATAREADY or DDE_DISCONNECT.
data format
CF_TEXT in this case.
data size
—Number of bytes in the data.
data pointer
—Pointer to the data.
callback data
—User defined (NULL in this case).