D2H

Everlast Everlast at For.Ever
Wed Aug 1 18:27:08 UTC 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.




More information about the Digitalmars-d-learn mailing list