www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Creating A D DLL For Use By VB

reply strkweatherr mchsi.com writes:
I'm having the same problem with DigitalMars D as I had with DigitalMars C/C++,
but nobody over there has answered any of my questions. 

I started with the MyDLL package and modified it so that it accepts two ints and
returns the sum. Test.exe works fine, but VB says the .lib file doesn't exist. I
am assuming that is because it isn't in a recognizable format.

I'm really desperate so I tried:

Public Declare Function addInt _
Lib "E:\DMDWork\MyDll.dll" _
Alias "D5mydll6addIntFiiZi" _
(lngInt1 As Long, _
lngInt2 As Long) _
As Long

As you might expect, I got a Type 49 error.

Another question. When I try to put EXPORTS in the .def file I get error
messages that say there is no entry point for the function. ???

Does anyone have a piece of source code, that works, for a DLL that is
accessible from non-D programs and that is less than 50 lines long?
Mar 18 2006
next sibling parent reply James Dunne <james.jdunne gmail.com> writes:
strkweatherr mchsi.com wrote:
 I'm having the same problem with DigitalMars D as I had with DigitalMars C/C++,
 but nobody over there has answered any of my questions. 
 
 I started with the MyDLL package and modified it so that it accepts two ints
and
 returns the sum. Test.exe works fine, but VB says the .lib file doesn't exist.
I
 am assuming that is because it isn't in a recognizable format.

VB can only work with DLLs, not LIBs. LIBs are statically linked libraries. DLLs are dynamically linked libraries. Worlds apart.
 
 I'm really desperate so I tried:
 
 Public Declare Function addInt _
 Lib "E:\DMDWork\MyDll.dll" _
 Alias "D5mydll6addIntFiiZi" _
 (lngInt1 As Long, _
 lngInt2 As Long) _
 As Long
 
 As you might expect, I got a Type 49 error.
 

Write your D DLL to use the Windows calling convention (a.k.a. STDCALL). Just put an 'extern (Windows)' before each function definition, then you won't have to use mangled symbol name of the function. Also, VB uses ByRef parameters by default; you want to use ByVal parameters instead. So your new VB function declaration should look like this: Public Declare Function addInt Lib "E:\DMDWork\MyDLL.dll" (ByVal lngInt1 As Long, lngInt2 As Long) As Long and define your D function like this: extern (Windows) int addInt (int a, int b) { return a + b; }
 Another question. When I try to put EXPORTS in the .def file I get error
 messages that say there is no entry point for the function. ???
 

Not sure what you mean here... some detailed output would help.
 Does anyone have a piece of source code, that works, for a DLL that is
 accessible from non-D programs and that is less than 50 lines long?

I'd say to stick with Windows calling convention for interoperating with VB. I've written a number of D DLLs that work with VBA (in Excel) quite easily. Debugging becomes another problem, however... Good luck! You can reach me at my posted e-mail address if you need further assistance or sample code. -- Regards, James Dunne
Mar 18 2006
next sibling parent reply starkweatherr mchsi.com writes:
Is it safe to assume that I need to put the export (Windows) in fron to the
declaration as well as the definition?
Mar 19 2006
parent starkweatherr mchsi.com writes:
In article <dvkad2$2dcj$1 digitaldaemon.com>, starkweatherr mchsi.com says...
Is it safe to assume that I need to put the export (Windows) in fron to the
declaration as well as the definition?

I don't know where the other message went, but I tried both //MyDLL.d extern (Windows) int addInt(int int1, int int2); //MyDLL.d extern (Windows) int addInt(int int1, int int2); and //MyDLL.d export extern (Windows) int addInt(int int1, int int2); //MyDLL.d export extern (Windows) int addInt(int int1, int int2); and I get the same thing: Error 42: Symbol undefined _addInt 8 I also tried: LIBRARY "mydll.dll" EXETYPE NT SUBSYSTEM WINDOWS CODE SHARED EXECUTE DATA WRITE EXPORTS addInt 8 and got: Optlink : Error 180: No match found for export/Entry - : addInt Optlink : Error 81: Cannot EXPORT : addInt DMD Error 42: Symbol Undefined _addInt 8
Mar 19 2006
prev sibling parent reply starkweatherr mchsi.com writes:
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 8

