A C/C++ Sample Application for Linux and Windows(XP, Vista and Windows 7); 32bit and 64bit
#if defined (LINUX)
#include "../include/adl_sdk.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#else
#include <windows.h>
#include <tchar.h>
#include "..\include\adl_sdk.h"
#endif
#include <stdio.h>
typedef int ( *ADL_MAIN_CONTROL_CREATE )(ADL_MAIN_MALLOC_CALLBACK, int );
typedef int ( *ADL_MAIN_CONTROL_DESTROY )();
typedef int ( *ADL_ADAPTER_NUMBEROFADAPTERS_GET ) ( int* );
typedef int ( *ADL_ADAPTER_ADAPTERINFO_GET ) ( LPAdapterInfo, int );
typedef int ( *ADL_DISPLAY_COLORCAPS_GET ) ( int, int, int *, int * );
typedef int ( *ADL_DISPLAY_COLOR_GET ) ( int, int, int, int *, int *, int *, int *, int * );
typedef int ( *ADL_DISPLAY_COLOR_SET ) ( int, int, int, int );
typedef int ( *ADL_DISPLAY_DISPLAYINFO_GET ) ( int, int *, ADLDisplayInfo **, int );
void* __stdcall ADL_Main_Memory_Alloc ( int iSize )
{
void* lpBuffer = malloc ( iSize );
return lpBuffer;
}
void __stdcall ADL_Main_Memory_Free ( void** lpBuffer )
{
if ( NULL != *lpBuffer )
{
free ( *lpBuffer );
*lpBuffer = NULL;
}
}
#if defined (LINUX)
void * GetProcAddress( void * pLibrary, const char * name)
{
return dlsym( pLibrary, name);
}
void Sleep( int time)
{
usleep(time*1000);
}
#endif
int main (int c,char* k[],char* s[])
{
#if defined (LINUX)
void *hDLL;
#else
HINSTANCE hDLL;
#endif
ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create;
ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy;
ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get;
ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get;
ADL_DISPLAY_COLORCAPS_GET ADL_Display_ColorCaps_Get;
ADL_DISPLAY_COLOR_GET ADL_Display_Color_Get;
ADL_DISPLAY_COLOR_SET ADL_Display_Color_Set;
ADL_DISPLAY_DISPLAYINFO_GET ADL_Display_DisplayInfo_Get;
LPAdapterInfo lpAdapterInfo = NULL;
LPADLDisplayInfo lpAdlDisplayInfo = NULL;
int i, j;
int iNumberAdapters;
int iAdapterIndex;
int iDisplayIndex;
int iNumDisplays;
int iColorCaps, iValidBits;
int iCurrent, iDefault, iMin, iMax, iStep;
#if defined (LINUX)
hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
#else
hDLL = LoadLibrary("atiadlxx.dll");
if (hDLL == NULL)
hDLL = LoadLibrary("atiadlxy.dll");
#endif
if (NULL == hDLL)
{
printf("ADL library not found!\n");
return 0;
}
ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL_Main_Control_Create");
ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL_Main_Control_Destroy");
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get");
ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) GetProcAddress(hDLL,"ADL_Adapter_AdapterInfo_Get");
ADL_Display_DisplayInfo_Get = (ADL_DISPLAY_DISPLAYINFO_GET) GetProcAddress(hDLL,"ADL_Display_DisplayInfo_Get");
ADL_Display_ColorCaps_Get = (ADL_DISPLAY_COLORCAPS_GET)GetProcAddress(hDLL,"ADL_Display_ColorCaps_Get");
ADL_Display_Color_Get = (ADL_DISPLAY_COLOR_GET)GetProcAddress(hDLL,"ADL_Display_Color_Get");
ADL_Display_Color_Set = (ADL_DISPLAY_COLOR_SET)GetProcAddress(hDLL,"ADL_Display_Color_Set");
if ( NULL == ADL_Main_Control_Create ||
NULL == ADL_Main_Control_Destroy ||
NULL == ADL_Adapter_NumberOfAdapters_Get ||
NULL == ADL_Adapter_AdapterInfo_Get ||
NULL == ADL_Display_DisplayInfo_Get ||
NULL == ADL_Display_ColorCaps_Get ||
NULL == ADL_Display_Color_Get ||
NULL == ADL_Display_Color_Set )
{
printf("ADL's API is missing!\n");
return 0;
}
if ( ADL_OK != ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1) )
{
printf("ADL Initialization Error!\n");
return 0;
}
if ( ADL_OK != ADL_Adapter_NumberOfAdapters_Get ( &iNumberAdapters ) )
{
printf("Cannot get the number of adapters!\n");
return 0;
}
if ( 0 < iNumberAdapters )
{
lpAdapterInfo = malloc ( sizeof (AdapterInfo) * iNumberAdapters );
memset ( lpAdapterInfo,'\0', sizeof (AdapterInfo) * iNumberAdapters );
ADL_Adapter_AdapterInfo_Get (lpAdapterInfo, sizeof (AdapterInfo) * iNumberAdapters);
}
for ( i = 0; i < iNumberAdapters; i++ )
{
iAdapterIndex = lpAdapterInfo[ i ].iAdapterIndex;
ADL_Main_Memory_Free ( &lpAdlDisplayInfo );
if (ADL_OK != ADL_Display_DisplayInfo_Get (lpAdapterInfo[i].iAdapterIndex, &iNumDisplays, &lpAdlDisplayInfo, 0))
continue;
for ( j = 0; j < iNumDisplays; j++ )
{
if ( ( ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED | ADL_DISPLAY_DISPLAYINFO_DISPLAYMAPPED ) !=
( ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED | ADL_DISPLAY_DISPLAYINFO_DISPLAYMAPPED &
lpAdlDisplayInfo[ j ].iDisplayInfoValue ) )
continue;
if ( iAdapterIndex != lpAdlDisplayInfo[ j ].displayID.iDisplayLogicalAdapterIndex )
continue;
iDisplayIndex = lpAdlDisplayInfo[ j ].displayID.iDisplayLogicalIndex;
ADL_Display_ColorCaps_Get( iAdapterIndex, iDisplayIndex, &iColorCaps, &iValidBits);
iColorCaps &= iValidBits;
if ( ADL_DISPLAY_COLOR_BRIGHTNESS & iColorCaps )
{
if ( ADL_OK == ADL_Display_Color_Get( iAdapterIndex, iDisplayIndex, ADL_DISPLAY_COLOR_BRIGHTNESS,
&iCurrent, &iDefault, &iMin, &iMax, &iStep))
{
ADL_Display_Color_Set( iAdapterIndex, iDisplayIndex, ADL_DISPLAY_COLOR_BRIGHTNESS, iMin / 2 );
Sleep( 500 );
ADL_Display_Color_Set( iAdapterIndex, iDisplayIndex, ADL_DISPLAY_COLOR_BRIGHTNESS, iCurrent );
Sleep( 500 );
ADL_Display_Color_Set( iAdapterIndex, iDisplayIndex, ADL_DISPLAY_COLOR_BRIGHTNESS, iMax / 4 );
Sleep( 500 );
ADL_Display_Color_Set( iAdapterIndex, iDisplayIndex, ADL_DISPLAY_COLOR_BRIGHTNESS, iCurrent );
Sleep( 500 );
}
}
}
}
ADL_Main_Memory_Free ( &lpAdapterInfo );
ADL_Main_Memory_Free ( &lpAdlDisplayInfo );
ADL_Main_Control_Destroy ();
#if defined (LINUX)
dlclose(hDLL);
#else
FreeLibrary(hDLL);
#endif
return 0;
}