NO

Author Topic: ddeml and excel  (Read 9808 times)

czerny

  • Guest
ddeml and excel
« on: March 24, 2013, 10:44:53 PM »
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

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: ddeml and excel
« Reply #1 on: March 25, 2013, 12:59:30 AM »
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

  • Guest
Re: ddeml and excel
« Reply #2 on: March 25, 2013, 09:54:00 AM »
The problem is with the file test.xls. Should be created before being used.
Something like this:

Code: [Select]
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

  • Guest
Re: ddeml and excel
« Reply #3 on: March 25, 2013, 11:35:39 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

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: ddeml and excel
« Reply #4 on: March 25, 2013, 12:01:24 PM »
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

  • Guest
Re: ddeml and excel
« Reply #5 on: March 25, 2013, 02:19:21 PM »
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
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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: ddeml and excel
« Reply #6 on: March 25, 2013, 02:39:42 PM »
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
« Last Edit: March 25, 2013, 05:44:37 PM by timovjl »
May the source be with you

laurro

  • Guest
Re: ddeml and excel
« Reply #7 on: March 25, 2013, 03:04:38 PM »
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

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: ddeml and excel
« Reply #8 on: March 25, 2013, 03:29:35 PM »
It works with Excel 2010.

czerny

  • Guest
Re: ddeml and excel
« Reply #9 on: March 25, 2013, 08:36:25 PM »
For me it doesn't work neither with 2000 nor 2003. I do not think that it is a version problem.

czerny

  • Guest
Re: ddeml and excel
« Reply #10 on: March 25, 2013, 08:55:06 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.

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: ddeml and excel
« Reply #11 on: March 26, 2013, 12:02:57 AM »
Hi Czerny,

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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: ddeml and excel
« Reply #12 on: March 26, 2013, 08:29:00 AM »
@czerny
It is a Office language problem.
"R1C1" is for english version.
« Last Edit: March 26, 2013, 11:43:10 PM by timovjl »
May the source be with you

czerny

  • Guest
Re: ddeml and excel
« Reply #13 on: March 26, 2013, 10:22:04 AM »
@czerny
It is a Office language problem.
"R1C1" is for english version.
Puuh! Unbelievable!
Thank you timovjl!