I am looking into japheth Excel Automation sample. I have change some and at the same time coded the same in VB. Now I have VB and masm doing the same thing and I understand what masm is doing. Masm is working because of japheth's work. The problem arises when I want to do something else. For example when adding a new book japheth has following code.
mov var1.vt,VT_ERROR

mov var1.scode,DISP_E_PARAMNOTFOUND
invoke vf(pWorkbooks,Workbooks,Add_),var1,0,addr pWorkbook

This opens a new book. But how should I know that it is "scode" variant I should use and how do I know that it is just "DISP_E_PARAMNOTFOUND" among 15 other DISP_E_ equ to use.

And how do I find the right methods, propreties and so on among all 18000 rows in the excel.inc file. For example I have spent several hours to try to open an existing workbook. Still I haven't succeeded. The names in excel.inc are not equal to the names in VB object browser.

This is excel.inc for Add
STDMETHOD Add_ , :VARIANT,:SDWORD,:ptr ptr Workbook

This is excel.inc for Open
STDMETHOD Open , :BSTR,:VARIANT,:VARIANT,:VARIANT,:VARIANT,
:VARIANT,:VARIANT,:VARIANT,:VARIANT,:VARIANT,:VARIANT,:VARIANT,:VARIANT,
:SDWORD,:ptr ptr Workbook

What do I put in all these VARIANTs?

Can somebody tip me how I should approach the problem.
Posted on 2004-03-25 08:43:11 by minor28
This VB code open my workbook
Set pWorkbook = pWorkbooks.Open("c:\projects\masm\projects_com\excel\bok1.xls")

But how on earth do I open it in masm. This is my latest attempt.
.data

szWorkbook db "c:\projects\masm\projects_com\excel\bok1.xls",0
.code
mov var1.vt,VT_UINT
mov var1.uintVal,0
mov var2.vt,VT_BOOL
mov var2.boolVal,FALSE
mov var3.vt,VT_UINT
mov var3.uintVal,1
mov var4.vt,VT_BSTR
mov var4.bstrVal,0
mov var5.vt,VT_BOOL
mov var5.boolVal,TRUE
mov var6.vt,VT_DISPATCH
mov var6.pdispVal,xlWindows
mov var7.vt,VT_UNKNOWN
mov var7.punkVal,0
invoke MultiByteToWideChar,CP_ACP,0,addr szWorkbook,-1,addr lpWideCharStr,\
sizeof lpWideCharStr
invoke vf(pWorkbooks,Workbooks,Open),addr lpWideCharStr,var1,var2,var3,var4,\
var4,var5,var6,var7,var5,\
var5,var7,var2,\
0,addr pWorkbook

Excel.inc file:
;STDMETHOD Open , :BSTR,:VARIANT,:VARIANT,:VARIANT,:VARIANT,
; :VARIANT,:VARIANT,:VARIANT,:VARIANT,
; :VARIANT,:VARIANT,:VARIANT,:VARIANT,
; :SDWORD,:ptr ptr Workbook

VB object browser:
;Function Open(Filename As String, [UpdateLinks], [ReadOnly], [Format], [Password],
; [WriteResPassword], [IgnoreReadOnlyRecommended], [Origin], [Delimiter],
; [Editable],[Notify], [Converter], [AddToMru])
; As Workbook


All variants are optional. It should do with one variant for all parameters. But how? Do someone know?
Posted on 2004-03-25 11:41:47 by minor28
Hi minor28,

> All variants are optional. It should do with one variant for all parameters. But how? Do someone know?

Telling that a parameter is "not there" is done with:

> mov var1.vt,VT_ERROR
> mov var1.scode,DISP_E_PARAMNOTFOUND

as I've done it when calling the "Add" method. Thats described somewhere in ole automation docs.

BTW: there exists a COM forum for such questions. As I am concerned I tend to ignore the OOP forum a bit.

Japheth
Posted on 2004-03-26 00:31:42 by japheth
Thanks japheth,

I am sorry I started in wrong section. Future problems will be posted at COM section.

As a matter of fact the VT_ERROR variant was my first try. I have spent several of hours trying different combinations and none is working. This is the steps I am doing.
invoke GetAppPtr,pUnknown

mov pApp,eax
invoke vf(pApp,_Application,get_Workbooks),addr pWorkbooks
mov var1.vt,VT_ERROR
mov var1.scode,DISP_E_PARAMNOTFOUND

;Alternative 1: WORKING
invoke vf(pWorkbooks,Workbooks,Add_),var1,0,addr pWorkbook

;Alternative 2: NOT WORKING
.data
szWorkbook db "c:\projects\masm\excel\bok1.xls",0
.code
invoke MultiByteToWideChar,CP_ACP,0,addr szWorkbook,-1,addr lpWideCharStr,\
sizeof lpWideCharStr ;=>lpWideCharStr = c.:.\.p.r.o.j.e.c.t.s.\.m.a.s.m.\.e.x.c.e.l.\.b.o.k.1...x.l.s.

invoke vf(pWorkbooks,Workbooks,Open),addr lpWideCharStr,var1,var1,var1,var1,\
var1,var1,var1,var1,var1,var1,var1,var1,0,addr pWorkbook
;Error: if Filename = szWorkbook => E_OUTOFMEMORY (8007000C)
; if Filename = lpWideCharStr => STATUS_ACCESS_VIOLATION (C0000005)

Alternative 1, the Add method is working but not Alternative 2, the Open method. I can't figure it out what's wrong. Any id?as?
Posted on 2004-03-26 03:17:58 by minor28
Usually the automation objects want strings as BSTR, not just as "wide" strings. BSTRs are dynamically allocated with function SysAllocString, look for more details there.

Japheth
Posted on 2004-03-26 06:28:26 by japheth
Thanks japheth,

SysAllocString was the probleme. Now I can open my workbook.
Posted on 2004-03-26 09:52:16 by minor28