//获得参数 void __cdecl CDataBase::GetParameterValue(LPCTSTR pszParamName, _variant_t & vtValue) { //效验参数 ASSERT(pszParamName!=NULL); //获取参数 try { vtValue.Clear(); vtValue=m_DBCommand->Parameters->Item[pszParamName]->Value; } catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); } return; }
bool RegUtils::GetNextValue(const HKEY& hKey, int iKeyIndex, CStdString& sName, _variant_t& vtData) { TCHAR szValueName[MAX_PATH]; DWORD dwValueNameSize = MAX_PATH; DWORD dwValueDataSize = MAX_PATH; BYTE byteValueData[MAX_PATH]; DWORD dwType = REG_NONE; ZeroMemory(szValueName, MAX_PATH); ZeroMemory(byteValueData, MAX_PATH); sName = _T(""); vtData.Clear(); if (RegEnumValue(hKey, iKeyIndex, szValueName, &dwValueNameSize, NULL, &dwType, byteValueData, &dwValueDataSize) == ERROR_SUCCESS) { switch (dwType) { case REG_SZ: vtData = (TCHAR*)byteValueData; sName = szValueName; break; case REG_DWORD: vtData = (DWORD)*byteValueData; sName = szValueName; break; default: LOG_WS_ERROR(_T("Unexpected type returned from the registry")); _ASSERT(_T("Unexpected type returned from the registry") == 0); return false; } return true; } return false; }
//***************************************************************************** //* Function Name: WrapInSafeArray //* Description: Wrap a buffer in a SAFEARRAY. This function sets up a //* SAFEARRAY data structure (p_sa) to describe a buffer //* (without copying the data). It then sets up a smart variant //* (p_svar) to contain the SAFEARRAY. The SAFEARRAY is set up //* with flags such that the data is not deallocated when the //* smart variant is destructed/cleared. //***************************************************************************** static void WrapInSafeArray ( SAFEARRAY& p_sa, _variant_t& p_svar, LPCVOID p_lpv, int p_cb) { ZeroMemory (&p_sa, sizeof (p_sa)); p_sa.cDims = 1; p_sa.fFeatures = FADF_AUTO | FADF_FIXEDSIZE; p_sa.cbElements = 1; p_sa.pvData = const_cast<LPVOID>(p_lpv); p_sa.rgsabound[0].cElements = p_cb; p_sa.rgsabound[0].lLbound = 0; try { p_svar.Clear (); } catch (const _com_error&) { } V_VT (&p_svar) = VT_ARRAY | VT_UI1; V_ARRAY (&p_svar) = &p_sa; }