Shared libraries/DLLs

Unknown W. Brackets unknown at simplemachines.org
Sun Feb 3 23:30:22 PST 2008


This is useless for plugins because I have no idea what the module name 
will be.  It would be ridiculous for me to enforce all plugins use the 
same module.

It might make sense to have an extern (C) export that is the module 
name, thus enabling me to use such a methodology.

But having GetProcAddress("_D7example4initFZi") hard coded in the host 
would really not work for me.

-[Unknown]


Tomasz Polachowski wrote:
> Unknown W. Brackets Wrote:
> 
>> Consider the following simple "library":
>>
>> ---
>> module library;
>>
>> import loader;
>>
>> // (the DllMain stuff from D's doc pages.)
>>
>> extern (C)
>> export int foo()
>> {
>> 	return 42 * loader.bar();
>> }
>> ---
>>
>> And also consider this "application":
>>
>> ---
>> module loader;
>>
>> import std.c.windows.windows;
>> import std.string, std.stdio;
>>
>> extern (C)
>> alias int function() example_f;
>>
>> void main()
>> {
>> 	HMODULE m = cast(HMODULE) LoadLibraryA(toStringz("library.dll"));
>>
>> 	example_f f = cast(example_f) GetProcAddress(m, toStringz("foo"));
>>
> (...)
> 
> Why did you insert 'extern (C)' in 'library' and 'loader' when you'd like to call D code from D module?
> 
> getProcAddress takes a decorated name only as a 2nd argument (as you can see in 'Win32 DLLs in D'). Just compile 'library' (or a file containing WinMain that imports it) with -L/map switch to receive a complete symbol list in one *.map file. All the imports are under the "Address   Export   Alias' section. I've been using an 'Alias' name passed into getProcAddress. [Btw for 'int library.foo()', decorated name alias is _D7library3fooFZi'] Decorated name contains condensed information about module and function names, return type and types of the function args.


More information about the Digitalmars-d-learn mailing list