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

Ali Çehreli acehreli at yahoo.com
Sat Jul 2 01:05:25 UTC 2022


On 7/1/22 12:11, Vinod KC wrote:

The following function is dimedll.testFunc:

 > ```d
 > module dimedll;
// ...
 > export void testFunc() {
 >      writeln("This is from dll");
 > }
 > ```

We suspect the name of the file that defines main() is dime.d.

 > extern void testFunc();

That symbol belongs to this module, which is implied to be 'module dime'.

 >      testFunc();

That's a call to dime.testFunc, which does not exist.

With the provided information alone, the following is what I would do:

1) This dll must have a .di file, which should contain the following:

// dimedll.di
void testFunc();

(.di files can be generated by dmd with its -H command line switch.)

2) Provide dimedll.di as your library's interface file (a la "header file").

3) The users of this dll should import that .di file (declaring the 
functions themselves won't work):

import dimedll;

void main() {
   // ...
}

Ali



More information about the Digitalmars-d-learn mailing list