Question

Following procedure returns the address of of a zero terminated string:

GetExecutablePath proc

local hInstance:HMODULE
local szFileName[MAX_PATH]:BYTE

invoke GetModuleHandle, NULL
mov hInstance, eax
.if hInstance == NULL
    xor eax, eax
    ret
.endif

invoke GetModuleFileName, hInstance, addr szFileName, sizeof szFileName
.if eax == 000h
    xor eax, eax
    ret
.endif

lea eax, szFileName

ret
GetExecutablePath endp

In my main procedure, I would like to copy the content of this address into another local variable:

local szPath[MAX_PATH]:BYTE
invoke GetExecutablePath
; MOVE CONTENT OF eax TO szPath

I only found a way to copy(mov) the address of eax to a local variable, but I am looking for a way to copy the referenced content to a new variable.

Était-ce utile?

La solution

You are trying to access a local variable that has already gone out of scope. This is a bad idea. Instead, you should rewrite your GetExecutablePath function such that it accepts a pointer to a buffer.

To answer the question anyway: technically, you would use some form of memory block copy.

PS: you don't have to zero eax when you know it's already zero ;)

PS #2: you should forget about masm's high-level directives such as .if or .while and use the appropriate asm constructs instead. If you are a beginner you should learn those, and if you are not, then it's no extra effort and you'll at least know exactly what you'll get.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top