Am I supposed to put 'export extern (Windows) ' instead of just 'extern
(Windows)'?
Mar 19 2006
parent reply James Dunne <james.jdunne gmail.com> writes:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

starkweatherr 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 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
Mar 19 2006
parent reply starkweatherr mchsi.com writes:
It doesn't appear that the zip file is accessible. A working sample is just what
I need. Can you post the code un-zipped?

The reason why I a using implib is that is the way the demo app does it. The
code I am using came with the DMD package, and works as long as I run it from
test.exe. If there is a better way, that is exactly what I am looking for.

The reason why I am not using EXPORTS in the .def files is the error messages
that produces. There is something wrong there also, and I have no idea what that
problem is either.

I'm not worried about the VB side. Maybe I should explain the project.

I've been writing bare frameworks for using DLLs generated by various C/C++
compilers from VB for upload to PSC. So far I have finished VC++ 6 and BCB 5.5.
Someone who saw the code suggested that I write one for DMC, which I had never
heard of before. That effort is still awaiting a response to questions in the
Command Line forum on the DMC side. Similar problems, different language.

I noticed 'D' while I was trying to get DMC to work and decided to give that a
try. It has been really frustrating to try to put together what is in the
documentation with the demo app that comes with DMD, especially since that has a
typo in it.

I would appreciate any help that I can get, but this is a one time thing for me.
Once I get a working framework, I'll never look back.

Thanks for your help.
Mar 20 2006
parent reply James Dunne <james.jdunne gmail.com> writes:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

starkweatherr mchsi.com wrote:
 It doesn't appear that the zip file is accessible. A working sample is just
what
 I need. Can you post the code un-zipped?
 
 The reason why I a using implib is that is the way the demo app does it. The
 code I am using came with the DMD package, and works as long as I run it from
 test.exe. If there is a better way, that is exactly what I am looking for.
 
 The reason why I am not using EXPORTS in the .def files is the error messages
 that produces. There is something wrong there also, and I have no idea what
that
 problem is either.
 
 I'm not worried about the VB side. Maybe I should explain the project.
 
 I've been writing bare frameworks for using DLLs generated by various C/C++
 compilers from VB for upload to PSC. So far I have finished VC++ 6 and BCB 5.5.
 Someone who saw the code suggested that I write one for DMC, which I had never
 heard of before. That effort is still awaiting a response to questions in the
 Command Line forum on the DMC side. Similar problems, different language.
 
 I noticed 'D' while I was trying to get DMC to work and decided to give that a
 try. It has been really frustrating to try to put together what is in the
 documentation with the demo app that comes with DMD, especially since that has
a
 typo in it.
 
 I would appreciate any help that I can get, but this is a one time thing for
me.
 Once I get a working framework, I'll never look back.
 
 Thanks for your help.
 
 

The ZIP is accessible, just not through the crappy web interface provided at digitalmars.com. Read with a real newsgroup reader, like Thunderbird and you should be fine. I'll attach the extracted code here. Derek Parnell's response's code is extremely similar to mine. Both approaches seem to work. BTW, what is PSC? ... and why are you using that abortion of a language called VB? =P -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O M-- V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e h>--->++ r+++ y+++ ------END GEEK CODE BLOCK------ James Dunne
Mar 20 2006
next sibling parent reply David L. Davis <David_member pathlink.com> writes:
In article <dvmhm3$161$1 digitaldaemon.com>, James Dunne says...
This is a multi-part message in MIME format.
--------------010903040605030506090108
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

