DLLエントリポイント - 実験2
実験その2です、今度は call 部分を外出しにします。
call.asm
BITS 32 global call_func call_func: push ebp mov ebp, esp sub esp, 8 mov eax, dword [ebp + 8] call eax leave ret
nasm -felf call.asm -o call.o
main.cpp
extern "C" void call_func(unsigned int func); void hello() { printf("hello\n"); } int main(int argc, char *argv[]) { unsigned int f = (unsigned int )hello; call_func(f); return 0; }
g++ -c main.cpp
結果
nobita% g++ main.o call.o -o hoge nobita% ./hoge hello
うまくいきました。