Win32 functions in NASM

Reply

Join Date: Oct 2006
Posts: 3
Reputation: kindnumbernine is an unknown quantity at this point 
Solved Threads: 0
kindnumbernine kindnumbernine is offline Offline
Newbie Poster

Win32 functions in NASM

 
0
  #1
Aug 4th, 2009
Hello. I was wondering if someone here could tell me what is needed to call a win32 function from NASM. I thought I could declare MessageBox for example with EXTERN and then use LINK to link my object module with user32.lib (from visual studio) but I get "unresolved symbol MessageBox" error when linking. Any ideas what I'm missing or what I'm doing wrong here?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Win32 functions in NASM

 
0
  #2
Aug 4th, 2009
Here's a link to a forum with someone with a similar problem.
http://www.nabble.com/How-to-call-Me...d23420607.html

For this kind of problem, posting code would be more beneficial!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: kindnumbernine is an unknown quantity at this point 
Solved Threads: 0
kindnumbernine kindnumbernine is offline Offline
Newbie Poster

Re: Win32 functions in NASM

 
0
  #3
Aug 5th, 2009
Thank you for the link. I had to rename the function to _MessageBoxA@16 in my source and it worked. Now I wonder why functions are named like this in the visual studio libraries. Is it a requirement of the linker? How would one go about writing their own routine in assembly to import a function directly from a DLL?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Win32 functions in NASM

 
0
  #4
Aug 5th, 2009
Didn't use to be that way, but due to multi-language there are various libraries.

MessageBox is merely a macro mapping to functions such as:
MessageBoxA Single-Byte Character System
MessageBoxW Wide-Character (Unicode)
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: Win32 functions in NASM

 
0
  #5
Aug 9th, 2009
An alternative is to use the Alink downloads:

http://alink.sourceforge.net/download.html

  1. ; To assemble: nasm -f obj hw.asm
  2. ; To link: alink -oPE hw .obj win32.lib
  3.  
  4. extern MessageBoxA
  5. extern ExitProcess
  6.  
  7. segment .data USE32
  8.  
  9. title db 'My First Win32 ASM Program', 0
  10. message db 'Hello, World!', 0
  11.  
  12. segment .text USE32
  13.  
  14. ..start
  15. push dword 0Eh
  16. push dword title
  17. push dword message
  18. push dword 0
  19. call MessageBoxA
  20. push dword 0
  21. call ExitProcess
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: kindnumbernine is an unknown quantity at this point 
Solved Threads: 0
kindnumbernine kindnumbernine is offline Offline
Newbie Poster

Re: Win32 functions in NASM

 
0
  #6
Aug 16th, 2009
Thanks for the responses! I'm still confused though as to why functions are named like that. You say its because of multi-language - could you elaborate on that? Also, Microsoft's linker requires the entry point label to begin with an underscore but not other global names I put in my code. Could someone explain why that is?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC