qaqpbann.gif (1572 bytes)

trans.gif (85 bytes)spc-pc-info.gif (340 bytes)

Home
Software
Six Sigma
Certification
Books
Training
Support
Contact
Demos
Knowledge Center
Order Form
Search

Contents | Index

Example C Program (using DDEML)

The following is the text for DEMO.CPP, a Borland C++ 3.0 program that illustrates sending Request, Execute and Poke DDE transactions to the SPC application. It should compile without difficulty under C++ 2.0 and will need minimal rework to compile as a C program under Microsoft C 6.0, etc.

#include <windows.h>

#include <ddeml.h>

BOOL NEAR Execute (HCONV,LPSTR);

BOOL NEAR Request (HCONV,LPSTR,HDDEDATA* =NULL);

BOOL NEAR Poke (HCONV,LPSTR,LPSTR);

DWORD idDDE;

  • oid FAR cdecl dm (LPSTR,...);

HDDEDATA EXPENTRY DdeCallback (WORD,WORD,HCONV,HSZ,HSZ,HDDEDATA,DWORD,DWORD);

#define EXEPATH "c:\\u\\spcwin\\spcwin.exe"

#pragma argsused

int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,

LPSTR lpszCmdLine, int nCmdShow)

{

/* Initialize DDEML:

*/

FARPROC lpfn = MakeProcInstance((FARPROC)DdeCallback,hInstance);

if (DdeInitialize(&idDDE,

(PFNCALLBACK)lpfn,

APPCMD_FILTERINITS, NULL))

{

FreeProcInstance(lpfn);

return 1;

}

/* Create strings:

*/

HSZ hszService = DdeCreateStringHandle(idDDE,"SPCWin",NULL);

HSZ hszTopic = DdeCreateStringHandle(idDDE,"System",NULL);

/* Connect to system topic:

*/

HCONV hConv = DdeConnect(idDDE,hszService,hszTopic,NULL);

if (!hConv)

{

/* No connection - try running program and trying again:

*/

WinExec(EXEPATH,SW_SHOWNORMAL);

hConv = DdeConnect(idDDE,hszService,hszTopic,NULL);

}

if (hConv)

{

/* Connection made to system topic.

*/

dm("");

HDDEDATA hData;

/* Try to create data set using NEW.LIST command:

*/

if (Request(hConv,

"[NEW.LIST(3,25,DATE,D,,,N,COUNT,N,8,0,Y)]",&hData))

{

/* Query sample size (it should be 25.0 as set above):

*/

LPSTR lpsz = (LPSTR)DdeAccessData(hData,NULL);

char sz[201];

wsprintf(sz,"[SET.S.SIZE(\"%s\")]",lpsz);

Request(hConv,sz);

DdeUnaccessData(hData);

DdeFreeDataHandle(hData);

}

/* Disconnect from System topic:

*/

DdeDisconnect(hConv);

}

DdeFreeStringHandle(idDDE,hszTopic);

/* Attempt to connect to existing data set:

*/

hszTopic = DdeCreateStringHandle(idDDE,

"c:\\u\\spcwin\\data\\forddata.dbf",NULL);

hConv = DdeConnect(idDDE,hszService,hszTopic,NULL);

if (hConv)

{

/* Create X-bar and R chart on the " HEIGHT" column:

*/

Execute(hConv,"[NEW.CHART(0,,,\" HEIGHT\")]");

/* Tile windows:

*/

Execute(hConv,"[TILE]");

/* Change a cell's value:

*/

Poke(hConv,"R6C3","20.35");

/* Disconnect from data set topic:

*/

DdeDisconnect(hConv);

}

DdeFreeStringHandle(idDDE,hszTopic);

/* Free strings and deinitialize DDEML:

*/

DdeFreeStringHandle(idDDE,hszService);

DdeUninitialize(idDDE);

FreeProcInstance(lpfn);

return 0;

}

/* Send a Request transaction and print result to debug terminal:

* If phData is passed, return data handle to caller. Otherwise,

* free it.

*/

BOOL NEAR Request (HCONV hConv, LPSTR lpsz, HDDEDATA *phData)

{

HSZ hsz = DdeCreateStringHandle(idDDE,lpsz,NULL);

DWORD dw;

HDDEDATA hData = DdeClientTransaction(NULL,0L,hConv,

hsz,CF_TEXT,

XTYP_REQUEST,1000,&dw);

DdeFreeStringHandle(idDDE,hsz);

if (phData)

*phData = hData;

if (hData)

{

LPSTR lpszR = (LPSTR)DdeAccessData(hData,NULL);

dm("%s - %s",lpsz,lpszR);

DdeUnaccessData(hData);

if (!phData)

DdeFreeDataHandle(hData);

}

else

dm("Request %s - no response",lpsz);

return (hData != NULL);

}

/* Send an Execute transaction.

*/

BOOL NEAR Execute (HCONV hConv, LPSTR lpsz)

{

return (DdeClientTransaction((LPBYTE)lpsz,lstrlen(lpsz)+1,hConv,

NULL,CF_TEXT,

XTYP_EXECUTE,1000,NULL) != 0);

}

/* Send an Poke transaction.

*/

BOOL NEAR Poke (HCONV hConv, LPSTR lpszItem, LPSTR lpszData)

{

HSZ hsz = DdeCreateStringHandle(idDDE,lpszItem,NULL);

BOOL b = (DdeClientTransaction((LPBYTE)lpszData,lstrlen(lpszData)+1,hConv,

hsz,CF_TEXT,

XTYP_POKE,1000,NULL) != 0);

DdeFreeStringHandle(idDDE,hsz);

return b;

}

/* Output debug message.

*/

  • oid FAR cdecl dm (LPSTR lpszFmt,...)

{

char sz[220];

wvsprintf(sz, lpszFmt, (LPSTR)(&lpszFmt + 1));

OutputDebugString(sz);

OutputDebugString("\n\r");

}

/* Callback need not do anything.

*/

#pragma argsused

HDDEDATA EXPENTRY DdeCallback (WORD wType,WORD wFmt,HCONV hConv,HSZ hsz1,

HSZ hsz2,HDDEDATA hData,DWORD lData1,

DWORD lData2)

{

return 0;

}

The MAKEFILE is as follows:

APP = demo

OBJ = $(APP).obj

CL = bcc -WE -mm -c -v -I\usr\binclude

LINK = tlink /Tw -v /c /L\usr\blib c0wm $(OBJ),$(APP).exe,nul,import cwm ddeml;

.cpp.obj:

$(CL) -zC$*_TEXT $*.cpp

$(APP).exe: $(OBJ)

$(LINK)

rc -t $(APP).exe

obj: $(OBJ)

$(APP).obj: $(APP).cpp


Site Map | Privacy | About Us

Copyright © 1995-1999 Quality America Inc. All Rights Reserved