The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jj2007 on July 20, 2009, 10:17:01 AM

Title: DLL with polink: Unresolved external symbol
Post by: jj2007 on July 20, 2009, 10:17:01 AM
I am trying to produce a very simple dll. It works fine with link.exe but fails with polink:

Unresolved external symbol '_SayHello'

include \masm32\include\masm32rt.inc

.code
LibMain proc instance:DWORD, reason:DWORD, unused:DWORD
    mov eax, TRUE
    ret
LibMain endp

SayHello proc EXPORT MyText:DWORD
    invoke MessageBox, 0, MyText, chr$("I sit in a dll!"), MB_OK
    ret
SayHello endp

end LibMain


My def file is as follows:
LIBRARY "MiniDll"
EXPORTS
SayHello


Commandline:
\Masm32\bin\polink.exe /Subsystem:Windows /DLL /DEF:TmpDllEx.def  "MiniDll.obj" /OUT:MiniDll.dll

All that works perfectly with link.exe, versions 5.12 and 9.00

Any ideas?
Title: Re: DLL with polink: Unresolved external symbol
Post by: dedndave on July 20, 2009, 01:02:35 PM
hiyas Jochen,
i am guessing the "_" decorator may have something to do with it
Erol is the guy to ask, of course - lol
Title: Re: DLL with polink: Unresolved external symbol
Post by: Vortex on July 20, 2009, 04:57:35 PM
Hi Jochen,

No need to use a module definition file if you specify the EXPORT keyword below :

SayHello proc EXPORT MyText:DWORD

\masm32\bin\ml /c /coff MiniDLL.asm
\masm32\bin\polink /SUBSYSTEM:WINDOWS /DLL MiniDLL.obj


Linker : Polink Version 6.00.1

[attachment deleted by admin]
Title: Re: DLL with polink: Unresolved external symbol
Post by: jj2007 on July 20, 2009, 08:54:33 PM
Hi Erol,

With your settings, it builds the dll but the exports are decorated:

this will work: mov pSayHello, rv(GetProcAddress, hDll, chr$("_SayHello@4"))
this does not work: mov pSayHello, rv(GetProcAddress, hDll, chr$("SayHello"))


The commandline /DLL /DEF:TmpDllEx.def will produce the "unresolved" error, if I uise only /dll, it links fine but again, I have the decorated names. How can I get rid of the decoration?

P.S.: The export.txt is apparently not needed, and has no influence on the result.

EDIT:

SayHello proc EXPORT MyText:DWORD

It works fine when I use the /def:Myfile.def option and take away the export keyword (the latter does not disturb link.exe...).

Edit(2): For RichMasm (http://www.masm32.com/board/index.php?topic=9044.msg73814#msg73814) (see TheGuide, MiniDLL), I found a solution that works fine for link.exe and polink.exe:

QuoteSayHello proc MyText:DWORD  ; $export

The editor will create the .def file based on the names of those procedures that have $exp in the same line as the proc itself.