Thread overview |
---|
August 01, 2018 D2H | ||||
---|---|---|---|---|
| ||||
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 Re: D2H | ||||
---|---|---|---|---|
| ||||
Posted in reply to Everlast | 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 Re: D2H | ||||
---|---|---|---|---|
| ||||
Posted in reply to Everlast | 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 Re: D2H | ||||
---|---|---|---|---|
| ||||
Posted in reply to Everlast | 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.
|
Copyright © 1999-2021 by the D Language Foundation