This is the C++ code:
Code: Select all
//Make DLL to send DDEexecute from LiveCode
// Generated by External Creator V1.00
// For language: C++ (no exceptions, no rtti)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <C:\Documents and Settings\3vix\Build LC external\ExternalsEnvironmentV3\libexternal\src\external.h>
//#include "stdafx.h"
#include "windows.h"
#include "ddeml.h"
#include "stdio.h"
#include <string>
#include <iostream>
using namespace std;
////////Roba di DDE///////////////////////////////////////////////////////////////////////
HDDEDATA CALLBACK DdeCallback(
UINT uType, // Transaction type.
UINT uFmt, // Clipboard data format.
HCONV hconv, // Handle to the conversation.
HSZ hsz1, // Handle to a string.
HSZ hsz2, // Handle to a string.
HDDEDATA hdata, // Handle to a global memory object.
DWORD dwData1, // Transaction-specific data.
DWORD dwData2) // Transaction-specific data.
{
return 0;
}
char *risultato = "0";
void DDEExecute(DWORD idInst, HCONV hConv, char* szCommand)
{
HDDEDATA hData = DdeCreateDataHandle(idInst, (LPBYTE)szCommand,
lstrlen(szCommand) +1, 0, NULL, CF_TEXT, 0);
if (hData==NULL) {
risultato = "Parametri di comando errati!";
return;
}
else {
DdeClientTransaction((LPBYTE)hData, 0xFFFFFFFF, hConv, 0L, 0,
XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
}
}
void GetDDEready(char* TheApp, char* TheTopic, char* TheVar) //prepare connection DDE
{
//char myapp[] = "IOMidaDB";
//char mytopic[] = "IOM4";
//richiesta dati per ID
//char szCmd1[] = "S;C:/archiviMida4/O01820110701.MDB;;C:/CC_SaniMont_DB2012/IOMidaDbFornitura/RisultatoMida.txt;C:/CC_SaniMont_DB2012/IOMidaDbFornitura/EsitoMida.txt;2646_ClienteCodice;10";
//char szCmd1[] = p_arguments[2];
//DDE Initialization
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
if (iReturn!=DMLERR_NO_ERROR)
{
risultato = "Inizializzazione DDE fallita !";
return;
}
//DDE Connect to Server using given AppName and topic.
HSZ hszApp, hszTopic;
HCONV hConv;
//hszApp = DdeCreateStringHandle(idInst, myapp, 0);
//hszTopic = DdeCreateStringHandle(idInst, mytopic, 0);
hszApp = DdeCreateStringHandle(idInst, TheApp, 0);
hszTopic = DdeCreateStringHandle(idInst, TheTopic, 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
risultato = "Connessione DDE fallita !";
return;
}
//Execute commands/requests specific to the DDE Server.
DDEExecute(idInst, hConv, TheVar); //send the DDE
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
}
void runDDEexecute(char *p_arguments[], int p_argument_count,
char **r_result, Bool *r_pass, Bool *r_err)
//void rnaHelloUser(char *p_arguments[], int p_argument_count,
//char **r_result, Bool *r_pass, Bool *r_err)
{
// First check we have been passed a single argument ñ if not itís an error
//
if (p_argument_count != 3)
{
*r_result = strdup("Wrong number of parameters");
*r_err = True;
*r_pass = False;
return;
}
GetDDEready(p_arguments[0],p_arguments[1],p_arguments[2]); //get connection
// Next compute the length of our required string
unsigned int t_buffer_length;
char *t_buffer;
p_arguments[0]= risultato;
t_buffer_length = strlen(p_arguments[0]) + 1;
t_buffer = (char *)malloc(t_buffer_length);
if (t_buffer == NULL)
{
*r_result = strdup("out of memory");
*r_err = True;
*r_pass = False;
return;
}
// We have allocated our buffer ñ so now construct our string
sprintf(t_buffer, "%s", p_arguments[0]);
// t_buffer now contains a pointer to the result so just return...
*r_result = t_buffer;
*r_err = False;
*r_pass = False;
risultato = "0";
}
// END USER DEFINITIONS
EXTERNAL_BEGIN_DECLARATIONS("runDDE")
//EXTERNAL_BEGIN_DECLARATIONS("rnahello")
// BEGIN USER DECLARATIONS
EXTERNAL_DECLARE_FUNCTION("runddeexecute", runDDEexecute)
// END USER DECLARATIONS
EXTERNAL_END_DECLARATIONS
If you create for example a Excel file named "C:/Test.xls", you open it and from LiveCode you send a runDDEexecute("Excel","C:/Test.xls","convid,'[close(false)]'") function (return 0 if correctly executed),...voilà: Excel close the doc!
Now...I have 2 problems:
1 - For my needs, the DDEexecute get sent from LC to an application that write something to disk (a text file). How can I have LC to wait until the file get written ? I believe that a recursive "get URL" doesn't make sense...uh?
2 - LiveCode 4.6.4: if I do a "put the externalPackages", I don't get anything. Not even the default externals.
If you need the dll, you can download it here:
http://www.managementcalendar.com/Downl ... addll.html
Trevix