Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
August 18, 2011 making a really simple dll. | ||||
---|---|---|---|---|
| ||||
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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles McAnany | > 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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Example: https://bitbucket.org/trass3r/matd/src/tip/examples/mmfile/ |
August 18, 2011 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kai Meyer | 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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r Attachments:
| "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 Re: making a really simple dll. | ||||
---|---|---|---|---|
| ||||
Posted in reply to maarten van damme | 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.
|
Copyright © 1999-2021 by the D Language Foundation