Serving the Quantitative Finance Community

 
User avatar
futurenets
Topic Author
Posts: 0
Joined: October 12th, 2002, 3:25 pm

DDE

December 30th, 2002, 4:36 pm

Does anyone have any C++ code that I could experiment with as a DLL function for simply setting an Excel cell to a given value/text using DDE (not automation)?e.g. Workbook1 Worksheet1 Cell A1 = "YES"
 
User avatar
jens
Posts: 0
Joined: July 14th, 2002, 3:00 am

DDE

December 30th, 2002, 4:47 pm

Appendix A of the Excel developer's kit has information on DDE, but i have never used it and probably never will Jens.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

DDE

January 1st, 2003, 5:06 pm

Why DDE ?Is is more horrible than a horrible thing on a horrible day that is professor of horrible at London university.I've have some really much more friendly COM code.
 
User avatar
AVt
Posts: 90
Joined: December 29th, 2001, 8:23 pm

DDE

January 2nd, 2003, 10:26 pm

Dominic - do you mind to post an example?
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

DDE

January 3rd, 2003, 7:56 am

void main(){ using namespace Excel; _ApplicationPtr pXL; try { pXL.CreateInstance(L"Excel.Application.9"); pXL->Visible = VARIANT_TRUE; WorkbooksPtr pBooks = pXL->Workbooks; _WorkbookPtr pBook = pBooks->Open("c:\\wilmex\\DomSheet.xls"); double q=42; pXL->Range["Sheet2!A1"]->Value2=q; pXL->Save(); } catch(_com_error &e) { dump_com_error(e); }}This shouldn't be too hard to follow, once you've navigated to the interface, you've got the object model for Excel that you will recognise from VBA.The less intuitive bit is conning VC++ to pick up the library.At the top of the file, you need to put someting like#import <mso9.dll> no_namespace rename("DocumentProperties", "DocumentPropertiesXL") #import "C:\Program Files\Common Files\Microsoft Shared\VBA\vbeext1.olb" no_namespace #import <excel9.olb> rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfacesThe paths given here may not work on your machine, in particular mso9.dll may not be on your machine at all. Scan for MSO*.dll, and pick the one with the highest number.The final #import is a fudge I picked up somewhere, to get around the way Excel functions clash with Win32 ones.Contact me directly if you want the project.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

DDE

January 3rd, 2003, 12:48 pm

Ok, try again, here is this project, be prepared to fix the #import lines for your local machine.
 
User avatar
futurenets
Topic Author
Posts: 0
Joined: October 12th, 2002, 3:25 pm

DDE

January 3rd, 2003, 3:18 pm

DominicYour method looks great and much cleaner but I can't get it to compile. Also I need to create this as a DLL. I'm using Excel 2002 but don't have the mso9.dll, vbeext1.olb or excel9.olb installed on my machine. Where are they on yours?PW
 
User avatar
jens
Posts: 0
Joined: July 14th, 2002, 3:00 am

DDE

January 3rd, 2003, 3:26 pm

You probably need to look for mso10.dll or mso11.dll, which is usually (Office 2000) inProgram Files\Microsoft Office\OfficeAnother tip: I usually write (and test) Excel COM stuff in VBA, and use the VB2VC converter to generate the corresponding C++ code later.Jens.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

DDE

January 6th, 2003, 9:27 am

Jens is of course correct, alas the MSO DLLs are copyright, and I didn't want to upload them hereabouts.Some scripted builds can cause real headaches here.