Thread overview
D2H
Aug 01, 2018
Everlast
Aug 01, 2018
Everlast
Aug 01, 2018
Everlast
Aug 01, 2018
Everlast
August 01, 2018
Is there any program that can take a D file and essentially make an H file for other programs to import for dll work?

I want to create the DLL's in D rather than C++ and would like to generate the H file from the D file.


August 01, 2018
On Wednesday, 1 August 2018 at 15:48:27 UTC, Everlast wrote:
> Is there any program that can take a D file and essentially make an H file for other programs to import for dll work?
>
> I want to create the DLL's in D rather than C++ and would like to generate the H file from the D file.

Also, when I try to load a dll generated by matlab(the target) it says that it is an invalid dll.

see

http://matlab.izmiran.ru/help/techdoc/matlab_external/ch2_sha6.html

Maybe you can get a simple dll to work?
August 01, 2018
On Wednesday, 1 August 2018 at 15:55:28 UTC, Everlast wrote:
> On Wednesday, 1 August 2018 at 15:48:27 UTC, Everlast wrote:
>> Is there any program that can take a D file and essentially make an H file for other programs to import for dll work?
>>
>> I want to create the DLL's in D rather than C++ and would like to generate the H file from the D file.
>
> Also, when I try to load a dll generated by matlab(the target) it says that it is an invalid dll.
>
> see
>
> http://matlab.izmiran.ru/help/techdoc/matlab_external/ch2_sha6.html
>
> Maybe you can get a simple dll to work?


import core.sys.windows.windows;
import core.sys.windows.dll;

export extern(C) int foo()
{
	return 42;
}

mixin SimpleDllMain;


and for the .h file

__declspec(dllimport) int foo();

then in matlab

unloadlibrary test
loadlibrary test
calllib('test', 'foo')

seems to work out.
August 01, 2018
On Wednesday, 1 August 2018 at 17:01:28 UTC, Everlast wrote:
> On Wednesday, 1 August 2018 at 15:55:28 UTC, Everlast wrote:
>> On Wednesday, 1 August 2018 at 15:48:27 UTC, Everlast wrote:
>>> Is there any program that can take a D file and essentially make an H file for other programs to import for dll work?
>>>
>>> I want to create the DLL's in D rather than C++ and would like to generate the H file from the D file.
>>
>> Also, when I try to load a dll generated by matlab(the target) it says that it is an invalid dll.
>>
>> see
>>
>> http://matlab.izmiran.ru/help/techdoc/matlab_external/ch2_sha6.html
>>
>> Maybe you can get a simple dll to work?
>
>
> import core.sys.windows.windows;
> import core.sys.windows.dll;
>
> export extern(C) int foo()
> {
> 	return 42;
> }
>
> mixin SimpleDllMain;
>
>
> and for the .h file
>
> __declspec(dllimport) int foo();
>
> then in matlab
>
> unloadlibrary test
> loadlibrary test
> calllib('test', 'foo')
>
> seems to work out.

To auto generate, simply set the options to generate the interface file then use something like sed

sed -i "/^\(export\)/!d" file
sed -i -e "s/export extern (C)/__declspec(dllimport)/g" file

and this will extract the exports and fix up things for matlab to use.