Hi All,

I've created a WinDbg extension dll and I'm wondering if there's a way to simplify the construct in MASM syntax.

From the WinDbg help file: Each extension command in a WdbgExts extension DLL is declared using the DECLARE_API macro. This macro is defined in wdbgexts.h.



DECLARE_API( myextension )
{
code for myextension
}

The DECLARE_API macro is defined as follows:

#define DECLARE_API(s) \
CPPMOD VOID \
s( \
HANDLE hCurrentProcess, \
HANDLE hCurrentThread, \
ULONG dwCurrentPc, \
ULONG dwProcessor, \
PCSTR args \
)


I've been able to recreate the C syntax with something like this, which I *think* is correct:

myextension PROTO C :DWORD,:DWORD,:DWORD,:DWORD, :VARARG

myextension PROC C hCurrentProcess:HANDLE, hCurrentThread:HANDLE, dwCurrentPc:DWORD, dwProcessor:DWORD, argVal:VARARG

;blah
ret
myextension ENDP

In WinDbg you would load your extension dll then call your proc with something like:

!myextension arg1,arg2,...


My question is whether there's a way to simplify the MASM proc declaration, rather than listing each parameter for every extension function, is there a way to declare them using a similar C syntax as the DECLARE_API(s) macro.

i.e. can you wrap the PROTO declaration in a macro and use it in your PROC declaration?

Something like?:
myextension PROC DECLARE_API

I believe PROC itself is a macro, so something like this may be possible. So far various attempts/searches have not proved fruitful.

TIA,
Kayaker
Posted on 2004-02-10 02:34:37 by Kayaker
May be something like this if it simplifies something for you :-)



DECLARE_API MACRO s:REQ
s PROTO C :DWORD,:DWORD,:DWORD,:DWORD,:VARARG
ENDM

DEFINE_API MACRO s:REQ
s proc C hCurrentProcess:HANDLE, hCurrentThread:HANDLE, dwCurrentPc:DWORD, dwProcessor:DWORD, args:VARARG
ENDM

DECLARE_API Extension2

.code

Extension PROC C hCurrentProcess:HANDLE, hCurrentThread:HANDLE, dwCurrentPc:DWORD, dwProcessor:DWORD, args:VARARG
invoke Extension2, 0, 0, 0, 0, 0, 0, 0
ret
Extension ENDP

DEFINE_API Extension2
ret
Extension2 ENDP
Posted on 2004-02-10 05:05:40 by Four-F

May be something like this if it simplifies something for you :-)


Yeah, it does actually ;-) Sweet. It seems I was missing the trick of using the :REQ macro reference. I kind of like that syntax for certain instances. Just as another example that I tested, multiple DlgProc's could be declared this way if one wanted:

[size=12]

DECLARE_API MACRO s:REQ
s PROTO :DWORD,:DWORD,:DWORD,:DWORD
ENDM

DEFINE_API MACRO s:REQ
s PROC uses ebx edi esi hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
ENDM

DECLARE_API DlgProc1
DECLARE_API DlgProc2
DECLARE_API DlgProc3

.code
DEFINE_API DlgProc1
...
ret
DlgProc1 endp

DEFINE_API DlgProc2
...
ret
DlgProc2 endp

DEFINE_API DlgProc3
...
ret
DlgProc3 endp
[/size]


Thanks Four-F, it's always a good day when you learn something new :)

Kayaker
Posted on 2004-02-10 17:47:25 by Kayaker