News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How do we find out which function comes from which library?

Started by amrak, May 14, 2015, 12:38:33 PM

Previous topic - Next topic

amrak

Hello once again! Is there a way to find out which function comes from which library in MASM? As an example in the following code (Code comes from the tutorials folder in masm32 ..C:\masm32\tutorial\console\demo2\proc.asm) it includes several libraries
include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

And there is one function call (I believe print char$ is a function call, please correct me if I got this wrong)

main proc

    print chr$("Hi, I am in the 'main' procedure",13,10)

    ret                         ; return to the next instruction after "call"

main endp

How do we find out where print char is defined at from those several included files.

dedndave

first, "print" and "chr$" are masm32 macros
they are defined in \masm32\macros\macros.asm

for specific API functions...
one way is to look at the MSDN documentation page - get used to the page format
near the bottom is a "Requirements" section
it gives the header, library, and DLL

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365747%28v=vs.85%29.aspx

well - the headers apply to C code, and our libraries are different, but usually have the same name
the way Hutch has masm32 set up, the include files have the same name as the library
and - they only have the function prototypes
nearly everything else is defined in windows.inc (and winextra.inc, added by windows.inc)
constants, structures, typedefs, etc are in windows.inc/winextra.inc

rrr314159

I can only tell you what I did in this situation, opened files and searched for "print". Didn't work very well! Fact is, "print" is in macros.asm: it's a masm32 macro. In it, you'll find the function called is "crt_printf". So you can go search thru the includes for that, and find out it's in msvcrt.inc. I notice u don't have that in your includes; but I believe you'll find it referenced in masm32.inc. Normally I would check that myself b4 answering, but you were asking for the technique to find it, not where it is, so I'll let u figure it out :biggrin:

There are various ways to make this easier.

One, you don't have to open each include file (or macros file) one at a time, u can search thru the whole directory with Windows search, DOS "find", and various utilities which can be much better. No doubt u already know about these.

Two, often the function you're looking for is referenced a lot, so search for (for instance) "print MACRO" or "crt_printf proto", to get to the actual definition not just references to it. As you do this you'll figure out variants like using a tab instead of space between the two words, etc.

Three, there are no doubt more sophisticated techniques someone else can tell you. For instance, searching in the lib's (or even DLL's) directly, but then u have to know about mangling. Or, probably MasmBasic has a function to do this. If not, tell jj2007 u wish it did, wait an hour, and there it will be! Or go to MSDN, altho that seems out of sync with masm32 often. Or ...

But at least this way works, perhaps it will get u started

[edit] I see dedndave has a more sophisticated technique (posted while I was posting), listen to him, he's always right; but perhaps my way will come in handy at times also
I am NaN ;)

amrak

Thank you rrr314159 and dedndave. Dedndave thanks for always responding and helping us!

jj2007

Another option is xHelp, which searches all available macro and help files.

dedndave

you can use windows explorer search to search for files with specific text in them
and, inside a file, editors like NotePad have Find operations to help locate the text within the file

hutch--

If you are using the old WIN32.HLP, it tells you the library and C include file that it is declared in. In MASM32 the library matches the include file so its that library name that is useful to you.

amrak