Advertisement
Guest User

IntelPWMControl

a guest
Mar 17th, 2013
7,908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. // this file is in the public domain
  2.  
  3. #include <windows.h>
  4. #include <objbase.h>
  5. #include <stdio.h>
  6.  
  7. #undef NDEBUG
  8. #include <assert.h>
  9.  
  10. struct ICUIPower : public IUnknown
  11. {
  12.   virtual HRESULT STDMETHODCALLTYPE IsSupported(LPBOOL pSupported);
  13.   virtual HRESULT STDMETHODCALLTYPE dummy1();
  14.   virtual HRESULT STDMETHODCALLTYPE dummy2();
  15.   virtual HRESULT STDMETHODCALLTYPE dummy3();
  16.   virtual HRESULT STDMETHODCALLTYPE dummy4();
  17.   virtual HRESULT STDMETHODCALLTYPE GetPWMFrequency(LPUINT puiInverterType, LPDWORD pdwPWMFreq, LPDWORD pdwErrorCodes);
  18.   virtual HRESULT STDMETHODCALLTYPE SetPWMFrequency(UINT uiInverterType, DWORD dwPWMFreq, LPDWORD pdwErrorCodes);
  19. };
  20.  
  21. int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  22. {
  23.   int targetPWMFreq = 500;
  24.   sscanf_s(lpCmdLine, "%d", &targetPWMFreq);
  25.   targetPWMFreq = max(targetPWMFreq, 50);
  26.   targetPWMFreq = min(targetPWMFreq, 1050);
  27.   assert(SUCCEEDED(CoInitialize(0)));
  28.   CLSID clsid = { 0xC332C124, 0x340D, 0x4430, { 0xAA, 0x0D, 0xC7, 0x56, 0x02, 0x87, 0x6F, 0xCC } };
  29.   IID IID_ICUIPower = { 0x299D88F9, 0x2CBD, 0x4225, { 0xBF, 0x19, 0xFC, 0xD1, 0x64, 0xC5, 0x4C, 0x3F } };
  30.   IUnknown *pUnknown;
  31.   assert(SUCCEEDED(CoCreateInstance(clsid, 0, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown)));
  32.   ICUIPower *pCUIPower;
  33.   assert(SUCCEEDED(pUnknown->QueryInterface(IID_ICUIPower, (void**)&pCUIPower)));
  34.   while (1)
  35.   {
  36.     UINT uiInverterType = 0;
  37.     DWORD dwPWMFreq = 0,
  38.           dwErrorCodes = 0;
  39.     assert(SUCCEEDED(pCUIPower->GetPWMFrequency(&uiInverterType, &dwPWMFreq, &dwErrorCodes)));
  40.     if (dwPWMFreq != targetPWMFreq)
  41.     {
  42.       dwPWMFreq = targetPWMFreq;
  43.       assert(SUCCEEDED(pCUIPower->SetPWMFrequency(uiInverterType, dwPWMFreq, &dwErrorCodes)));
  44.     }
  45.     Sleep(1000);
  46.   }
  47.   pCUIPower->Release();
  48.   pUnknown->Release();
  49.   CoUninitialize();
  50.   return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement