Frankie: The original cause of my post was, to show, that something is wrong with the files, the wizard generats if one checks the 'def file' option. I could not find any way to access this dll without changing the def or the dll itself.
Czerny I went too deep in the problem, to plainly answer to your original question: the wizard output cannot be linked directly because it creates a
symbol without decorations.
The sample:
; TODO: Add your exports here!
"MyExportFunction"=_SampleFunction@8
Creates an undecorated symbol, 'MyExportFunction', that cannot be linked from 'C' environment (maybe it can from Fortran or Pascal unless they care for letters case). The wizard would just show that you can name the symbol the way you like. But, I agree with you, it doesn't show what the user is looking for: how to export and then link a symbol from a DLL...
Now consider that the DLL wizard is very old and not updated maybe from version 4.5. Probably originally it was clear that the preferred way to export a symbol is to use the '__declspec(dllexport)' that takes care to produce a symbol correctly decorated transparently to the user. Maybe the scopeof the generated DEF file would show a 'special' application.
The point is that you cannot link to undecorated symbols
, in C language is
mandatory that the symbol name has a prepended underscore. If the function is a stdcall (an M$ extension because 'C' has only the cdecl), M$ standard also requires that to the symbol is appended an '@' sign followed by the decimal number of bytes used on the function call.
No difference with /Gn.
The compiler switch -Gn (n should mean 'normalize' ? ) just prepends the underscore so
any type of call (cdecl, stdcall and fastcall) a cdecl or stdcall produce the same symbol name. This should be usefull to link with other compilers that doesn't perform full decoration.
With /Gm switch:
The entry in the dll is 'SampleFunction' but in the export library '_SampleFunction'.
The compiler -Gm switch is something that I personally asked to Pelle
because is usefull on some of my application made with mixed language ('C' and assembly) where I could define functions in assembler without any decoration and call them from 'C' modules (otherway I had to compute how many bytes were used in calls and add '@' and number of bytes to symbols. Very boring for fast programming
).
Now come to the real bugs I have found.
Your def file defines 6 function names, but the dll exports only 5.
First bug: is not possible to define an undecorated symbol that has the same name of the source symbol.
SampleFunction = _SampleFunction@8 ;without stdcall decorations and underscore
This DEF statement is ignored.
That's why you find only 5 symbols against 6 declarations.
Further, the exported functions of the export library are 5 too and they don't match with the dll names.
I don't understood what you mean. The exported symbols have the assigned names:
<Name you want> = <Internal name means fully decorated>
If I use only 1 entry in the def file:
LIBRARY "dlltest"
EXPORTS
SampleFunction
The entry in the dll is 'SampleFunction' but in the export library '_SampleFunction@8'.
I have wrote it in my comments:
SampleFunction ;standard export, will create a decorated symbol export
If you specify only the plane name (the one used in the source code) the linker exports automagically the correct decorated name.
Then come the second bug: the forwarding symbols export (as explained in the help) doesn't seem to work.
With this techniqe is possible to create a symbol that exports a function from a different DLL. I would try to export the 'Beep' function from 'kernel32.dll' with a different name:
mybeep = kernel32._Beep@8 ;This don't work
The address is
not resolved when executable is loaded and program crashes!
Strangely it could work in this way:
mybeep = _Beep@8
Anyway the use of DEF files shouldn't be the preferred way to export symbols. There are at least 4 ways to do it, and the use of a DEF file is convenient only when you need to change also DLL characteristics (see
here).
If this all is ok, then please explain!
Please Czerny use some emoticons, I don't could understand if you are asking something or arguing with me...