Hello
Here's a farily simple question. I im using the LoadLibrary/GetModuleHandle/push push call to acess API's in a Dll, is there an easier way to do this using INVOKE?

e.g.


DllExportAPI PROTO :DWORD,:DWORD

.DATA
szDllExportAPI BYTE "DllExportAPI",0

.DATA?
_DllExportAPI DWORD ?
hMod HINSTANCE ?

.CODE
main:

INVOKE LoadLibrary ,ADDR DllName
mov hMod,eax


INVOKE GetProcAddress ,hMod,ADDR szDllExportAPI
mov _DllExportAPI,eax


;Here is a random guess as to how it might be done
;(or might not as this doesn't work :()

INVOKE DllExportAPI PTR _DllExportAPI ,TRUE,FALSE



Something similer to this would be nice for everyone to use as it would get of the push/calls.


Cheers
Posted on 2002-02-03 01:49:55 by huh
I try not to fuss with DLL's (personal tastes), but i did run into simular problems when developing our OOP model.

You are basically using a funciton pointer. And if you wish it to be invokeable you need to provide at proto statement for the "api" within the dll (As your trying to do).

But masm is funny and you can not directly do this in one step. To get it going, you need to have two pointers.

First the proto...
My_DLL_API_Proto TYPEDEF PROTO :DWORD, :BYTE, :WORD

Then the pointer to this..
My_DLL_Ptr TYPEDEF PTR My_DLL_API_Proto

Then in use...
invoke My_DLL_Ptr PTR , Val1, Val2, Val3

This looks messy, and is to some extent, so what we ended up doing is hacking out some creative macro's to make the job look simpler:

Here is one such idea:



DLL_PROTO MACRO AName:Req, args:VARARG
@CatStr( <&AName&_Pto TYPEDEF PROTO >, <args>)
@CatStr( <&AName&_Ptr TYPEDEF PTR >, <&AName&_Pto> )
ENDM

DLL MACRO AName:Req, Rg:Req
EXITM @CatStr( <&AName&_Ptr PTR [>, <&Rg ]> )
ENDM


You could use it as:

DLL_PROTO MyAPI, :DWORD, :DWORD

...
mov eax, lpMyAPI
invoke DLL(MyAPI, eax), True, False


Hmm.. Think i will keep this macro :) I think you get the idea..
Hope this helps..
:alright:
NaN
Posted on 2002-02-03 03:35:26 by NaN