/********************************************************************************************************* ** 函数名称: InitConfData ** 函数名称: InitConfData ** ** 功能描述: 初始化配置信息,先从flash加载,如果加载失败,则以默认数据填入 ** ** 输 入: CRamMain * pRam ** ** 输 出: INT8U ** ** 全局变量: ** 调用模块: 无 ** ** 作 者: LiJin ** 日 期: 2008年9月18日 ** 备 注: **------------------------------------------------------------------------------------------------------- ** 修改人: ** 日 期: ** 备 注: **------------------------------------------------------------------------------------------------------ ********************************************************************************************************/ extern INT8U InitConfData(CRamMain *pRam) { INT8U bRet = FALSE; // if (pRam == NULL) // return FALSE; bRet = LoadConfData(pRam); if (bRet == FALSE) {//加载失败 启用默认配置 InitDefaultBinData(& pRam->BinData); } else {//成功 } //初始化内存 InitMemData(); //设置装置 SetDeviceAddr( pRam->BinData.HdCfg.CpuCfg.Port.Addr ); //根据配置启动相关的硬件 //启动通信口 InitCom( & pRam->BinData.HdCfg.CpuCfg.Port ); return bRet; }
bool GetWin7AudioState(const VolumeAction action) { IMMDevice * pEndpoint = 0; IAudioEndpointVolume * pEndptVol = 0; bool success = false; if (InitCom()) { if (pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pEndpoint) == S_OK) { if (pEndpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, 0, (void**)&pEndptVol) == S_OK) { if (pEndptVol->GetMute(&is_mute) == S_OK && action == TOGGLE_MUTE) { success = pEndptVol->SetMute(is_mute == TRUE ? FALSE : TRUE, 0) == S_OK; } // get current volume float vol = 0.0f; if (action != TOGGLE_MUTE && pEndptVol->GetMasterVolumeLevelScalar(&vol) == S_OK) { master_volume = vol; } } } } SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndpoint) UnInitCom(); return success; }
const unsigned short TestInit() { printf("Test com init \n"); com com_1; int i; InitCom(&com_1); if(com_1.m_usPokerCount != 0 || com_1.m_usScore != 0) { return 1; } for(i = 0; i < (int)MAX_SUITE - 1; i++) { if(com_1.m_szHand[i].m_usPokerCount != 0) { printf("check hand: %d %u\n", i, com_1.m_szHand[i].m_usPokerCount); return i; } } return 0; }
INT GetCurrentDesktopIndex(UINT *count) { *count = 0; IObjectArray *pObjectArray = nullptr; IVirtualDesktop *pCurrentDesktop = nullptr; if (!InitCom()) { Log("InitCom failed"); return -1; } HRESULT hr = pDesktopManagerInternal->GetDesktops(&pObjectArray); if (FAILED(hr)) { Log("pDesktopManagerInternal->GetDesktops failed %x", hr); return -1; } hr = pObjectArray->GetCount(count); if (FAILED(hr)) { Log("pObjectArray->GetCount failed %x", hr); pObjectArray->Release(); return -1; } hr = pDesktopManagerInternal->GetCurrentDesktop(&pCurrentDesktop); if (FAILED(hr)) { Log("pDesktopManagerInternal->GetCurrentDesktop failed %x", hr); pObjectArray->Release(); return -1; } int index = -1; for (UINT i = 0; i < *count && i < MAXDESKTOPS && index == -1; ++i) { IVirtualDesktop *pDesktop = nullptr; if (FAILED(pObjectArray->GetAt(i, __uuidof(IVirtualDesktop), (void**)&pDesktop))) continue; if (pDesktop == pCurrentDesktop) { index = MOVETOMENU_START + i; } pDesktop->Release(); } pObjectArray->Release(); if (pCurrentDesktop != nullptr) { pCurrentDesktop->Release(); } return index; }
int getVRAMSize() { static int mem; if (!mem) { InitCom(); mem = GetTotalVideoMemory(); } return mem * 1024 * 1024; }
UINT GetIndex() { std::wstring id_default; if (InitCom()) id_default = GetDefaultID(); UnInitCom(); for (UINT i = 0; i < endpointIDs.size(); ++i) { if (_wcsicmp(endpointIDs[i].c_str(), id_default.c_str()) == 0) return i + 1; } return 0; }
PLUGIN_EXPORT LPCWSTR GetString(void* data) { static WCHAR result[256]; wsprintf(result, L"ERROR"); if (!InitCom() || !pEnumerator) { UnInitCom(); wsprintf(result, L"ERROR - Initializing COM"); return result; } IMMDevice * pEndpoint = 0; if (pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pEndpoint) == S_OK) { IPropertyStore * pProps = 0; if (pEndpoint->OpenPropertyStore(STGM_READ, &pProps) == S_OK) { PROPVARIANT varName; PropVariantInit(&varName); if (pProps->GetValue(PKEY_Device_DeviceDesc, &varName) == S_OK) { wcsncpy(result, varName.pwszVal, 255); PropVariantClear(&varName); SAFE_RELEASE(pProps) SAFE_RELEASE(pEndpoint) UnInitCom(); return result; } else { PropVariantClear(&varName); SAFE_RELEASE(pProps) SAFE_RELEASE(pEndpoint) wsprintf(result, L"ERROR - Getting Device Description"); } } else { SAFE_RELEASE(pProps) SAFE_RELEASE(pEndpoint) wsprintf(result, L"ERROR - Getting Property"); } } else { SAFE_RELEASE(pEndpoint) wsprintf(result, L"ERROR - Getting Default Device"); } UnInitCom(); return result; }
CComInit::CComInit(void) : m_hComReadCard(INVALID_HANDLE_VALUE) ,m_hComWndScreen(INVALID_HANDLE_VALUE) ,m_hComMsg(INVALID_HANDLE_VALUE) { InitCom(); for(int i=0;i<10;i++) { int result = TryCom(i); m_canUse[i] = result; } ReadComInfo(); }
HRESULT RegisterDevice(PCWSTR devID) { HRESULT hr = S_FALSE; InitCom(); IPolicyConfig *pPolicyConfig; hr = CoCreateInstance(IID_CPolicyConfigClient, nullptr, CLSCTX_ALL, IID_IPolicyConfig, (LPVOID *)&pPolicyConfig); if (hr == S_OK) { hr = pPolicyConfig->SetDefaultEndpoint(devID, eConsole); if (hr == S_OK) { hr = pPolicyConfig->SetDefaultEndpoint(devID, eCommunications); } SAFE_RELEASE(pPolicyConfig); } UnInitCom(); return hr; }
bool SetWin7Volume(UINT volume, int offset = 0) { IMMDevice * pEndpoint = 0; IAudioEndpointVolume * pEndptVol = 0; bool success = false; if (InitCom()) { if (pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pEndpoint) == S_OK) { if (pEndpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, 0, (void**)&pEndptVol) == S_OK) { pEndptVol->SetMute(FALSE, 0); float vol = 0.0f; if (offset != 0) // change master volume + offset { float off = static_cast<float>(offset) / 100.0f; vol = master_volume + off; vol = (vol < 0.0f) ? 0.0f : ((vol > 1.0f) ? 1.0f : vol); } else { vol = (float)volume / 100.0f; } // set to volume success = pEndptVol->SetMasterVolumeLevelScalar(vol, 0) == S_OK; if (success) success = pEndptVol->GetMasterVolumeLevelScalar(&vol) == S_OK; if (success) master_volume = vol; } } } SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndpoint) UnInitCom(); return success; }
PLUGIN_EXPORT void Initialize(void** data, void* rm) { if (!InitCom()) { UnInitCom(); return; } UINT count; if (!pCollection || (S_OK != pCollection->GetCount(&count))) { UnInitCom(); return; } endpointIDs = std::vector<std::wstring>(count); for (UINT i = 0; i < count; ++i) { IMMDevice *pEndpoint = 0; // Get pointer to endpoint number i. if (pCollection->Item(i, &pEndpoint) == S_OK) { // Get the endpoint ID string. LPWSTR pwszID = 0; if (pEndpoint->GetId(&pwszID) == S_OK) { endpointIDs[i] = pwszID; } CoTaskMemFree(pwszID); } SAFE_RELEASE(pEndpoint) } UnInitCom(); GetWin7AudioState(INIT); }
void WMIMonitor(ScriptValue &s, ScriptValue *args) { HRESULT hr; int i; for (i=0; i<numWmiServers; i++) { if (!scriptstrcmp(args[0].stringVal, wmiServers[i].name)) break; } if (i == numWmiServers) { if (!srealloc(wmiServers, sizeof(WMIServer)*(numWmiServers+1))) return; InitCom(); if (FAILED(CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_SECURE_REFS, NULL))) { return; } IWbemLocator *locator; hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &locator); if (FAILED(hr)) { locator = 0; UninitCom(); return; } wmiServers[i].name = args[0].stringVal; BSTR bstr = UTF8toBSTR(args[0].stringVal->value, &args[0].stringVal->len); if (!bstr) { locator->Release(); UninitCom(); return; } wmiServers[i].services = 0; hr = locator->ConnectServer(bstr, 0, 0, 0, WBEM_FLAG_CONNECT_USE_MAX_WAIT, 0, 0, &wmiServers[i].services); freeBSTR(bstr); if (FAILED(hr)) { locator->Release(); UninitCom(); return; } args[0].stringVal->AddRef(); numWmiServers++; } wmiServers[i].refs++; BSTR bstr = UTF8toBSTR(args[1].stringVal->value, &args[1].stringVal->len); if (bstr) { IEnumWbemClassObject *penum; HRESULT res = wmiServers[i].services->CreateInstanceEnum(bstr, 0, 0, &penum); if (WBEM_S_NO_ERROR == res) { IWbemClassObject *obj; ULONG returned; while ((res=penum->Next(INFINITE, 1, &obj, &returned)) == WBEM_NO_ERROR) { obj->Release(); } penum->Release(); } //wmiServers[i].services->GetObjectW(bstr, 0, 0, freeBSTR(bstr); } }
VOID AddMenu(HWND hwnd, HMENU menu) { if (bAddedMenu == true) return; HMENU systemMenu; if ((systemMenu = GetSystemMenu(hwnd, FALSE)) == NULL) { return; } if (menu != INVALID_HANDLE_VALUE && menu != systemMenu) { return; } bAddedMenu = true; if (!InitCom()) { return; } IObjectArray *pObjectArray = nullptr; IVirtualDesktop *pCurrentDesktop = nullptr; HRESULT hr = pDesktopManagerInternal->GetDesktops(&pObjectArray); if (FAILED(hr)) { return; } UINT count; hr = pObjectArray->GetCount(&count); if (FAILED(hr)) { pObjectArray->Release(); return; } hr = pDesktopManagerInternal->GetCurrentDesktop(&pCurrentDesktop); if (FAILED(hr)) { pCurrentDesktop = nullptr; } MENUITEMINFO MoveToItem = { 0 }; MoveToItem.cbSize = sizeof(MoveToItem); MoveToItem.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | MIIM_STRING; Log("Add MoveToMenu"); MoveToItem.wID = MOVETOMENU_ID; MoveToItem.dwTypeData = TEXT("Move &To"); MoveToItem.hSubMenu = CreateMenu(); InsertMenuItem(systemMenu, SC_CLOSE, FALSE, &MoveToItem); for (UINT i = 0; i < count && i < MAXDESKTOPS; ++i) { IVirtualDesktop *pDesktop = nullptr; if (FAILED(pObjectArray->GetAt(i, __uuidof(IVirtualDesktop), (void**)&pDesktop))) continue; char desktopName[64] = { 0 }; sprintf_s(desktopName, sizeof(desktopName), "Desktop &%d", i + 1); MENUITEMINFO item = { 0 }; item.cbSize = sizeof(item); item.fMask = MIIM_CHECKMARKS | MIIM_STATE | MIIM_ID | MIIM_STRING; item.fState = (pDesktop == pCurrentDesktop) ? MFS_CHECKED : MFS_UNCHECKED; item.wID = MOVETOMENU_START + i; item.dwTypeData = desktopName; InsertMenuItem(MoveToItem.hSubMenu, -1, FALSE, &item); pDesktop->Release(); } // Create 'New Desktop' Item { MENUITEMINFO item = { 0 }; item.cbSize = sizeof(item); item.fMask = MIIM_ID | MIIM_STRING; item.fState = MFS_UNCHECKED; item.wID = MOVETOMENU_NEW; item.dwTypeData = TEXT("&New Desktop"); InsertMenuItem(MoveToItem.hSubMenu, -1, FALSE, &item); } pObjectArray->Release(); if (pCurrentDesktop != nullptr) { pCurrentDesktop->Release(); } }
/* main procedure */ int main (int argc, char **argv) { int IsFather; int i; /* we get rid of the path from program name */ ModuleName = argv[0]; /* On determine si le script a un pere */ if (argc>=8) IsFather=(argv[7][0]!=(char)161); else IsFather=1; signal (SIGPIPE, DeadPipe); signal (SIGINT, DeadPipe); /* cleanup on other ways of closing too */ signal (SIGHUP, DeadPipe); signal (SIGQUIT, DeadPipe); signal (SIGTERM, DeadPipe); if (argc < 6) { fprintf(stderr,"%s must be started by Fvwm.\n", ModuleName); exit(1); } else if(argc>=7) { ScriptName = argv[6]; ref = strtol(argv[4], NULL, 16); if (ref == 0) ref = None; fd[0] = atoi(argv[1]); fd[1] = atoi(argv[2]); SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST| M_MAP| M_RES_NAME| M_RES_CLASS| M_CONFIG_INFO| M_END_CONFIG_INFO| M_WINDOW_NAME); /* Enregistrement des arguments du script */ x11base=(X11base*) calloc(1,sizeof(X11base)); x11base->TabArg[0]=ModuleName; for (i=8-IsFather;i<argc;i++) x11base->TabArg[i-7+IsFather]=argv[i]; } else { fprintf(stderr,"%s requires only the path of the script.\n", ModuleName); exit(1); } ParseOptions(); SendText(fd,"Send_WindowList",0); ReadConfig(ScriptName); /* Lecture et analyse du script */ InitCom(); /* Fonction d'initialisation de TabCom et TabFunc */ BuildGUI(IsFather); /* Construction des boutons et de la fenetre */ ReadFvwmScriptArg(argc,argv,IsFather); MainLoop(); return 0; }
CMatlabEngine::CMatlabEngine(bool bDedicated) : m_bInitialized(false) { #ifndef _UNICODE m_pBuffer=new WCHAR[1024]; m_uBufferSize=1024; #endif m_pMtlbDispApp = 0; m_bstrWorkspace = ::SysAllocString( L"base" ); m_dpNoArgs.cArgs=0; m_dpNoArgs.cNamedArgs=0; m_dpNoArgs.rgdispidNamedArgs=NULL; m_dpNoArgs.rgvarg=NULL; // Get the Class Identifier for Matlab Application Object, // which is a globally unique identifier (GUID) OLECHAR FAR* szFunction; CLSID clsid; if (bDedicated) m_hr=::CLSIDFromProgID(OLESTR("Matlab.Application.Single"), &clsid); else m_hr=::CLSIDFromProgID(OLESTR("Matlab.Application"), &clsid); if (FAILED(m_hr)) return; // Create an instance of the Matlab application and obtain the pointer // to the application's IUnknown interface IUnknown* pUnk; InitCom(); // just in case client code neglected to call CoInitialize() // m_hr = ::CoCreateInstance(clsid, NULL, CLSCTX_SERVER,IID_IUnknown,(void**) &pUnk); m_hr = ::CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IUnknown, (void**) &pUnk); if (FAILED(m_hr)) return; // Query IUnknown to retrieve a pointer to the application IDispatch // interface m_hr = pUnk ->QueryInterface(IID_IDispatch, (void**)&m_pMtlbDispApp); if (FAILED(m_hr)) return; // Get the Dispatch Identifiers szFunction = OLESTR("GetFullMatrix"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_GetFullMatrix); if (FAILED(m_hr)) return; szFunction = OLESTR("PutFullMatrix"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_PutFullMatrix); if (FAILED(m_hr)) return; szFunction = OLESTR("Execute"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_Execute); if (FAILED(m_hr)) return; szFunction = OLESTR("MinimizeCommandWindow"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_MinimizeCommandWindow); if (FAILED(m_hr)) return; szFunction = OLESTR("MaximizeCommandWindow"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_MaximizeCommandWindow); if (FAILED(m_hr)) return; #ifdef MATLAB_VERSION_6 szFunction = OLESTR("GetCharArray"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_GetCharArray); if (FAILED(m_hr)) return; szFunction = OLESTR("PutCharArray"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_PutCharArray); if (FAILED(m_hr)) return; szFunction = OLESTR("Visible"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_Visible); if (FAILED(m_hr)) return; #endif szFunction = OLESTR("Quit"); m_hr = m_pMtlbDispApp ->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &m_dispid_Quit); if (FAILED(m_hr)) return; m_bInitialized = true; }