digitalmars.D.learn - Access violation when exiting program
- Frank Fuente (36/36) Jun 04 2013 Hi,
- Andrej Mitrovic (6/11) Jun 17 2013 From the header file[1] I can see it uses the WINAPI macro, which
- Andrej Mitrovic (2/13) Jun 17 2013 Btw, apologies for the late reply.
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.
Jun 04 2013
On Tuesday, 4 June 2013 at 14:06:29 UTC, Frank Fuente wrote:The function is declared... alias extern (C) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion;The calling convention is wrongly declared, it should be:alias extern (Windows) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion;From the header file[1] I can see it uses the WINAPI macro, which makes the function have the stdcall calling convention (extern(Windows) in D). ftp://ftp.mn-net.com/Rapid_Tests/Software/USB%20DRIVER/FTDI_USB_32BIT/FTD2XX.H
Jun 17 2013
On Tuesday, 18 June 2013 at 00:16:10 UTC, Andrej Mitrovic wrote:On Tuesday, 4 June 2013 at 14:06:29 UTC, Frank Fuente wrote:Btw, apologies for the late reply.The function is declared... alias extern (C) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion;The calling convention is wrongly declared, it should be:alias extern (Windows) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion;From the header file[1] I can see it uses the WINAPI macro, which makes the function have the stdcall calling convention (extern(Windows) in D). ftp://ftp.mn-net.com/Rapid_Tests/Software/USB%20DRIVER/FTDI_USB_32BIT/FTD2XX.H
Jun 17 2013