ProMiNick
Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
|
minimal context of problem:
my interface realization:
macro interface definition
{
match name tail, definition: \{
virtual
db \`name
load initial@struct byte from $$
if initial@struct = '.'
display 'Error: name of interface should not begin with a dot.',0Dh,0Ah
err
end if
end virtual
macro endi \\{
if $
display 'Error: definition of ',\`name,' contains illegal instructions.',0Dh,0Ah
err
end if
match =@guid,@guid \\\{
display 'Error: missing GUID in definition of ',\`name,0Dh,0Ah
err \\\}
restruc stdmethod
purge endi
irpv methods,method@vtbl \\\{
restore method@vtbl
\\\common
;define methods@vtbl methods
define@vtbl name,methods
define methods@\#name methods \\\}
IID_\#name equ @guid
restore @vtbl, @guid
;define@vtbl methods@vtbl
;match methods,methods@vtbl \\\{ \\\}
end virtual \\}
;match :,tail \\{ \\}
match =extends parent:, tail \\{ method@vtbl equ methods@\\#parent \\} \}
struc stdmethod args& \{ define method@vtbl . \}
macro GUID ID& \{ define @guid ID
purge GUID \}
define @vtbl
virtual at 0 }
macro define@vtbl name,[method]
{
match no, @vtbl \{
disply 'Error: define@vtbl is used outside of interface definition.',0Dh,0Ah
err \}
name#.#method PTR ?
local value
common
name#.com.interface = $ / sizeof.PTR
restruc name
struc name vtbl:? \{
common
. PTR vtbl
virtual at 0
forward
.#method PTR ?
common
.\#.com.object = name#.com.interface
end virtual
\}
restruc name#vtbl
struc name#vtbl value \{ \local \..base
label \..base
forward
.#method PTR value
common
label . at \..base
\}
}
macro comobject name ; in current moment this is just a syntax for declaring CLSID_, but it will be functionaly extended in future
{
virtual
db `name
load initial@struct byte from $$
if initial@struct = '.'
display 'Error: name of com object should not begin with a dot.',0Dh,0Ah
err
end if
end virtual
macro endo \{
if $
display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah
err
end if
match =@guid,@guid \\{
display 'Error: missing GUID in definition of ',`name,0Dh,0Ah
err \\}
restruc stdmethod
purge endo
CLSID_#name equ @guid
restore @vtbl, @guid
end virtual \}
macro CLSID ID& \{ define @guid ID
purge CLSID \}
define @vtbl
virtual at 0 }
one of examples:
; Component Object Model usage demonstration
format PE GUI 4.0
entry start
include 'win32a.inc'
;include 'generic/macro/guid.inc'
;include 'os specific/windows/interfaces/shell.inc'
;include 'os specific/windows/equates/com.inc'
ID_EXIT = IDCANCEL
ID_SHOW = 100
ID_HIDE = 101
IDD_COMDEMO = 1
section '.text' code readable executable
start:
invoke CoInitialize,NULL
invoke CoCreateInstance,lpCLSID_TaskbarList,NULL,CLSCTX_INPROC_SERVER,lpIID_ITaskbarList,ShellTaskBar
invoke GetModuleHandle,0
invoke DialogBoxParam,eax,IDD_COMDEMO,HWND_DESKTOP,COMDemo,0
cominvk ShellTaskBar,Release
invoke ExitProcess,0
proc COMDemo hwnd,msg,wparam,lparam
push ebx esi edi
cmp [msg],WM_INITDIALOG
je .wminitdialog
cmp [msg],WM_COMMAND
je .wmcommand
cmp [msg],WM_CLOSE
je .wmclose
xor eax,eax
jmp .finish
.wminitdialog:
jmp .processed
.wmcommand:
cmp [wparam],BN_CLICKED shl 16 + ID_EXIT
je .wmclose
cmp [wparam],BN_CLICKED shl 16 + ID_SHOW
je .show
cmp [wparam],BN_CLICKED shl 16 + ID_HIDE
jne .processed
.hide:
cominvk ShellTaskBar,HrInit
cominvk ShellTaskBar,DeleteTab,[hwnd]
jmp .processed
.show:
mov ebx,[ShellTaskBar]
comcall ebx,ITaskBarList,HrInit
comcall ebx,ITaskBarList,AddTab,[hwnd]
comcall ebx,ITaskBarList,ActivateTab,[hwnd]
jmp .processed
.wmclose:
invoke EndDialog,[hwnd],0
.processed:
mov eax,1
.finish:
pop edi esi ebx
ret
endp
section '.data' data readable writeable
lpCLSID_TaskbarList GUID CLSID_TaskbarList;56FDF344-FD6D-11D0-958A-006097C9A090
lpIID_ITaskbarList GUID IID_ITaskbarList;56FDF342-FD6D-11D0-958A-006097C9A090
ShellTaskBar ITaskbarList
section '.idata' import data readable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
ole,'OLE32.DLL'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'
import user,\
DialogBoxParam,'DialogBoxParamA',\
EndDialog,'EndDialog'
import ole,\
CoInitialize,'CoInitialize',\
CoCreateInstance,'CoCreateInstance'
section '.rsrc' resource data readable
directory RT_DIALOG,dialogs
resource dialogs,\
IDD_COMDEMO,LANG_ENGLISH+SUBLANG_DEFAULT,comdemo
dialog comdemo,'Taskbar item control',70,70,170,24,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
dialogitem 'BUTTON','Show',ID_SHOW,4,4,45,15,WS_VISIBLE+WS_TABSTOP
dialogitem 'BUTTON','Hide',ID_HIDE,54,4,45,15,WS_VISIBLE+WS_TABSTOP
dialogitem 'BUTTON','Exit',ID_EXIT,120,4,45,15,WS_VISIBLE+WS_TABSTOP
enddialog
Error: assertion failed.
USECOM.ASM [29] cominvk ShellTaskBar,Release
COM32.INC [11] assert defined ShellTaskBar.com.object
At first sight on macro define@vtbl - line ".\#.com.object = name#.com.interface" should define ShellTaskBar.com.object.
ITaskbarList defined this way:
interface ITaskbarList extends IUnknown
GUID 56FDF342-FD6D-11D0-958A-006097C9A090
HrInit stdmethod(ITaskbarList *THIS):HRESULT
AddTab stdmethod(ITaskbarList *THIS, HWND hwnd):HRESULT
DeleteTab stdmethod(ITaskbarList *THIS, HWND hwnd):HRESULT
ActivateTab stdmethod(ITaskbarList *THIS, HWND hwnd):HRESULT
SetActiveAlt stdmethod(ITaskbarList *THIS, HWND hwnd):HRESULT
endi
and TaskbarList defined this way (CLSID I mean):
comobject TaskbarList
CLSID 56FDF344-FD6D-11D0-958A-006097C9A090
endo
_________________ I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Last edited by ProMiNick on 04 Jul 2019, 16:48; edited 2 times in total
|