James, I really wish that you wouldn't bash my "Bread and Butter" language (Visual Basic). I've made a pretty good living for my family and myself over the pass decade with it, and like any programming language, it has its strengths and weaknesses. It's just one of many tools, and as you should know, not every tool works for every job at hand...so don't limit yourself or others. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Mar 20 2006
parent reply James Dunne <james.jdunne gmail.com> writes:
David L. Davis wrote:
 In article <dvmhm3$161$1 digitaldaemon.com>, James Dunne says...
 
This is a multi-part message in MIME format.
--------------010903040605030506090108
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

James, I really wish that you wouldn't bash my "Bread and Butter" language (Visual Basic). I've made a pretty good living for my family and myself over the pass decade with it, and like any programming language, it has its strengths and weaknesses. It's just one of many tools, and as you should know, not every tool works for every job at hand...so don't limit yourself or others. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html

I didn't bash it, I just called it an abortion. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O M-- V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e h>--->++ r+++ y+++ ------END GEEK CODE BLOCK------ James Dunne
Mar 20 2006
parent reply David L. Davis <SpottedTiger yahoo.com> writes:
In article <dvn9hc$11mr$1 digitaldaemon.com>, James Dunne says...
David L. Davis wrote:
 In article <dvmhm3$161$1 digitaldaemon.com>, James Dunne says...
 
This is a multi-part message in MIME format.
--------------010903040605030506090108
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

James, I really wish that you wouldn't bash my "Bread and Butter" language (Visual Basic). I've made a pretty good living for my family and myself over the pass decade with it, and like any programming language, it has its strengths and weaknesses. It's just one of many tools, and as you should know, not every tool works for every job at hand...so don't limit yourself or others. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html

I didn't bash it, I just called it an abortion.

James, I find the very word "abortion" to be a very repulse and ugly, far worst than even bashing other languages...tho I tried to ignore that part of your comment and stick with your language reference. If you don't like VB or Java or whatever that's fine, just said D's better then VB or Java or whatever, but I really think your last statement has crossed a line that you shouldn't have. For what it's worth, remember that your comments are read by a Global Community, and you shouldn't go out of your way to offend others. David L. P.S. If you think you comments are funny...think again. I'm not laughing! ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Mar 20 2006
next sibling parent reply Rory Starkweather <Rory_member pathlink.com> writes:
It comes back pretty quickly when you have a starting point.

// uppercase.d
import std.string;      // For uppercase
import std.c.stdio;     // For printf

int main(char[][] Args)
{
char cChar;         // Declare a variable (cChar) of type char

if (Args.length > 1)
{
printf("Received %d args.\n", Args);
}

//uppercase returns the xth letter of the 26, capitalized.
cChar = uppercase[12];   
// Remember to use %c for char values.
// If you use %s for string, you get an access error.
// This should return 'M'
printf ("I'm hoping this will print a letter: %c\n", cChar);
return 0;
}
Mar 20 2006
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 21 Mar 2006 02:28:53 +0000 (UTC), Rory Starkweather  
<Rory_member pathlink.com> wrote:
 It comes back pretty quickly when you have a starting point.

 // uppercase.d
 import std.string;      // For uppercase
 import std.c.stdio;     // For printf

 int main(char[][] Args)
 {
 char cChar;         // Declare a variable (cChar) of type char

 if (Args.length > 1)
 {
 printf("Received %d args.\n", Args);

Don't you mean: printf("Received %d args.\n",Args.length); the odd thing is, it doesn't crash without it!?
 }

 //uppercase returns the xth letter of the 26, capitalized.
 cChar = uppercase[12];
 // Remember to use %c for char values.
 // If you use %s for string, you get an access error.
 // This should return 'M'
 printf ("I'm hoping this will print a letter: %c\n", cChar);
 return 0;
 }

You should probably start to use writef instead of printf. Regan
Mar 20 2006
parent reply Rory Starkweather <Rory_member pathlink.com> writes:
 if (Args.length > 1)
 {
 printf("Received %d args.\n", Args);

Don't you mean: printf("Received %d args.\n",Args.length); the odd thing is, it doesn't crash without it!?

Good point. Interesting too because the number printed out is correct. }
You should probably start to use writef instead of printf.

