Question on DLL example

Nox / Lux nox.et.lux.aeterna at gmail.com
Wed Nov 8 01:59:40 PST 2006


Hello all,

I have been trying out the "Win32 DLLs in D" example found at
http://www.digitalmars.com/d/dll.html (the "D code calling D code in DLLs"
section), and now I have many questions :)
I am trying to figure out how a plugin system could be written in D.

Heh, the first thing that strikes me about the example is that there are quite
a few things I don't understand. Like what is "HINSTANCE g_hInst;" and what
does it mean?

What does
"extern (C)
{
	void gc_init();
	void gc_term();
	void _minit();
	void _moduleCtor();
	void _moduleUnitTests();
}"
do and why is it contained within extern (C)? Isn't this D code interfacing
with D code?

What does
fp = GetProcAddress(h, "D5mydll16MyDLL_InitializeFPvZv");
do, and why is the second argument a mangled name?

Also I noticed that if I copied the code of mydll.d into a second file and
named it "mydll2.d", test.d would fail to run it after I compiled it to
"mydll2.dll". It would fail "MyDLL_Initialize()" ("error loading symbol
MyDLL_Initialize()"). But if the source file is named mydll.d, compiled and
then simply renamed to mydll2.dll, test.d will load it without problem. Why is
that? It is not very versatile of a program only to accept a plugin compiled
under a certain name - I would like a more general solution. Is that possible,
possible but complicated or impossible?

I realize by now that it probably would be good idea to read up on how DLLs
work in general. Does anyone have any tips on where (websites, books) I could
find an introduction to this?


Many thanks!



More information about the Digitalmars-d-learn mailing list