Thread overview
making a really simple dll.
Aug 18, 2011
Charles McAnany
Aug 18, 2011
Trass3r
Aug 18, 2011
Trass3r
Aug 18, 2011
Adam D. Ruppe
Aug 18, 2011
Trass3r
Aug 18, 2011
Kai Meyer
Aug 18, 2011
Trass3r
Aug 19, 2011
maarten van damme
Aug 19, 2011
Trass3r
August 18, 2011
Hi, all. I'm trying to write some efficient code for a macro in vba using a language
that I enjoy. I don't need any fancy operating system interaction, I just want to
write
int foo(int arg){
   return arg; //actual computation a bit more involved.
}

Compile it to dll and call it with vba.

I looked at the dll documentation and I'm baffled by the time I get to the first line: __gshared HINSTANCE g_hInst; and then it starts talking about dll_process_attach. I don't want to attach processes, I want to compute an integer.

Is there a simple way to make dlls, or is it going to be ugly to even write the
"Hello World" of dlls?
Cheers,
Charles
August 18, 2011
> I looked at the dll documentation and I'm baffled by the time I get to the first
> line: __gshared HINSTANCE g_hInst; and then it starts talking about
> dll_process_attach. I don't want to attach processes, I want to compute an integer.

The Dllmain is needed so the D runtime is properly initialized.
Just copy the code http://www.d-programming-language.org/dll.html into a dllmain.d and put your actual code in other modules.
You don't need to do the EXPORTS shit in the .def file though, just use the export keyword.
August 18, 2011
Example:
https://bitbucket.org/trass3r/matd/src/tip/examples/mmfile/
August 18, 2011
We should make a mixin template DllMain that has a generic main.

import std.dll;

void myDllProc() { }

mixin DllMain!myDllProc;


I did this with my cgi.d and like it alot - the templated main saves a lot of boilerplate.
August 18, 2011
Am 18.08.2011, 21:17 Uhr, schrieb Adam D. Ruppe <destructionator@gmail.com>:
> We should make a mixin template DllMain that has a generic main.

We should also have a -shared switch that transparently includes all of the boilerplate crap:
particularly the .def file, maybe even a default DllMain if none exists.
August 18, 2011
On 08/18/2011 01:32 PM, Trass3r wrote:
> Am 18.08.2011, 21:17 Uhr, schrieb Adam D. Ruppe
> <destructionator@gmail.com>:
>> We should make a mixin template DllMain that has a generic main.
>
> We should also have a -shared switch that transparently includes all of
> the boilerplate crap:
> particularly the .def file, maybe even a default DllMain if none exists.

This would be my vote. -shared will:
1) check if there is a DllMain defined at the end, and if not, sticks a generic one in there
2) check if there are any exported functions (via .def or export()), if not, export them all

That way, the OP's original simple 1 function d file compiles to a dll.

Same goes for the Linux side. Default constructor and destructors that initialize and destroy the D runtime if there aren't any defined at the end of the compilation.

-Kai Meyer
August 18, 2011
Am 18.08.2011, 21:42 Uhr, schrieb Kai Meyer <kai@unixlords.com>:
> 2) check if there are any exported functions (via .def or export()), if not, export them all

That's insane. Larger projects have tons of functions and may only need to export a few.
The language includes the export keyword to export functions and people should use it.
dmd just needs to generate a .def file to make Optstink create a dll.
August 19, 2011
"as for the linux side"
I though dmd was unable to generate shared libs on linux?

It would be cool to have a mixin "shared" that when compiled on windows generates a windows dll and if compiler on linux generates a linux shared lib :)

2011/8/18 Trass3r <un@known.com>

> Am 18.08.2011, 21:42 Uhr, schrieb Kai Meyer <kai@unixlords.com>:
>
>  2) check if there are any exported functions (via .def or export()), if
>> not, export them all
>>
>
> That's insane. Larger projects have tons of functions and may only need to
> export a few.
> The language includes the export keyword to export functions and people
> should use it.
> dmd just needs to generate a .def file to make Optstink create a dll.
>


August 19, 2011
Am 19.08.2011, 04:29 Uhr, schrieb maarten van damme <maartenvd1994@gmail.com>:

> "as for the linux side"
> I though dmd was unable to generate shared libs on linux?

But GDC and LDC are.