This is my third day with D. I had planned to wait until tomorrow for the hard stuff. ;}
Mar 20 2006
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 21 Mar 2006 06:28:20 +0000 (UTC), Rory Starkweather  
<Rory_member pathlink.com> wrote:
 if (Args.length > 1)
 {
 printf("Received %d args.\n", Args);

Don't you mean: printf("Received %d args.\n",Args.length); the odd thing is, it doesn't crash without it!?

Good point. Interesting too because the number printed out is correct.

I've just realised why :) An array in D is essentially a structure in the form: struct array { int length; void *data; } When you pass an array to printf you're essentially passing the address of the start of that struct, in other words the address of the length 'int'. It's the reason why this also works: char[] test = "test"; printf("%.*s\n",test); the length int is found first, and is used for the '*'. The data pointer is next and is used for the 's'.
 You should probably start to use writef instead of printf.

This is my third day with D. I had planned to wait until tomorrow for the hard stuff. ;}

No worries. Regan
Mar 21 2006
parent Rory Starkweather <Rory_member pathlink.com> writes:
It's the reason why this also works:

char[] test = "test";
printf("%.*s\n",test);

I'm glad you reminded me of that.
Mar 21 2006
prev sibling next sibling parent John Reimer <terminal.node gmail.com> writes:
David L. Davis wrote:

 
 James, I find the very word "abortion" to be a very repulse and ugly, far worst
 than even bashing other languages...tho I tried to ignore that part of your
 comment and stick with your language reference. If you don't like VB or Java or
 whatever that's fine, just said D's better then VB or Java or whatever, but I
 really think your last statement has crossed a line that you shouldn't have.
For
 what it's worth, remember that your comments are read by a Global Community,
and
 you shouldn't go out of your way to offend others.
 
 David L.
 
 P.S. If you think you comments are funny...think again. I'm not laughing!
 
 -------------------------------------------------------------------
  "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
 -------------------------------------------------------------------
  
  MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html

Good points. I agree with you David. -JJR
Mar 20 2006
prev sibling parent reply James Dunne <james.jdunne gmail.com> writes:
David L. Davis wrote:
 In article <dvn9hc$11mr$1 digitaldaemon.com>, James Dunne says...
 
David L. Davis wrote:

In article <dvmhm3$161$1 digitaldaemon.com>, James Dunne says...


This is a multi-part message in MIME format.
--------------010903040605030506090108
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

James, I really wish that you wouldn't bash my "Bread and Butter" language (Visual Basic). I've made a pretty good living for my family and myself over the pass decade with it, and like any programming language, it has its strengths and weaknesses. It's just one of many tools, and as you should know, not every tool works for every job at hand...so don't limit yourself or others. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html

I didn't bash it, I just called it an abortion.

James, I find the very word "abortion" to be a very repulse and ugly, far worst than even bashing other languages...tho I tried to ignore that part of your comment and stick with your language reference. If you don't like VB or Java or whatever that's fine, just said D's better then VB or Java or whatever, but I really think your last statement has crossed a line that you shouldn't have. For what it's worth, remember that your comments are read by a Global Community, and you shouldn't go out of your way to offend others. David L. P.S. If you think you comments are funny...think again. I'm not laughing! ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html

Actually I did think it was rather humerous, but obviously not to everyone. I see your point now. I meant not to offend anyone. Please accept my apology. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O M-- V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e h>--->++ r+++ y+++ ------END GEEK CODE BLOCK------ James Dunne
Mar 21 2006
parent David L. Davis <SpottedTiger yahoo.com> writes:
In article <dvp7ak$i6d$1 digitaldaemon.com>, James Dunne says...
David L. Davis wrote:
 In article <dvn9hc$11mr$1 digitaldaemon.com>, James Dunne says...
 
 James, I find the very word "abortion" to be a very repulse and ugly, 
 far worst than even bashing other languages...tho I tried to ignore 
 that part of your comment and stick with your language reference. If 
 you don't like VB or Java or whatever that's fine, just said D's better 
 than VB or Java or whatever, but I really think your last statement has 
 crossed a line that you shouldn't have. For what it's worth, remember 
 that your comments are read by a Global Community, and you shouldn't 
 go out of your way to offend others.
 
 David L.
 
 P.S. If you think your comments are funny...think again. I'm not laughing!
 

