Hi All.
Waiting for some help, I downloaded the free Visual studio 2010 C++ express and spent a morning getting some basics on C++.
I managed to make a console application that fire DDEexecute with parameters but I am rather confused on what does what...!
Coming from LiveCode, C++ is very cumbersome and I am not sure if I was able to handle correctly all those string conversions. What it does is it opens the console, ask for the name of the application, the topic (for excel is the doc name) and send to it a DDEexecute with the parameters listed on the szCmd1[] string.
1- download Visual Studio C++ express 2010
2 make a new console project and name it DDClient3 (It's my third experiment...)
3- if, like me, you must handle accented chars, you must set the character set (on the DDClient property) to multibyte. I tried with Unicode, but i could not come up of al the mess in the string handling.
4- replace the content of the DDClient3.cpp with the following code:
Code: Select all
// Ask for application and topic and send a DDEexecute to it
//the DDE is the szCmd1
//
#include "stdafx.h"
#include "windows.h"
#include "ddeml.h"
#include "stdio.h"
#include <string>
#include <iostream>
using namespace std;
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;
}
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) {
printf("Command failed: %s\n", szCommand);
}
else {
DdeClientTransaction((LPBYTE)hData, 0xFFFFFFFF, hConv, 0L, 0,
XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
}
}
int main(int argc, char* argv[])
{
char myapp[30];
char mytopic[80];
cout << "App name:";
cin >> myapp;
cout << "Topic name:";
cin >> mytopic;
//parameters to send (no backslash...)
char szCmd1[] = "S;C:/archiviMida4/O01820110701.MDB;;C:/CC_SaniMont_DB2012/IOMidaDbFornitura/RisultatoMida.txt;C:/CC_SaniMont_DB2012/IOMidaDbFornitura/EsitoMida.txt;2646_clienteCodice;1014";
//DDE Initialization
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
if (iReturn!=DMLERR_NO_ERROR)
{
printf("DDE Initialization Failed: 0x%04x\n", iReturn);
Sleep(1500);
return 0;
}
////Start DDE Server and wait for it to become idle.
//HINSTANCE hRet = ShellExecute(0, L"open", szTopic, 0, 0, SW_SHOWNORMAL);
//if ((int)hRet < 33)
//{
// printf("Unable to Start DDE Server: 0x%04x\n", hRet);
// Sleep(1500); DdeUninitialize(idInst);
// return 0;
//}
//Sleep(1000);
//DDE Connect to Server using given AppName and topic.
HSZ hszApp, hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandle(idInst, myapp, 0);
hszTopic = DdeCreateStringHandle(idInst, mytopic, 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
printf("DDE Connection Failed.\n");
Sleep(1500); DdeUninitialize(idInst);
return 0;
}
//Execute commands/requests specific to the DDE Server.
DDEExecute(idInst, hConv, szCmd1); //send the DDE
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
Sleep(3000);
return 1;
}
Note that I'm not sure if it handles accented chars on the parameters to send. You cannot but backslash also on the parameters, since C++ considers the backslash as a special char, even inside quotes.
NOW, I only need to understand how to transform those input (TheApp, TheTopic, TheParameters) so as to be able to build an external for LiveCode...

Please help.
LONG LIFE TO LIVECODE.
Trevix