Hey guys,
I downloaded the ATI AGS (ATI GPU Services) Libary, and am attempting to retrieve some basic driver information using this API, from C#. The ATI AGS library is available for download from here:
http://developer.amd.com/gpu/ags/Pages/default.aspx
I wrote a little bit of C# code to pull driver information from the GPU using the AGS API, but I'm having some trouble calling the unmanaged method. I've tried all sorts of different permutations of DllImportAttribute parameters, to no avail. I'm getting either a MarshalDirectiveException or a pInvokeStackImbalance.
I'm pretty sure that this is all due to an incorrect P/Invoke signature, but I have exhausted my knowledge of this API.
By the way, as an aside, you'll see that I'm using the 32-bit DLL, and I seem to be getting farther with it, but when I use the 64-bit DLL, I get a BadImageFormatException.
Here is the code that I'm using:
[DllImport(
"atiags.dll"
, PreserveSig=false
, ExactSpelling=true
, ThrowOnUnmappableChar=true
, CharSet=CharSet.Unicode
, EntryPoint="agsDriverGetVersionInfo"
)]
public static extern void agsDriverGetVersionInfo(
[MarshalAs(UnmanagedType.Struct)]
out agsDriverVersionInfoStruct DriverInfo
);
public static agsDriverVersionInfoStruct GetAgsDriverVersion()
{
agsDriverVersionInfoStruct DriverInfo = new agsDriverVersionInfoStruct();
agsDriverGetVersionInfo(out DriverInfo);
}
public struct agsDriverVersionInfoStruct
{
[MarshalAs(UnmanagedType.LPTStr)]
public string strDriverVersion;
[MarshalAs(UnmanagedType.LPStr)]
public string strCatalystVersion;
[MarshalAs(UnmanagedType.LPStr)]
public string strCatalystWebLink;
}
Any ideas?
Edit: Here is the definition of the ATIAGSDriverGetVersionInfo() function in ati_ags.h. According to the ATI AGS documentation (a PDF included in the download), it says to define _ATI_AGS_USE_DLL, so I added this line at the top of my C# class code file:
Documentation Quote
Determine if AGS functionality will be accessed through a dll or static lib. If the dll option is chosen, make sure to define _ATI_AGS_USE_DLL in your project properties. If the static lib option is chosen, no special token needs to be defined.
__inline AGSReturnCode ATIAGSDriverGetVersionInfo( AGSDriverVersionInfoStruct *lpDriverVersionInfo )
{
AGSReturnCode iReturnValue = AGS_SUCCESS;
// Validate params
if ( NULL == lpDriverVersionInfo )
{
return AGS_FAILURE;
}
#ifdef _ATI_AGS_USE_DLL
// Load the lib
HINSTANCE lib = NULL;
lib = LoadLibrary(TEXT("atiags.dll"));
if (NULL == lib)
{
lib = LoadLibrary(TEXT("atiags64.dll"));
if (NULL == lib)
{
return AGS_FAILURE;
}
}
// Get the function pointer
AGSDRIVERGETVERSIONINFO agsDriverGetVersionInfo = NULL;
agsDriverGetVersionInfo = (AGSDRIVERGETVERSIONINFO)GetProcAddress(lib, "agsDriverGetVersionInfo");
if (NULL == agsDriverGetVersionInfo)
{
FreeLibrary(lib);
return AGS_FAILURE;
}
#endif // _ATI_AGS_USE_DLL
// Get the number of GPUs
iReturnValue = agsDriverGetVersionInfo( lpDriverVersionInfo );
#ifdef _ATI_AGS_USE_DLL
// Free the lib
FreeLibrary(lib);
#endif // _ATI_AGS_USE_DLL
return iReturnValue;
}