//++++++++++++++++++++++++++++++++++
// +++++ DDERequest for MATLAB 16bit
#include <windows.h>
#include <ddeml.h>
#include <malloc.h> //fuer _memmax()
#define DLLMEX
extern "C"
{
#include "..\header\mex.h"
#include "..\header\testargs.h"
}
#include "..\header\fastdde.h"
#pragma hdrstop
#define ARGS_IN_MIN 2
#define ARGS_IN_MAX 4
#define ARG1_IN prhs[0] //channel
#define ARG2_IN prhs[1] //item
#define ARG3_IN prhs[2] //FormatArray
#define ARG4_IN prhs[3] //timeout
#define ARG1_OUT plhs[0] //Data
/*
// Prototypes
BOOL FastDDEReq( HDDEDATA, Matrix** );
BOOL CFTextStringReq( HDDEDATA, Matrix** );
BOOL CFTextRequest( HDDEDATA, Matrix** );
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////
extern "C" void mexFunction(
int nlhs,
Matrix* plhs[],
int nrhs,
Matrix* prhs[]
)
{
DWORD timeout = TIMEOUT;
WORD cbFormat = CF_TEXT; //default
BOOL isStringMat = FALSE;
if ( TestIOArgs( nrhs, ARGS_IN_MIN, ARGS_IN_MAX ) && //alle erforderlichen Parameter angegeben?
TestChannelArg( ARG1_IN ) && //Channel-Argument ok?
TestItemArg( ARG2_IN ) ) //Item-Argument ok?
{
if ( nrhs >= ARGS_IN_MAX - 1 ) //3. Parameter (Clipboard-Format)?
{
cbFormat = TestFormatArg( ARG3_IN, CHK_STR_FORMAT, &isStringMat );
if ( nrhs == ARGS_IN_MAX ) //4. Parameter (TimeOut)?
timeout = TestTimeoutArg( ARG4_IN );
}
if ( cbFormat != (WORD)-1 && //sind bei ungueltigen Argumenten
timeout != (DWORD)-1 ) // -1
{
DWORD hChannel[2]; //2 mal 32 bit
hmemcpy( (char*)hChannel, (char huge*)mxGetPr(ARG1_IN), sizeof(double) );
DWORD hConv = hChannel[0];
DWORD idInst = hChannel[1];
UINT n = (UINT)mxGetN( ARG2_IN ) + 1;
char* szItem = (char*)mxCalloc( n, sizeof(char) );
if(!szItem)
{
mexPrintf( "??? Memory allocation error.\r\n" );
ErrorBeep();
return;
}
mxGetString( ARG2_IN, szItem, n );
HSZ hszItem = DdeCreateStringHandle( idInst, szItem, CP_WINANSI );
mxFree(szItem);
if ( !hszItem )
{
HandleDdeError(DdeGetLastError(idInst));
return;
}
HDDEDATA hData = DdeClientTransaction( (LPBYTE)NULL, (DWORD)0, hConv, hszItem,
cbFormat, XTYP_REQUEST, timeout, NULL );
if ( !hData )
{
HandleDdeError(DdeGetLastError(idInst));
DdeFreeStringHandle ( idInst, hszItem );
return;
}
if ( isStringMat ) // String Matrix
CFTextStringReq( hData, &ARG1_OUT );
else
{
if ( cbFormat == CF_TEXT ) // CF_TEXT Format
CFTextReq( hData, &ARG1_OUT );
else // Excel Format
FastDDEReq( hData, &ARG1_OUT );
}
DdeFreeDataHandle( hData );
}
}
}
Detected encoding: ASCII (7 bit) | 2
|