Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/acf3421cb60f361fd823 to your computer and use it in GitHub Desktop.
Save kumatti1/acf3421cb60f361fd823 to your computer and use it in GitHub Desktop.
COM版SetColor
//#define UNICODE
#import "igfxsrvc.exe"
#include <windows.h>
#include <stdio.h>
#include <comdef.h>
using namespace IGFXSRVCLib;
void GetName()
{
try {
IEDIDPtr pED;
HRESULT hr = pED.CreateInstance(__uuidof(EDID));
if (FAILED(hr)) _com_issue_error(hr);
DWORD dwDevice = 0;
for(int i =0;i<32;i++)
{
try {
dwDevice = 1<<i;
_bstr_t bstr;
hr = pED->GetSerialNumber(dwDevice, bstr.GetAddress() );
if(hr==S_OK) break;
}
catch (_com_error& err) {
//if(err.Error() == E_FAIL )
}
}
IColorPtr pColor;
hr = pColor.CreateInstance(__uuidof(Color));
if (FAILED(hr)) _com_issue_error(hr);
BYTE pByte[60];
pColor->GetColor(dwDevice, 60, pByte);
if (FAILED(hr)) _com_issue_error(hr);
long value=0;
pColor->get_MainScreenBrightness(dwDevice, 3, &value);
if (FAILED(hr)) _com_issue_error(hr);
char tmp[50];
sprintf(tmp,"%x", value);
MessageBoxA(0,tmp, "", MB_OK);
}
catch (_com_error& e) {
MessageBoxA(nullptr, e.ErrorMessage(), "err", MB_OK);
}
}
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{
::CoInitialize(NULL);
GetName();
::CoUninitialize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment