Hi,
First of all I?m new to ASM so be kind with me :tongue:
Well, I was reading some turbo assembler code and MASM code and realized that in turbo assembler if we want to use an API function we make just this:
extrn apifunction:PROC
In MASM we need to include a file and possible any lib.
So, using MASM we not need only to know the name of the API we want(ok, this is the minimum that anyone should know!) but also where it is in a lot of includes and lib files.
So, my question is: after identified an API function, how can I easly know what lib and include files to include in may ASM code?
Thank you!
S?rgio Oliveira
First of all I?m new to ASM so be kind with me :tongue:
Well, I was reading some turbo assembler code and MASM code and realized that in turbo assembler if we want to use an API function we make just this:
extrn apifunction:PROC
In MASM we need to include a file and possible any lib.
So, using MASM we not need only to know the name of the API we want(ok, this is the minimum that anyone should know!) but also where it is in a lot of includes and lib files.
So, my question is: after identified an API function, how can I easly know what lib and include files to include in may ASM code?
Thank you!
S?rgio Oliveira
go to msdn.microsoft.com and search for the api, on the api's page it will tell you which C headers it needs, it's usually a straight translation :)
In MASM we need to include a file and possible any lib.
you need the include file only, if you work with the macros, like "invoke". If you plain call the function, you only define it like in TASM with extrn.
Lib files are always needed, you will have them in TASM too. Since a lib file can contain more than one dll, you might have a "one-in-all.lib" file with all the basic windows dlls, like User32, kernel, gdi, etc.
Hi again,
Beaster, I already tried to do that. For instance, this simple code gives me 2 errors:
.586
.model flat, stdcall
option casemap :none
EXTRN ExitProcess: PROC
EXTRN MessageBoxA: PROC
.data
MsgText db "Hello world!",13,10,0
MsgTitle db "This is a messagebox",0
ErrorCode dd 0
.code
start:
push MB_OK
push offset MsgTitle
push offset MsgText
push 0
call MessageBoxA
push ErrorCode
call ExitProcess
end start
errors:
error lnk2001: unresolved external symbol _exitProcess
error lnk2001: unresolved external symbol _messageBoxA
That is way I had never been able to use "EXTRN"
Thank you
Beaster, I already tried to do that. For instance, this simple code gives me 2 errors:
.586
.model flat, stdcall
option casemap :none
EXTRN ExitProcess: PROC
EXTRN MessageBoxA: PROC
.data
MsgText db "Hello world!",13,10,0
MsgTitle db "This is a messagebox",0
ErrorCode dd 0
.code
start:
push MB_OK
push offset MsgTitle
push offset MsgText
push 0
call MessageBoxA
push ErrorCode
call ExitProcess
end start
errors:
error lnk2001: unresolved external symbol _exitProcess
error lnk2001: unresolved external symbol _messageBoxA
That is way I had never been able to use "EXTRN"
Thank you
Neptuno,
If you have MASM32 version 7, it has a toy to help you with what you are after. its an EXE file called liblist.exe and if you start it and type in the name of the API correctly, it will show you the library that it is in. It has about 11 thousand entries so it will handle almost every case.
All you need to do is then include the library and include file and you have any prototype you need for API calls.
Regards,
hutch@movsd.com
If you have MASM32 version 7, it has a toy to help you with what you are after. its an EXE file called liblist.exe and if you start it and type in the name of the API correctly, it will show you the library that it is in. It has about 11 thousand entries so it will handle almost every case.
All you need to do is then include the library and include file and you have any prototype you need for API calls.
Regards,
hutch@movsd.com
hutch,
That exe have the lib files, but what about the include files? Should I always use a include file with the same name that de lib file?
Thank you
S?rgio Oliveira
That exe have the lib files, but what about the include files? Should I always use a include file with the same name that de lib file?
Thank you
S?rgio Oliveira
neptuno, you'll need to add argument list to the EXTRN definitions,
otherwise masm will not decorate the names. Just use the include
files, it makes life easier.
otherwise masm will not decorate the names. Just use the include
files, it makes life easier.
f0dder,
Are you saying that I need to use the PROTO (something...like this)?
Can I tell me how? just for one of those above? (for instance, to exitProcess).
Thank you
Are you saying that I need to use the PROTO (something...like this)?
Can I tell me how? just for one of those above? (for instance, to exitProcess).
Thank you
It's not too hard, you can reap the protos from the masm32 includes... the
full definition of ExitProcess would be
(adding the STDCALL enables you to use any global calling convention
you want, while still having ExitProcess work).
Another way, included just for fun, would be this:
SYSCALL has same calling convention as STDCALL, but enable you
to use "weirdly named" functions, as it doesn't do any name decoration.
This is for microsoft import libraries, I believe the nasm import libraries
floating around don't have any name decoration.
full definition of ExitProcess would be
ExitProcess PROTO STDCALL :DWORD
(adding the STDCALL enables you to use any global calling convention
you want, while still having ExitProcess work).
Another way, included just for fun, would be this:
_ExitProcess@4 PROTO SYSCALL :DWORD
SYSCALL has same calling convention as STDCALL, but enable you
to use "weirdly named" functions, as it doesn't do any name decoration.
This is for microsoft import libraries, I believe the nasm import libraries
floating around don't have any name decoration.
f0dder,
When you said that to use EXTRN I would need to define "argument list to the EXTRN definitions" I thought you were saying that I would need to define the proto stuff.
Because with EXTRN, even if I use the proto stuff (like you said to exit process) I will not be able to assemble yet :(
Thanks
When you said that to use EXTRN I would need to define "argument list to the EXTRN definitions" I thought you were saying that I would need to define the proto stuff.
Because with EXTRN, even if I use the proto stuff (like you said to exit process) I will not be able to assemble yet :(
Thanks