Creating A D DLL For Use By VB

James Dunne james.jdunne at gmail.com
Sun Mar 19 22:34:19 PST 2006


starkweatherr at mchsi.com wrote:
> No joy. Here's the code.
> 
> //MyDLL.d
> extern (Windows) int addInt(int int1, int int2);
> 
> //MyDLL2.d
> module mydll;
> extern (Windows) int addInt(int int1, int int2)
> { 
> return (int1 + int2);
> }
> 
> ;MyDLL.def
> LIBRARY "mydll.dll"
> EXETYPE NT
> SUBSYSTEM WINDOWS
> CODE SHARED EXECUTE
> DATA WRITE
> 
> @echo off
> REM Build.bat
> E:\DigitalMars\dmd\bin\dmd -ofmydll.dll mydll2.d dll.d mydll.def
> E:\DigitalMars\dmd\bin\implib /system mydll.lib mydll.dll
> E:\DigitalMars\dmd\bin\dmd test.d mydll.lib
> 
> I got two errors. Implib says no functions are exported and
> OptLink says Undefined Symbol: intAdd at 8
> 
> Am I supposed to put 'export extern (Windows) ' instead of just 'extern
> (Windows)'?
> 
> 

Why are you running implib on the static lib instead of relying on the 
compiler-generated DLL file?  I get my DMD-generated DLL file working 
just fine.

I think at this point it's just easiest to post a working example 
project. :)  Enjoy!

In summary, you need the 'export' directive on each function you intend 
to export; also you need an EXPORTS section in your DEF file which 
explicitly lists all the function names you're exporting through your 
DLL.  Then, it's a simple matter of declaring the function correctly in 
the VB code, which sometimes is not so simple. =P

Remember these important tips for VB <-> C/C++/D interop:
	* All parameters are passed ByRef by default, use ByVal instead
	* No unsigned types except Byte
	* Integer = 16 bit signed
	* Long = 32 bit signed
	* VB strings are NULL-terminated wide-character strings.
	* D strings are length-tracked dynamic arrays.

-- 
Regards,
James Dunne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mylib.zip
Type: application/octet-stream
Size: 8546 bytes
Desc: not available
Url : http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20060320/7e06ba63/attachment.obj 


More information about the Digitalmars-d-learn mailing list