Hi,

The following program runs, loads the DLL, excutes the function, returns the correct value and unloads the DLL, but on exiting causes an exception:

Unhandled exception at 0x0040f9c0 in USBRelay.exe: 0xC0000005: Access violation writing location 0xffffffea.




The FT_STATUS is declared...
    alias uint FT_STATUS;

The function is declared...
alias extern (C) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion;

The main program is...

module main;

import  std.stdio,
        ftd2xx,
        core.runtime,
        std.exception,
        std.c.windows.windows;


int main(string[] argv)
{
        string  dllFilename = "FTD2XX.DLL";
        uint    libVer;

auto hDLL = enforce(cast(HMODULE)Runtime.loadLibrary(dllFilename));

        scope (exit) Runtime.unloadLibrary(hDLL);

FT_GetLibraryVersion GetLibraryVersion = enforce(cast(FT_GetLibraryVersion)GetProcAddress(hDLL, "FT_GetLibraryVersion"));

        FT_STATUS rv = GetLibraryVersion(&libVer);

        writefln("Version : %0x", libVer);

        return 0;
}

I'm sure its something stupid but nothing leaps out from the screen.
Am I using the loadLibrary and enforce correctly?

Regards, Frank.

Reply via email to