Forum Navigation
Creating a DLL? Using SharedLib?
Posted: 05/28/09 14:37:18I have the following three files:
default.d --------------------------------------------- module Default;
import tango.io.Stdout; import tango.core.runtime; import tango.sys.win32.Types;
HINSTANCE g_hInst;
extern (Windows) BOOL DllMain?(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) {
switch (ulReason) {
case DLL_PROCESS_ATTACH:
Runtime.initialize(); break;
case DLL_PROCESS_DETACH:
Runtime.terminate(); break;
case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH:
// Multiple threads not supported yet return false;
} g_hInst=hInstance; return true;
}
export void SG_init() {
Stdout.format("Hello World!\n");
}
default.def ------------------------------------------- LIBRARY "default.dll" EXETYPE NT SUBSYSTEM WINDOWS CODE SHARED EXECUTE DATA WRITE
test.d ------------------------------------------------ import tango.sys.SharedLib?; import tango.io.Stdout;
void function() do_stuff;
int main() {
if (auto lib = SharedLib?.load("default.dll")) {
Stdout.formatln("Library successfully loaded");
void* ptr = lib.getSymbol("SG_init"); if (ptr) {
Stdout.formatln("Symbol SG_init found. Address = 0x{:x}", ptr);
do_stuff = cast(void function())ptr; do_stuff();
} else {
Stdout.formatln("Symbol SG_init not found");
}
lib.unload();
} else {
Stdout.formatln("Could not load the library");
}
return 0;
}
I'm building my DLL like this:
dmd -ofdefault.dll default.d default.def
That gives this error:
OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. OPTLINK : Warning 183: Extension not .RES : tango-user-dmd.lib OPTLINK : Warning 183: Extension not .RES : tangobos.lib default.obj(default)
Error 42: Symbol Undefined _D5tango2io5Print12T5PrintTaZ5Print6formatMFAaYC5t
ango2io5Print12T5PrintTaZ5Print default.obj(default)
Error 42: Symbol Undefined _D5tango2io6Stdout6StdoutC5tango2io5Print12T5Print
TaZ5Print T:\tango\bin\..\lib\tango-user-dmd.lib
Error 30: Unexpected End of File
--- errorlevel 3
It seems to be having a problem linking to Tango. I can build exe's just fine, so I'm not sure what about DLLs is different.
But so once I get my DLL working, should I be able to build test.d like this:
dmd test.d
Just that? No further def files or anything?