When creating a DLL file, you can add the 'export' keyword to your proc's. The assembler will add information to the .OBJ file indicating that the function should be exported eliminating the need for a .DEF file.


Myproc proc export ...
...
ret
Myproc endp

To convert existing source code just get in your favorite editor and do a global replace 'proc' with 'proc export'. Then build as usual without the /DEF:MYPROG.DEF switch in the link command.

ml myprog.asm ...
link /dll myprog.obj ...
Posted on 2003-12-20 12:28:57 by gfalen
Tried it and it does not properly export the function, GetProcAddress returns 0.
Posted on 2003-12-20 12:37:02 by donkey
I don't quite understand. GetProcAddress is an api function which would be 'imported' in any dll you would create. If you mean passing this import along in YOUR dll as an export, yes this method can't do that since it can only export "procedures in the source file" which have the 'export' keyword.

If you create a source file with a line like this:


GetProcAddress proc hModule, lpProcName
jmp _imp__GetProcAddress@8
GetProcAddress endp


my method will export the synbol 'GetProcAddress' which will appear in the
.LIB file generated.
Posted on 2003-12-20 12:47:52 by gfalen
I create a DLL, I use LoadLibrary to load the DLL in my main program, I attempt to get a pointer to the function using GetProcAddress and it returns 0, the proc was not found.


MAIN PROGRAM


invoke LoadLibrary,OFFSET DllName
mov hHookDll,eax [color=red]DLL is loaded properly[/color]
invoke GetProcAddress,hHookDll,OFFSET szInstallHook
mov pInstallHook,eax [color=red]Returns 0[/color]
invoke GetProcAddress,hHookDll,OFFSET szUnInstallHook
mov pUnInstallHook,eax [color=red]Returns 0[/color]


DLL


InstallHook proc export hWin:DWORD

mov eax,hWin
mov hToolBar,eax

invoke SetWindowsHookEx,WH_MSGFILTER,OFFSET MsgHook,hInstance,0

mov hHook,eax
ret

InstallHook endp

UnInstallHook proc export

invoke UnhookWindowsHookEx,hHook
mov hHook,NULL
ret

UnInstallHook endp
Posted on 2003-12-20 13:01:02 by donkey
Ok, you have to use the decorated names then it works fine:

szInstallHook		db '_InstallHook@4',0

szUnInstallHook db '_UnInstallHook@0',0
Posted on 2003-12-20 13:14:34 by donkey
.def files are not unnecessary. they have their uses. you can create aliases for function names exported using "export" using .def files and also specify the ordinals for functions in dlls.

hey donkey,

looks like you're still in the 1980s....hehe.
Posted on 2003-12-20 13:19:48 by evil__donkey
...But you can build the dll w/o them which is what i asserted in my first post.
Posted on 2003-12-20 13:22:33 by gfalen
No evil donkey,

I use a different assembler & linker for some of my apps so I don't use decorated names, they are just a pain in the ass and are the next best thing to pointless. I live in the assembler world, decorated names are a relic of C.
Posted on 2003-12-20 13:24:30 by donkey
i wasn't referring to where you live, but to the number of your posts.
Posted on 2003-12-20 13:26:40 by evil__donkey
How do you get around decorated names when using masm?
Posted on 2003-12-20 13:26:54 by gfalen

How do you get around decorated names when using masm?

Use a DEF file :)
Posted on 2003-12-20 13:27:41 by donkey
When creating your own dll's - yes. But to use the masm lib's....
Posted on 2003-12-20 13:29:10 by gfalen
yeah create an alias in the def file like this

for a function called FooFunction

FooFunction PROTO :DWORD, :DWORD

FooFunction PROC export abd:DWORD, bcd:DWORD
;; foo
ret
FooFunction endp

in the def file

FooFunction=_FooFunction@8
Posted on 2003-12-20 13:30:17 by evil__donkey

i wasn't referring to where you live, but to the number of your posts.

Sorry, I though that you were saying I am using an outdated method to build my DLL's, there is a reason for it. I'm trying to get to the 90's as quick as possible :)
Posted on 2003-12-20 13:30:32 by donkey

When creating your own dll's - yes. But to use the masm lib's....

I use GoAsm more than masm, I don't need libraries for Windows functions :)
Posted on 2003-12-20 13:31:40 by donkey
what's this supposed to mean donkey?

This would, with a little creative programming (maybe just a fancy batch file), make linking dlls directly (like GoLink does) possible with MS Link.


it's here

http://www.asmcommunity.net/board/index.php?topic=13805
Posted on 2003-12-20 13:41:32 by evil__donkey
If I put the DLL in the same folder as GoAsm and include the name of the DLL in GFL.TXT I can call the functions in that DLL without having to do anything to load it, GoLink will find the function and insert the necessary code. However for the most part I only use DLL's for delay loading or hooks, by only loading the DLL when necessary I can significantly reduce the memory footprint, for hooks there are only two functions so it doesn't do much. GoLink is by far the best linker made, no libs, imports automatically from any DLL. If you want a static lib function in GoAsm you call it this, the code will be inserted into your object file:

invoke masm32.lib:dw2a,eax,addr buffer
Posted on 2003-12-20 14:09:41 by donkey
I did much the same testing as Greg did some time ago and you can get a DLL to work using the EXPORT directive in MASM but as it has been mentioned, you must use the decorated name to do it which is not all that convenient.

There are a few tricks though using DEF files that are useful enough. Fill the DEF file with the names of the procedures in a library, write a bare LibMain and make sure you include the library name and voila, you get a DLL full of library functions.

You can also do it with API functions.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-12-20 17:27:33 by hutch--