access violation With dll?
jklp via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 16 10:28:51 PDT 2015
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... ?)
More information about the Digitalmars-d-learn
mailing list