access violation With dll?
Taylor Hillegeist via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 16 12:25:40 PDT 2015
On Thursday, 16 July 2015 at 17:28:52 UTC, jklp wrote:
> On Thursday, 16 July 2015 at 17:22:50 UTC, jklp wrote:
>> On Thursday, 16 July 2015 at 17:04:09 UTC, Taylor Hillegeist
>> wrote:
>>> [...]
>>
>> Your proto is wrong. Your forgot the FFI convention (__cdecl =
>> extern(C)).
>> Try this instead:
>>
>> ---
>> extern(C)
>> alias Proto = void function(char*, int);
>>
>> Proto func = cast(Proto) GetProcAddress(h, "Test");
>>
>> if (func)
>> {
>> char[] STUFF;
>> STUFF.length = 5000;
>> func (STUFF.ptr , STUFF.length);
>> // prints etc...
>> }
>> ----
>
> Also i guess that the dll returns a null terminated string so
> the result has to be
> read like this:
>
> ---
> import std.string;
> printf("%s\n", fromStringz(STUFF.ptr));
> ---
>
> Otherwise you'll get a random output after the 'HELLO WORLD'.
> (wait maybe the console will automatically cut... ?)
Hey that was very useful. Thank you both! Also if you have any
good resources regarding this topic I would be interested.
More information about the Digitalmars-d-learn
mailing list