News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

calling a dll in masm and C

Started by guga, July 24, 2014, 01:23:23 PM

Previous topic - Next topic

guga

Hi guys

I need a bit help here for syntax.

I´m building a dll for pdb parsings with msdia and currently writting a tutorial on how to use the exported functions. My dll contains only 2 functions "GetPDBInfo" and "FreePDB". Since it does not have a .lib or a .def file, how is the proper syntax to calling the functions of the dll in masm and plain C ?

I mean, despited the usage of LoadLibrary. I want to know the proper syntax such as:

#pragma dll("path/PDBRipper.dll")

Is the above correct in C ? If it is...then what ? How to properly call the external functions ?

And what are the correct syntax for masm  on this same situations (loading the library and their functions) without having to build a lib or def file ?


Btw:

The function GetPDBInfo contains only 2 parameters
pUniString: A pointer to a Unicode Null Terminated string that is the path of the pdb
Flags: A integer value that is used as a flag to handle the equates for the function
On sucess it returns on eax a string allocated in memory with the proper tokens to be easily parsed. Btw: I kept it simple. Each element of the pdb is separated with a "|" token  ;)

The function Free have 1 parameter:
hMem: A pointer to the generated Ascii string allocated in memory by GetPDBInfo
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Simple Masm32 example:

  mov hDll, rv(LoadLibrary, chr$("MbMicroDll"))      ; rv is the retval macro, it returns eax
  .if eax
   mov ptrInstr, rv(GetProcAddress, hDll, chr$("InstrDLL"))
   .if eax
      push 2+4      ; mode 2 = ignore case of first letter, 4 = whole word
      push chr$("test")      ; the pattern
      push chr$("This is a Test")      ; the source
      push 1      ; the start pos
      call ptrInstr
      MsgBox 0, eax, chr$("The match is here:"), MB_OK
   .else
      invoke MessageBox, 0, chr$("InstrDLL not found"), 0, MB_OK
   .endif
   invoke FreeLibrary, hDll
  .else
   invoke MessageBox, 0, chr$("DLL not found"), 0, MB_OK
  .endif

guga

Hi JJ. Many thanks. I´ll include that on the tutorial.

Btw, there is another way to load it when the dll don´t have a def or lib file ? I mean, assuming the "#pragma dll" token in C is correct, is there a similar token for masm?

In RosAsm for example, there is no need for such definitions or lbraries, since the dll can be called directly, ex:
....
call 'user32.MessageBoxA'

But, i don´t recall having something similar in masm, and i´m not sure how is he syntax in C (If the pragma token is the proper one)

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

MichaelW

#pragma dll... does not appear to be supported by the Microsoft compilers:

http://msdn.microsoft.com/en-us/library/d9x1s805.aspx

Visual Basic supports a "lib" clause, that if I recall correctly when added to a procedure declaration will allow you to call the procedure without an import library or an explicit LoadLibrary + GetProcAddress, but I can't recall anything similar for C/C++.

And there are the MASM32 LoadProcAddress, GetDllProc, and DDPROTO macros.
Well Microsoft, here's another nice mess you've gotten us into.

guga

Hmm, ok. So there will be no much alternatives except building those defs and a small lib with vortex´s tools. No problem, i´ll release a lib file with the dll. It may be worthfull for masm and C programmers as well. At least it will be better provide another alternatives assides LoadLibrary etc
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com