News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Needed steps for upgrading the Windows API

Started by Gunnar Vestergaard, August 20, 2009, 05:29:19 PM

Previous topic - Next topic

Gunnar Vestergaard

On my pc I installed the Microsoft Windows SDK a long time ago. I can see from many pages of the Windows SDK documentation that the pages were updated in 2007. So the time has come for installing a new version of the Microsoft Windows SDK. What are the steps needed for preparing MASM32 to use the updated new SDK?

1: Downloading the Platform SDK
2: Installing the Platform SDK
3: Runnning the MASM32 installer again

Is this correct?

In the text file \masm32\intro.txt , the last line reads
Steve Hutchesson for the MASM32 Project, 1998-2008

Is it necessary to download a new version of MASM32 as well?

Also, I use the MASM that was installed with Visual C++ Express Edition 2008.

ecube

You don't really need to install a new SDK unless you're trying to new use new api functions added for vista+, or if you just want the documentation from msdn saved on your harddrive. Even then you don't need to, as you can dynamically load a system dll and search for the function and use it that way.

Assuming you grab windows 7 sdk you just install that, it'll have a new masm(ml.exe) that you replace your old one if you like, I don't recommend you replace link.exe with the newer versions though.

asfar as masm(ml.exe) goes I recommend you atleast grab the 1 from icezlions website(http://win32assembly.online.fr/), as it fixes alot of bugs, its version 6 somthing I think, that's really all you need, masm doesn't suck like C++ does and require constant updates.

Gunnar Vestergaard

Quote from: E^cube on August 20, 2009, 06:03:50 PM
Even then you don't need to, as you can dynamically load a system dll and search for the function and use it that way.

That sounds interesting. How do I search for a function in a dll?

ecube

I personally use a program called Pe explorer to quickly look at a dll's exported functions, however alternatively you can check out http://win32assembly.online.fr/files/pelib.zip, which is a fantastic library written in masm for messing with the pe format, it has a function to list exports to a callback you specify. If you have trouble putting this lib to use, I can write some code for you to list all exports from all dll's in your system32 folder.

once you know the exact name/ordinal of a function a dll exports you then can either import it via including the necessary (e.g user32.lib to use user32.dll functions, or you can dynamically load that dll in memory, get the function address and use it like that, to do it the dynamic way, example is below)

to load a function dynamically and call it you can use the below example, to call on 1 line you need to use the _invoke macro, source for thats below
include \masm32\include\masm32rt.inc   

     CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
     ENDM
     
LoadLib proto :DWORD,:DWORD
.data
mymsg db "hello there",0
mytitle db "title",0

.data?
MsgBoxPtr dd ?

.code
start:
invoke LoadLib,CTEXT("user32.dll"),CTEXT("MessageBoxA")
.if sdword ptr eax!=0
mov MsgBoxPtr,eax


;this is the annoying way to use the return address in masm
push MB_OK
push offset mytitle
push offset mymsg
push 0
call MsgBoxPtr

;using the nice _invoke macro you can use on 1 line
_invoke MsgBoxPtr,0,addr mymsg,addr mytitle,MB_OK
.endif

invoke ExitProcess,0
;this trys to get a handle the loaded specified dll e.g user32.dll, if that fails then it trys to load the dll and get the handle
;afterwards it uses that handle to get the function address
;returns 0 for error,otherwise returns function address
LoadLib proc iDll:DWORD,iFunc:DWORD
invoke GetModuleHandle,iDll
.if sdword ptr eax==NULL
    invoke LoadLibrary,iDll
   .if sdword ptr eax==NULL
       ret
   .endif
.endif
invoke GetProcAddress,eax,iFunc
ret
LoadLib Endp
end start



;invoke.inc

_invoke MACRO funcname:REQ,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20

    LOCAL pos
    iswhite = 0

    FOR arg,<p20,p19,p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>
        IFNB <arg>
            pos=@InStr(1,arg,<ADDR>) OR @InStr(1,arg,<addr>) OR @InStr(1,arg,<Addr>)
            IF pos
                IFIDN @SubStr(arg,%pos+4,1), < >       ;; space
                    iswhite = 1
                ENDIF
                IFIDN @SubStr(arg,%pos+4,1), < >      ;; tab
                    iswhite = 1
                ENDIF
                IF iswhite
                    IF (OPATTR(@SubStr(arg,%pos+5))) EQ 98 OR (OPATTR(@SubStr(arg,%pos+5))) EQ 34
                        lea eax,@SubStr(<arg>,%pos+5)
                        push eax
                    ELSE
                        push OFFSET @SubStr(<arg>,%pos+5)
                    ENDIF
                ENDIF
             ELSE
                push arg
             ENDIF
        ENDIF
    ENDM
    call funcname
ENDM


for GoASM you can use the return handle direct with its invoke, don't have to use macros :) btw this macro won't work with a C function like wsprintf

Astro

Hi,

If I understand your query correctly, you can just use dumpbin (NameOfDLL) /exports > NameOfDLL.txt from the command line and it will dump all exports for you into a text file. Ensure the path to it appears in PATH, otherwise you need to type c:\masm32\bin\dumpbin .... - a lot of typing!

.386
.model flat,stdcall

; LoadLibrary/FreeLibrary/GetProcAddress are in Kernel32
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data?
hDLL dword ?
hFunc dword ?

.data
DLL db "Your DLLHere.dll",0
Func db "FuncToCallHere",0

.code
start:

push offset DLL
call LoadLibrary ; Returns: eax==0 for FAIL, eax > 0 is handle to module.

mov hDLL,eax

push offset Func
push hDLL
call GetProcAddress ; Returns: eax==0 FAIL, eax > 0 pointer to function

mov hFunc,eax

call hFunc ; calls "FuncToCallHere"
; You could also just use: call eax - but be aware that eax can get trashed if you're doing other things before the call so safer to store it first

push hDLL
call FreeLibrary ; Be sure to free the library before exiting to decrement usage count/free memory!

ret

end start


Best regards,
Astro.

hutch--

Gunnar,

MASM32 does not need to be installed or re-installed, it is independent of the system installation technique. If you need a later SDK, just install it and find out the file you need to use to access it and put it on the QE menu if you use QE.

I personally use a year 2000 edition of the SDK to ensure backwards compatibility and only occasionally bother to use the online MSDN reference just to make sure an API has not changed in its usage.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Astro

Unless I'm looking in the wrong place, I can't find updated ml.exe amongst the Platform SDKs.

Best regards,
Astro.

hutch--

Thats right, you need device development kits to get ML.EXE.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Astro

I downloaded V10 hardly a month ago from here - I presume it is the latest?

I'm interested because I'm just about to embark on some Win Vista/7 development.

Best regards,
Astro.