Re: Unresolved external symbol when creating a DLL

Started by atzplzw, September 30, 2010, 04:20:59 PM

Previous topic - Next topic

atzplzw

Quite old but I do have the same problem. I like to create a assembler dll from C/C++ source. To test this I simply used the following function, which simply returns the instance:


__declspec(dllexport) HMODULE WINAPI Test()
{
    return s_hDll;
}


Mangled name is ?Test@@YGPAUHINSTANCE__@@XZ

Which I then insert in the asm file as

?Test@@YGPAUHINSTANCE__@@XZ proc near
mov eax, s_hDll
ret
?Test@@YGPAUHINSTANCE__@@XZ endp



Sadly this doesn't work. Error is Unresolved external symbol as the topic of this thread!
Asm Dll code is the same as posted by vortex.

It works if I just name the function: Test proc near
But this will not be an option because I need C++ object orientation style exports. The caller depends on it and I can't change that...

Any help is very appreciated!





clive

Seems to workable, MASM isn't further mangling it. If you use "FLAT, C" or "PROC C" it will add a leading underscore.

        .386

        .MODEL FLAT

        .DATA

s_hDll  dd      ?

        .CODE

?Test@@YGPAUHINSTANCE__@@XZ proc near public
  mov eax, s_hDll
  ret
?Test@@YGPAUHINSTANCE__@@XZ endp

        END


Disassembly

00000000                    ?Test@@YGPAUHINSTANCE__@@XZ:
00000000 A110000000             mov     eax,[s_hDll]
00000005 C3                     ret
00000010                    s_hDll:                     ; Xref 00000000
00000010 00 00 00 00                                        ....


Plus you should be able to modify the exported names of a DLL by using a DEF file, or forward it to another function, with a different name, in another DLL for that matter.
It could be a random act of randomness. Those happen a lot as well.


atzplzw

Ah! I see with dumpbin: _?Test@@YGPAUHINSTANCE__@@XZ@0
ml adds "_" to the function names in the obj.

Working with SYSCALL! Thanks...