Actually I did think it was rather humerous, but obviously not to everyone. I see your point now. I meant not to offend anyone. Please accept my apology. James Dunne

James, I can only speak for myself, but I do accept your apology. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Mar 21 2006
prev sibling parent reply starkweatherr mchsi.com writes:
The ZIP is accessible, just not through the crappy web interface 
provided at digitalmars.com.  Read with a real newsgroup reader, like 
Thunderbird and you should be fine.  I'll attach the extracted code here.

Derek Parnell's response's code is extremely similar to mine.  Both 
approaches seem to work.

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

I use Mozilla, but I gave up on NewsGroups after trying to get some information on Sun Sparcstations and ending up with weather reports from Britain. PSC is Planet Source Code. One of the users there saw the work I had done on using DLLs created by Borland C++ Builder 5.5 and MS VC++ 6 and asked me to take a look at DMC. While looking at DMC I noticed 'D'. The first time I had ever heard of it. VB really is a bad language, but the goal is to use it only for the user interface, which it does reasonably well, and do all of the actual work with DLLs. For the type of application I write (latest was for calculating filled volume of horizontal cylindrical tanks with hemispherical end caps) it seems to make sense. That application has two buttons, two text boxes and two labels. Everything else is under the hood. Since my template even has one of the buttons, it took about five minutes to build the screen. The application before that was to convert any positive integer less than 2,000,000 in any number base between 2 and 36 to any other number base between 2 and 36. I think you can see why I don't want to waste time on building forms. D, however, may not be the ultimate. Have you ever taken a look at Oberon-3, Wirth's latest? If he didn't insist on using that silly interface and flat file system, I would say that is about the best programming language available.
Mar 20 2006
parent James Dunne <james.jdunne gmail.com> writes:
starkweatherr mchsi.com wrote:
The ZIP is accessible, just not through the crappy web interface 
provided at digitalmars.com.  Read with a real newsgroup reader, like 
Thunderbird and you should be fine.  I'll attach the extracted code here.

Derek Parnell's response's code is extremely similar to mine.  Both 
approaches seem to work.

BTW, what is PSC?  ... and why are you using that abortion of a language 
called VB? =P

I use Mozilla, but I gave up on NewsGroups after trying to get some information on Sun Sparcstations and ending up with weather reports from Britain. PSC is Planet Source Code. One of the users there saw the work I had done on using DLLs created by Borland C++ Builder 5.5 and MS VC++ 6 and asked me to take a look at DMC. While looking at DMC I noticed 'D'. The first time I had ever heard of it. VB really is a bad language, but the goal is to use it only for the user interface, which it does reasonably well, and do all of the actual work with DLLs. For the type of application I write (latest was for calculating filled volume of horizontal cylindrical tanks with hemispherical end caps) it seems to make sense.

The last real work I did with VB6 involved calculating the filled volume of _vertical_ cylindrical tanks with 2:1 elliptical heads on either end.
 That application has two buttons, two text boxes and two labels.
 Everything else is under the hood. Since my template even has one of the
 buttons, it took about five minutes to build the screen. The application before
 that was to convert any positive integer less than 2,000,000 in any number base
 between 2 and 36 to any other number base between 2 and 36. I think you can see
 why I don't want to waste time on building forms.

I completely understand its use in GUIs, and I've been there myself. I found D's DUI library to be intuitive and easy to use. I wrote a nice little "Project Timer" application when I was back in college under an independent study course. I wrote it to log the hours I was working on for the *real* project.
 
 D, however, may not be the ultimate. Have you ever taken a look at Oberon-3,
 Wirth's latest? If he didn't insist on using that silly interface and flat file
 system, I would say that is about the best programming language available.
 
 

