943,910 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1442
  • Assembly RSS
Aug 4th, 2009
0

Win32 functions in NASM

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kindnumbernine is offline Offline
3 posts
since Oct 2006
Aug 4th, 2009
0

Re: Win32 functions in NASM

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!
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Aug 5th, 2009
0

Re: Win32 functions in NASM

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kindnumbernine is offline Offline
3 posts
since Oct 2006
Aug 5th, 2009
0

Re: Win32 functions in NASM

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)
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Aug 9th, 2009
0

Re: Win32 functions in NASM

An alternative is to use the Alink downloads:

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

Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 99
Solved Threads: 5
Junior Poster
Evenbit is offline Offline
140 posts
since Mar 2005
Aug 16th, 2009
0

Re: Win32 functions in NASM

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kindnumbernine is offline Offline
3 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Question on kernel and bootloader written in assembly.
Next Thread in Assembly Forum Timeline: Assembly wierdness





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC