User forums > Using Code::Blocks
How to call win32 APIs in inlined at&t asm?
reverser:
hi all
--- Code: ---char * msg = "Hello, World!\n";
char * wMsg = "Content of the window..";
char * wCaption = "Window title";
int main (){
std::cout << "before call" << "\n";
asm(
"movl _msg,%eax\n\t"
"pushl %eax\n\t"
"calll _printf\n\t"
"popl %eax\n\t"
"movl $0, %eax\n\t"
"movl _wCaption, %ebx\n\t"
"movl _wMsg, %ecx\n\t"
"movl $0, %edx\n\t"
"pushl %eax\n\t"
"pushl %ebx\n\t"
"pushl %ecx\n\t"
"pushl %edx\n\t"
"calll MessageBoxA\n\t"
"popl %edx\n\t"
"popl %ecx\n\t"
"popl %ebx\n\t"
"popl %eax\n\t"
);
std::cout << "after call" << "\n";
}
--- End code ---
when i want to compile, i get:
undefined reference to `MessageBoxA'
can someone please tell me what's wrong?
ollydbg:
Just a guess: do you link the correct library?
reverser:
--- Quote from: ollydbg on April 30, 2022, 04:53:39 pm ---Just a guess: do you link the correct library?
--- End quote ---
i don't think so
can you please tell me how? you have no idea how much i goggled it.
stahta01:
Link that might help https://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F
It is best to follow the "For your project :" part of the FAQ.
Edit: Google/MS says the library is user32
Tim S.
ollydbg:
This is the test code I use(I'm using 64bit GCC compiler)
--- Code: ---#include <iostream>
using namespace std;
char * msg = "Hello, World!\n";
char * wMsg = "Content of the window..";
char * wCaption = "Window title";
int main (){
std::cout << "before call" << "\n";
int src = 1;
int dst;
asm ("mov %1, %0\n\t"
"add $1, %0"
: "=r" (dst)
: "r" (src));
printf("%d\n", dst);
asm(
"movq $0, %%rax\n\t"
"movq $0, %%rax\n\t"
"add $48, %%rax\n\t"
"movq $0, %%rbx\n\t"
"movq $0, %%rcx\n\t"
"movq $0, %%rdx\n\t"
"push %%rax\n\t"
"push %%rbx\n\t"
"push %%rcx\n\t"
"push %%rdx\n\t"
"call MessageBoxA\n\t"
:
: "r" (msg), "r" (wMsg) , "r" (wCaption)
: "cc");
std::cout << "after call" << "\n";
}
--- End code ---
The MessageBoxA function can be called.
But I have no idea how to pass the string to this function.
See those links as reference:
http://asm.sourceforge.net/articles/rmiyagi-inline-asm.txt
https://stackoverflow.com/questions/66323292/messagebox-program-in-x86-assembly
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GotoLabels
https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
BTW: you need an export on assembly language for help. Our forum is not the right forum to ask.
EDIT:
To reference the input variables, you need
--- Code: ---%0, %1 and %2
--- End code ---
like string in the assembly code.
Navigation
[0] Message Index
[#] Next page
Go to full version