From: Frank K. <fbk...@zy...> - 2009-05-07 08:10:50
|
oh...@co... wrote: > Hi, > > I'm trying to add a call to MessageBoxA in a Nasm app. I know how to setup the parameters for the call, but I can't get Nasm to assemble successfully. > > I have added an "extern MessageBoxA" and "import MessageBoxA user32.dll" (this is on Windows), but when I do that, I get an error from parser saying that an instruction is expected. > > If I comment out the "import" line, I get a linker error. > > Am I not suppose to use both the "extern" and "import" lines, before the .Code line? Mmmm, yes, but only in "-f obj" output format (which defaults to 16-bit and requires some "cruft" to tell Nasm we want 32-bit). Supposedly, in "-f win32" format, we "don't need" it. I think the reason we "don't need" it is that we are expected to link with an "import library" on the linker command line. I am told that we can create our own import library by assembling "extern MessageBoxA" and "import MessageBoxA user32.dll" (with other extern/imports we need, presumably) as "-f obj" and linking the produced .obj with the .obj containing your code (assembled as "-f win32") - despite the different linkable object formats, this is supposed to work. I was told this after I'd quit running Windows, so never had a chance to try it. I think the more "usual" way would be to link against an import library supplied with your linker(?). This raises the obvious question: which linker are you using? And what, if anything, came with it? I don't know much about Windows linkers - I used Alink, mostly, for the few Windows programs I tried. I think Golink and Polink are more common these days. You might want to download the "nasmx" package: http://www.asmcommunity.net/projects/nasmx/ Recent versions have been in .exe format, so I can't even look at it to see what's there. Uses Golink, it says that on the web page... If it doesn't include a "win32.lib" or such, the examples may give you an idea how to function without it. If all else fails... http://home.comcast.net/~fbkotler/win32nasmbase.zip ...as I recall, that includes a library that worked with "-f win32", although it is extremely old and obsolete... This question about "import" comes up fairly often, and I don't really have a "good" answer to it, besides "it's for -f obj only" and we "don't need" it for -f win32... Anyone got a clearer idea on this? Best, Frank |