How to call a function from a dll created with d ?

apz28 home at home.com
Sat Jul 2 14:32:11 UTC 2022


Below is working on Windows

--file dimedll.d:

module dimedll;
import core.sys.windows.windows;
import core.sys.windows.dll;
import std.stdio;

mixin SimpleDllMain;

     export void testFunc()
     {
         writeln("This is from dll");
     }


--file dime.d:

import core.sys.windows.windows;
import std.stdio;
import dimedll;
pragma(lib, "dimedll.lib");

     void main() { 	
     	writeln("Lets call testFunc()");
     	testFunc();		
     }


--file dimedll.di:

module dimedll;
extern void testFunc();


--file dimedll.def

LIBRARY "dimedll.dll"
EXETYPE NT
SUBSYSTEM WINDOWS
CODE SHARED EXECUTE
DATA WRITE


-- command lines in sequence:
-- there should be files as first dmd: dimedll.exp, dimedll.lib, 
dimedll.obj

dmd -of=dimedll.dll dimedll.d dimedll.def
dmd dime.d dimedll.di



More information about the Digitalmars-d-learn mailing list