I haven't yet, but I'll give it a look. I don't know who Wirth is, but I recognize the name. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O M-- V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e h>--->++ r+++ y+++ ------END GEEK CODE BLOCK------ James Dunne
Mar 20 2006
prev sibling parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 19 Mar 2006 00:51:15 +0000 (UTC), strkweatherr mchsi.com wrote:

 I'm having the same problem with DigitalMars D as I had with DigitalMars C/C++,
 but nobody over there has answered any of my questions. 
 
 I started with the MyDLL package and modified it so that it accepts two ints
and
 returns the sum. Test.exe works fine, but VB says the .lib file doesn't exist.
I
 am assuming that is because it isn't in a recognizable format.

 ...

 Does anyone have a piece of source code, that works, for a DLL that is
 accessible from non-D programs and that is less than 50 lines long?

I just had a go now, following the instructions in the DigitalMars docs. First I took the 'mydll' source in the docs and saved it to a file called 'mydll.d'. Then I created a new file called 'testdll.d' and here is its source ... --------testdll.d----------- import mydll; import std.math; extern (Windows) { int sqrab(short a, short b) { // Calculates the square root of the sum of two squares. // (eg. used to find the length of the hypotenuse) return cast(int)sqrt((cast(real)a * cast(real)a) + (cast(real)b * cast(real)b)); } } -------------- I then created a .DEF file which contained ... -------------testdll.def---------------- LIBRARY TESTDLL DESCRIPTION 'My test DLL written in D' EXETYPE NT CODE PRELOAD DISCARDABLE DATA PRELOAD SINGLE EXPORTS sqrab 2 ------------------------------------------ I next compiled it with the following command line ... dmd -oftestdll.dll mydll.d testdll.d testdll.def Then moved the testdll.dll file to the windows system32 folder, Finally I created a VB module that contained the line ... Public Declare Function sqrab Lib "testdll" _ (ByVal A As Integer, ByVal B As Integer) As Long and the VB form used the DLL command as ... Sub Form_Click() Dim x As Integer Dim y As Integer x = CInt(Text1.Text) y = CInt(Text2.Text) result = sqrab(x, y) Label1.Caption = CStr(result) Label2.Caption = CStr(Sqr(CLng(x) * CLng(x) + CLng(y) * CLng(y))) End Sub And it all just worked. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 20/03/2006 6:04:50 PM
Mar 19 2006
parent starkweatherr mchsi.com writes:
Indeed it does work. Thanks.

Now, a post-mortem, if you don't mind.

I assume that, since it worked, the file you called mydll.d is the one with the
DllMain entry point in it and that you didn't make any changes to it?

Nothing new in testdll.d.

The differences in the .def file seem to be significant. I'll need to experiment
to find out why, but, with your .def file I don't get the messages about not
being able to export the function.

The compile part is very different from the sample. I don't work with command
line stuff very often, so please bear with me. The build.bat file I used came
with the demo app. Now it seems clear that the second call to dmd was just to
compile test.dll. The call to implib, though . . . I'm still having trouble
grasping the multiple different ways to create a dll. In this approach you are
using the .def file without implib. As I understand it, if you use implib you
don't need the .def file, or am I lost again?

Anyway, this works, and I will post it with proper credit to you. D looks
interesting. naturally, it has annnoying similarities to C++, but it seems a lot
cleaner. The reason why I got into this in the beginning is that VB, although
great for RAD, lacks both power and sophistication. C++ and D have the power,
but are pretty much useless for RAD. The obvious solution is a combination.
Unfortunately, my programming path went straight from C to VB, with no stop at
C++, so I need the C++/D part to be as easy as possible with eht emphasis on
ease of use of DLLs.

Thanks a lot for your help.

Rory
Mar 20 2006