News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

ddeml and excel

Started by czerny, March 24, 2013, 10:44:53 PM

Previous topic - Next topic

czerny

Hallo,

I have tried a ddeml example from MS. But it didn't work. Excel starts, the connection to the dde-server is ok, but I can not get further.
Can anybody have a look?

czerny

jj2007

I can make Excel (and WinWord) execute commands using DdeClientTransaction:

   Let esi='[OPEN("test_dde.xls")]'
   void Len(esi)
   inc eax   ; string len including zero delimiter
   invoke DdeClientTransaction, esi, eax, ebx, 0, 0, XTYP_EXECUTE, 10000, 0

Apologies that it's assembler - I hope the idea is clear... and it works just fine.

laurro

The problem is with the file test.xls. Should be created before being used.
Something like this:


char szTopic[] = "Test.xls"; // provide an excel file with entrys in A1 and A2
.
.
FILE *xls_file = fopen(szTopic,"w");
fclose(xls_file);

HINSTANCE hRet = ShellExecute(0, "open", szTopic, 0, 0, SW_SHOWNORMAL);
.
.


Laur

czerny

Quote from: laurro on March 25, 2013, 09:54:00 AM
The problem is with the file test.xls. Should be created before being used.

This is self-evident!
Can you read A1 and A2?

czerny

jj2007

For me, the ShellExecute part works, i.e. a testfile gets opened, but the subsequent connect fails:
        hszApp = DdeCreateStringHandle(idInst, szApp, 0);
        hszTopic = DdeCreateStringHandle(idInst, szTopic, 0);
        hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
        DdeFreeStringHandle(idInst, hszApp);
        DdeFreeStringHandle(idInst, hszTopic);
        if (hConv == NULL)
        {
            printf("DDE Connection Failed.\n");
         printf("Paras: idInst=%i\nhszApp=%p\nhszTopic=%p\n", idInst, hszApp, hszTopic);
            Sleep(1500); DdeUninitialize(idInst);
            return 0;
        }

DDE Connection Failed.
Paras: idInst=16777344
hszApp=0000c000
hszTopic=0000c001

hszApp and hszTopic look like valid handles.

However, when I change the second line to ...
        hszTopic = DdeCreateStringHandle(idInst, "System", 0);
... the connection stands.

laurro

Quote from: czerny on March 25, 2013, 11:35:39 AM
Quote from: laurro on March 25, 2013, 09:54:00 AM
The problem is with the file test.xls. Should be created before being used.

This is self-evident!
Can you read A1 and A2?

czerny
Quote from: czerny on March 25, 2013, 11:35:39 AM
Quote from: laurro on March 25, 2013, 09:54:00 AM
The problem is with the file test.xls. Should be created before being used.

This is self-evident!
Can you read A1 and A2?

czerny

No is not and yes I can, see attachment.
Mainly look at main().

Laur

TimoVJL

#6
Please tell us Excel version too.
That example works with Excel version 2003, but not with 2010 ?

http://support.microsoft.com/kb/279721

EDIT. Windows 7 x64, 32-bit MS Office Home and Student 2010
May the source be with you

laurro

Hi timo

Indeed I use 2003 and I was not aware of the differences between versions.
I'm sorry I can not be more helpful.

Laur

jj2007

It works with Excel 2010.

czerny

For me it doesn't work neither with 2000 nor 2003. I do not think that it is a version problem.

czerny

Quote from: laurro on March 25, 2013, 02:19:21 PM
No is not and yes I can, see attachment.
Mainly look at main().
This example creates an empty new file 'test.xls', establishes the dde-connection and not more.

jj2007

Hi Czerny,

Your original C source posted above works fine, provided the file test.xls is available in the specified location.

TimoVJL

#12
@czerny
It is a Office language problem.
"R1C1" is for english version.
May the source be with you

czerny

Quote from: timovjl on March 26, 2013, 08:29:00 AM
@czerny
It is a Office language problem.
"R1C1" is for english version.
Puuh! Unbelievable!
Thank you timovjl!