I'm wondering if it's possible to get the return type of a function with inline ASM in VC++. Basically what I want to try to do is something like
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PE32.th32ModuleID);
So far I have
					__asm{
mov eax, PE32.th32ModuleID
push eax
mov eax, FALSE
push eax
mov eax, 0x1F0FFF
push eax
Call OpenProc

How would I get the handle of OpenProc and store it? (typedef of OpenProcess from kernel32.dll)

typedef HANDLE (__stdcall *pOpenProcess)(DWORD, BOOL, DWORD);
OpenProc = (pOpenProcess)GetProcAddress(hKernel, "OpenProcess");
Posted on 2006-09-08 23:22:58 by redz
The easiest way is to define a dword variable to hold the result, and to shove eax into it when the call has returned.
Posted on 2006-09-08 23:46:13 by Homer
thats the only way ive ever seen it done
like this

__asm{
mov eax, PE32.th32ModuleID
push eax
mov eax, FALSE
push eax
mov eax, 0x1F0FFF
push eax
Call OpenProc
mov tempvar,eax
}

// then you can use tempvar here in your c code like normal


Posted on 2006-09-10 11:45:28 by Nice Eddie
Hm, why are you doing something like that in inline assembly? There's absolutely no advantage over writing it in plain C... Also, you don't need "mov eax, val/push eax", you can push the values directly. And the others have probably misunderstood you, or perhaps I am. But anyway, after you "call OpenProc", the return is in EAX.

Also, if you want to return stuff yourself, you can either do the tempval as already suggested, or write a "naked" routine. But you're pretty much better off using an external asm module instead of inline assembly.
Posted on 2006-09-10 14:54:33 by f0dder
Using inline asm 'because it's more l33t to do so' isn't going to let you learn anything. External DLL with asm modules is what you want to use.

But if you really wish...

#ifndef ALIGN
#define ALIGN __declspec(align(32))
#endif


#pragma warning(disable : 4035)
ALIGN unsigned long __stdcall lstrlen2(unsigned char *memptr) {

    __asm {
        mov     eax,
_loop0: mov     dl,
        add     eax, 1
        or      dl, dl
        jnz     _loop0
        sub     eax, 1
        sub     eax,
    }
}
#pragma warning(default : 4035)

This function supersedes Windows' "lstrlen". MSVC still performs type checks (thanks to not making the function 'naked'). The 4035 warning gets disabled while the function is being compiled so MSVC won't print the "function must return unsigned long" complain.

/edit
Actually, you don't need this "ALIGN", but it's more 'l33t' to use it :P
Posted on 2006-09-10 18:54:31 by ti_mo_n
Hey back off guys, what does it matter as long as he's screwing about with asm?

redz - f0dder is correct, there's nothing to be gained in this particular example, but I do urge you to continue screwing around with inline asm, noting that inline asm isn't as powerful as a fully-featured assembler..
Posted on 2006-09-10 23:16:14 by Homer