Access violation when exiting program

Frank Fuente a at b.com
Tue Jun 4 07:06:28 PDT 2013


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.


More information about the Digitalmars-d-learn mailing list