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

Vinod K Chandran kcvinu82 at gmail.com
Sat Jul 2 13:37:40 UTC 2022


On Saturday, 2 July 2022 at 01:05:25 UTC, Ali Çehreli wrote:
>
> 3) The users of this dll should import that .di file (declaring 
> the functions themselves won't work):
> Ali
>


Hi, Thanks for the reply. I have tried your suggestion. First, I 
compiled my dll's source code with `-H` switch as you said. Then 
I got the header file with this content.

```d
// D import file generated from dimedll.d
module dimedll;
import core.sys.windows.windows;
import core.sys.windows.dll;
import std.stdio;
mixin SimpleDllMain!();
export void testFunc();
```
So far so good. Then I change my `dime.d` source file like this.

     ```d
     import dimedll;
     void main() { 	
         log("Lets build our own ime");
         testFunc();	
     }
     ```
     Unfortunately, I got this error message.


dime.obj : error LNK2019: unresolved external symbol 
__imp___D7dimedll8testFuncFZv referenced in function __Dmain
dime.obj : error LNK2001: unresolved external symbol 
__D7dimedll12__ModuleInfoZ
dime.exe : fatal error LNK1120: 2 unresolved externals
Error: linker exited with status 1120


Then I have tested with `dimedll.testFunc()` instead of 
`testFunc()` at the calling site.
Then also I got an error message like this.


dime.obj : error LNK2019: unresolved external symbol 
__imp___D7dimedll8testFuncFZv referenced in function __Dmain
dime.obj : error LNK2001: unresolved external symbol 
__D7dimedll12__ModuleInfoZ
dime.exe : fatal error LNK1120: 2 unresolved externals
Error: linker exited with status 1120

     I want to test this with ddemangle.exe, but there is no 
proper documentation for that tool. So I don't know how to use 
that tool. So Actually I am stuck.



More information about the Digitalmars-d-learn mailing list