Click to See Complete Forum and Search --> : C++ inline ASM


doitlong
September 2nd, 2004, 02:05 AM
#include <stdio.h>

class CHello{
public:
void fun()
{
printf("Hello World");
}
};

void main()
{
CHello hello;
_asm{
LEA EAX,hello
CALL [EAX]hello.fun
};
}


/-------------------------------------------------------------------

error C2411: 'fun' : illegal struct/union member in 'first operand'

-------------------------------------------------------------------/

Tools : VC++6.0

Alkhimey
July 2nd, 2005, 11:46 AM
CALL [EAX]hello.fun()

NoHero
July 2nd, 2005, 03:11 PM
The thing you are trying to do has following issues:


You cannot use C++ OOP within a low level language because you do not know how it is implemented and internaly represented by the compiler.
When you try to do it, and get an hack for a compiler this hack is compiler depended, because any compiler does it another way.
A member function is (most time) nothing else than a normal function which get's internally a pointer to a structure containing all data members of the class. The problem now: You either don't know how to call the function, because you do not know it's name and you cannot "extract" the internal structure from the class.
Everything would be mixed up when using virtual members, because they are stored as function pointer table inside the hidden structure.
And digging as deep as you are trying to do, is not the way it supposed to be. You should get your nose out of this, otherwise it will cause a lot of strange bugs you aren't able to identify or even fix them.


To cut the long story: What you are trying todo is not fine coding style and (nearly) impossible.

BytePtr
July 3rd, 2005, 12:03 PM
#include <stdio.h>

char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
void main( void )
{
__asm
{
mov eax, offset world
push eax
mov eax, offset hello
push eax
mov eax, offset format
push eax
call printf
pop ebx
pop ebx
pop ebx
}
}