static SAFEARRAY * newSafeArray (Tcl_Obj *pObj, VARTYPE type) { int size; int length; unsigned char *pSrc = Tcl_GetByteArrayFromObj(pObj, &length); switch ( type ) { case VT_I1 : size = 1; break; case VT_I2 : size = 2; break; case VT_I4 : size = 4; break; case VT_UI1 : size = 1; break; case VT_UI2 : size = 2; break; case VT_UI4 : size = 4; break; } length /= size; SAFEARRAY *psa = SafeArrayCreateVector(type, 0, length); if (psa == 0) { _com_issue_error(E_OUTOFMEMORY); } unsigned char *pDest; HRESULT hr; hr = SafeArrayAccessData(psa, reinterpret_cast<void **>(&pDest)); if (FAILED(hr)) { _com_issue_error(hr); } memcpy(pDest, pSrc, length*size); hr = SafeArrayUnaccessData(psa); if (FAILED(hr)) { _com_issue_error(hr); } return psa; }
// This is called by IE to notify us of events // Full documentation about all the events supported by DWebBrowserEvents2 can be found at // http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx STDMETHODIMP CEventSink::Invoke(DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS *pDispParams,VARIANT *pVarResult,EXCEPINFO *pExcepInfo,UINT *puArgErr) { UNREFERENCED_PARAMETER(lcid); UNREFERENCED_PARAMETER(wFlags); UNREFERENCED_PARAMETER(pVarResult); UNREFERENCED_PARAMETER(pExcepInfo); UNREFERENCED_PARAMETER(puArgErr); VARIANT v[5]; // Used to hold converted event parameters before passing them onto the event handling method int n; bool b; PVOID pv; LONG lbound,ubound,sz; if(!IsEqualIID(riid,IID_NULL)) return DISP_E_UNKNOWNINTERFACE; // riid should always be IID_NULL // Initialize the variants for(n=0;n<5;n++) VariantInit(&v[n]); if(dispIdMember==DISPID_BEFORENAVIGATE2) { // Handle the BeforeNavigate2 event VariantChangeType(&v[0],&pDispParams->rgvarg[5],0,VT_BSTR); // url VariantChangeType(&v[1],&pDispParams->rgvarg[4],0,VT_I4); // Flags VariantChangeType(&v[2],&pDispParams->rgvarg[3],0,VT_BSTR); // TargetFrameName VariantChangeType(&v[3],&pDispParams->rgvarg[2],0,VT_UI1|VT_ARRAY); // PostData VariantChangeType(&v[4],&pDispParams->rgvarg[1],0,VT_BSTR); // Headers if(v[3].vt!=VT_EMPTY) { SafeArrayGetLBound(v[3].parray,0,&lbound); SafeArrayGetUBound(v[3].parray,0,&ubound); sz=ubound-lbound+1; SafeArrayAccessData(v[3].parray,&pv); } else { sz=0; pv=NULL; } b=Event_BeforeNavigate2((LPOLESTR)v[0].bstrVal,v[1].lVal,(LPOLESTR)v[2].bstrVal,(PUCHAR)pv,sz,(LPOLESTR)v[4].bstrVal,((*(pDispParams->rgvarg[0].pboolVal))!=VARIANT_FALSE)); if(v[3].vt!=VT_EMPTY) SafeArrayUnaccessData(v[3].parray); if(b) *(pDispParams->rgvarg[0].pboolVal)=VARIANT_TRUE; else *(pDispParams->rgvarg[0].pboolVal)=VARIANT_FALSE; } // Free the variants for(n=0;n<5;n++) VariantClear(&v[n]); return S_OK; }
void SimpleBrowser::Write(LPCTSTR string) { if (m_pBrowser!= NULL) { // get document interface IHTMLDocument2 *document = GetDocument(); if (document != NULL) { // construct text to be written to browser as SAFEARRAY SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1); VARIANT *variant; SafeArrayAccessData(safe_array,(LPVOID *)&variant); variant->vt = VT_BSTR; variant->bstrVal = CString(string).AllocSysString(); SafeArrayUnaccessData(safe_array); // write SAFEARRAY to browser document document->write(safe_array); document->Release(); document = NULL; } } }
STDMETHODIMP CItemObject::put_ItemID(VARIANT id) { // FolderId = id; // Binary data is stored in the variant as an array of unsigned char if (id.vt == (VT_ARRAY | VT_UI1)) // (OLE SAFEARRAY) { // Retrieve size of array ItemID.cb = id.parray->rgsabound[0].cElements; ItemID.lpb = new BYTE[ItemID.cb]; // Allocate a buffer to store the data if (ItemID.lpb != NULL) { void *pArrayData; // Obtain safe pointer to the array SafeArrayAccessData(id.parray, &pArrayData); // Copy the bitmap into our buffer memcpy(ItemID.lpb, pArrayData, ItemID.cb); // Unlock the variant data SafeArrayUnaccessData(id.parray); } } return S_OK; }
//读Buffer bool CRsDupRgn::LoadBufferField(CBaseDBEntity *pGoods, const char* szFiledName, _RecordsetPtr &rs) { if(pGoods == NULL) return false; try { if(rs->GetadoEOF()) { ReleaseRs(rs); return false; } long lSize=0; FieldsPtr fldPtr = rs->GetFields(); FieldPtr itemPtr = fldPtr->GetItem(szFiledName); lSize = itemPtr->ActualSize; if(lSize > 0) { _variant_t varBLOB; varBLOB = itemPtr->GetChunk(lSize); BYTE *pBuf=NULL; SafeArrayAccessData(varBLOB.parray,(void**)&pBuf); SafeArrayUnaccessData(varBLOB.parray); // 清空SKILL CEntityProperty* ep = pGoods->GetDataEntityManager().GetEntityProperty(string(szFiledName)); if(ep) ep->SetBufAttr(0, pBuf, lSize); } } catch(_com_error e) { PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_LOADRGNOBJERR), e); return false; } return true; }
STDMETHODIMP CByteArray::GetArray(/*[out,retval]*/ VARIANT *pVal) { HGLOBAL hGlobal; ULARGE_INTEGER pos; LARGE_INTEGER li; li.QuadPart = 0; m_stream->Seek(li, System::IO::STREAM_SEEK_CUR, &pos); if (SUCCEEDED(GetHGlobalFromStream(m_stream, &hGlobal))) { void* data = GlobalLock(hGlobal); SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = (DWORD)pos.QuadPart; SAFEARRAY* psa = SafeArrayCreate(VT_UI1, 1, rgsabound); //sa = SafeArrayCreateVector(VT_I1, 0, (DWORD)pos.QuadPart); void* pv; SafeArrayAccessData(psa, (void**)&pv); CopyMemory(pv, data, (DWORD)pos.QuadPart); SafeArrayUnaccessData(psa); GlobalUnlock(hGlobal); VariantInit(pVal); pVal->vt = VT_ARRAY | VT_UI1; pVal->parray = psa; return S_OK; } return E_FAIL; }
void IEEmbed::navigate(NETLIBHTTPREQUEST *nlhr) { WCHAR *szUrl = mir_a2u(nlhr->szUrl); BSTR bstrHeaders; LPSAFEARRAY psa; LPSTR pPostData; VARIANT vPostData = {0}, vHeaders = {0}; bstrHeaders = SysAllocString(L"Content-Type: application/x-www-form-urlencoded\r\n"); V_VT(&vHeaders) = VT_BSTR; V_BSTR(&vHeaders) = bstrHeaders; VariantInit(&vPostData); psa = SafeArrayCreateVector(VT_UI1, 0, nlhr->dataLength); SafeArrayAccessData(psa, (LPVOID*)&pPostData); memcpy(pPostData, nlhr->pData, nlhr->dataLength); SafeArrayUnaccessData(psa); V_VT(&vPostData) = VT_ARRAY | VT_UI1; V_ARRAY(&vPostData) = psa; pWebBrowser->Navigate(szUrl, NULL, NULL, &vPostData, &vHeaders); SysFreeString(bstrHeaders); VariantClear(&vPostData); mir_free(szUrl); }
long SmtTinFclsAdoLayer::GetTinTriangles(SmtTin *&pTin) { int nTriangles = 0; m_SmtRecordset.GetCollect("geom_trianglenum",nTriangles); long lDataSize = m_SmtRecordset.GetField("geom_triangles")->ActualSize; if(lDataSize > 0) { _variant_t varBLOB; varBLOB = m_SmtRecordset.GetField("geom_triangles")->GetChunk(lDataSize); if(varBLOB.vt == (VT_ARRAY | VT_UI1)) { SmtTriangle *pTriBuf = NULL; SafeArrayAccessData(varBLOB.parray,(void **)&pTriBuf); pTin->AddTriangleCollection(pTriBuf,nTriangles); SafeArrayUnaccessData (varBLOB.parray); } } return SMT_ERR_NONE; }
STDMETHOD(GetSecurity) (THIS_ SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR *ppSecurityDescriptor, BOOL fDefault ) { try { _variant_t vsd = m_filesystem->GetPathSecurityDescriptor(m_pathName); SECURITY_DESCRIPTOR* self; SafeArrayAccessData(vsd.parray, (void**)&self); DWORD absSize = 0; DWORD daclSize = 0; DWORD saclSize = 0; DWORD ownerSize = 0; DWORD primGroupSize = 0; MakeAbsoluteSD(self, NULL, &absSize, NULL, &daclSize, NULL, &saclSize, NULL, &ownerSize, NULL, &primGroupSize); pSD = LocalAlloc(0, absSize); MakeAbsoluteSD(self, pSD, &absSize, /*pSD->Dacl =*/ (PACL)LocalAlloc(0, daclSize), &daclSize, /*pSD->Sacl =*/ (PACL)LocalAlloc(0, saclSize), &saclSize, /*pSD->Owner =*/ (PSID)LocalAlloc(0, ownerSize), &ownerSize, /*pSD->Group =*/ (PSID)LocalAlloc(0, primGroupSize), &primGroupSize); SafeArrayUnaccessData(vsd.parray); } catch (_com_error &e) { com_error_Message(e); } *ppSecurityDescriptor = pSD; return S_OK; }
void CWtlHtmlView::Write(LPCTSTR string) { if (m_spWebBrowser2 == NULL) GetBody(); if (m_spWebBrowser2 != NULL) { // get document interface IHTMLDocument2 *document = GetDocument(); if (document != NULL) { // construct text to be written to browser as SAFEARRAY SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1); VARIANT *variant; SafeArrayAccessData(safe_array,(LPVOID *)&variant); CComBSTR bstrTmp = string; variant->vt = VT_BSTR; variant->bstrVal = bstrTmp; // write SAFEARRAY to browser document document->write(safe_array); SafeArrayUnaccessData(safe_array); document->Release(); document = NULL; } } }
STDMETHODIMP C_ECBLoader::get_Styles(STRING_ARRAY *pVal) { if (!pVal) { return E_POINTER; } try { if (*pVal) { SafeArrayDestroy(*pVal); } int len = styles.GetLength(); SAFEARRAYBOUND rgsabound[] = { len, 0 }; SAFEARRAY* psa = SafeArrayCreate(VT_BSTR, 1, rgsabound); BSTR *bs; SafeArrayAccessData(psa, (LPVOID*)&bs); for (int n = 0; n < len; n++) { *bs++ = styles[n]->toBSTR(); } SafeArrayUnaccessData(psa); SafeArrayCopy(psa, pVal); SafeArrayDestroy(psa); } catch (C_STLNonStackException const &exception) { exception.Log(_T("Exception in C_ECBLoader::get_Styles")); } return S_OK; }
int PolylineTest::writePersistFile() { ComPtr<IPolyline> pl; auto hr = CoCreateInstance(CLSID_PolylineObj, NULL, CLSCTX_INPROC_SERVER, IID_IPolyline, (void**)&pl); if (FAILED(hr)) { return -1; } LPTYPEINFO pTypeInfo = NULL; LPTYPELIB pTypelib = NULL; IRecordInfo* pRecInfo = NULL; hr = LoadRegTypeLib(LIBID_GraphicsLibrary, 1, 0, GetUserDefaultLCID(), &pTypelib); _ASSERT(SUCCEEDED(hr) && pTypelib); hr = pTypelib->GetTypeInfoOfGuid(__uuidof(PolyPoint), &pTypeInfo); _ASSERT(SUCCEEDED(hr) && pTypeInfo); hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo); _ASSERT(SUCCEEDED(hr) && pRecInfo); pTypeInfo->Release(); pTypelib->Release(); std::vector<POINT> points = { { 1, 2 }, { 100, 200 }, { 300, 400 } }; auto psa = SafeArrayCreateVectorEx(VT_RECORD, 0, points.size(), pRecInfo); PolyPoint* pps; SafeArrayAccessData(psa, (void**)&pps); _ASSERT(psa); for (size_t i = 0; i < points.size(); ++i) { pps[i].x = points[i].x; pps[i].y = points[i].y; } pl->put_Points(psa); outputPoints(pl); ComPtr<IPersistFile> pf; pl->QueryInterface(IID_IPersistFile, (void**)&pf); pf->Save(kFileName, TRUE); pf->SaveCompleted(kFileName); return 0; }
BOOL CPrefConnectServers::OnApply() { std::vector<CString> HostServers; for(int i = 0; i < m_lstServers.GetItemCount(); i++) { CString HostPort = m_lstServers.GetItemText(i, 0); HostPort += ":" + m_lstServers.GetItemText(i, 1); m_pDoc->m_autCache->AddNode(HostPort, false); HostServers.push_back(HostPort); } VARIANT vaNodes; VariantInit(&vaNodes); vaNodes.vt = VT_ARRAY | VT_BSTR; SAFEARRAYBOUND bounds = {HostServers.size(), 0}; SAFEARRAY* psa = SafeArrayCreate(VT_BSTR, 1, &bounds); BSTR* strArray; SafeArrayAccessData(psa, reinterpret_cast<void**> (&strArray)); for(int i = 0; i < HostServers.size(); i++) strArray[i] = HostServers[i].AllocSysString(); SafeArrayUnaccessData(psa); vaNodes.parray = psa; m_autPrefs->SetHostServers(&vaNodes); VariantClear(&vaNodes); return CPropertyPage::OnApply(); }
HRESULT InputFileData::AssignSafeArray(SAFEARRAY* psa) { if (!m_sFileName.IsEmpty()) return E_INVALIDARG; if (psa->cDims != 1) return E_INVALIDARG; if (psa->rgsabound[0].lLbound != 0) return E_INVALIDARG; void* pvData = NULL; if (FAILED(SafeArrayAccessData(psa, &pvData))) return E_INVALIDARG; m_iCharCount = psa->rgsabound[0].cElements; m_pBuffer = new unsigned char[m_iCharCount]; m_bOurBuffer = true; memcpy(m_pBuffer, pvData, m_iCharCount); SafeArrayUnaccessData(psa); return S_OK; }
void Zqpkt::set_pkt(zq_pkt *pkt) { // FIXME:这里复制了一遍,更好地做法是使用引用计数,但是这个涉及到修改 zqpsrc,算了 stamp_ = pkt->pts / 45000.0; data_.vt = VT_ARRAY | VT_UI1; SAFEARRAYBOUND b; b.lLbound = 0; b.cElements = pkt->len; data_.parray = SafeArrayCreate(VT_UI1, 1, &b); if (data_.parray) { void *ptr; if (S_OK == SafeArrayAccessData(data_.parray, &ptr)) { memcpy(ptr, pkt->ptr, pkt->len); SafeArrayUnaccessData(data_.parray); } } if (pkt->type == 1) key_ = pkt->data.video.frametype == 'I'; else key_ = true; // 音频都是 key }
//////////////////////////////////////////////////////////////////// // ConvertBlobToVarVector // // Takes a PROPVARIANT BLOB or pclipdata and converts it to VARIANT SAFEARRAY // which can be treated by VB as vector (1-dim) Byte Array. // STDAPI ConvertBinaryToVarVector(PROPVARIANT *pVarBlob, VARIANT *pVarByteArray) { HRESULT hr = S_FALSE; SAFEARRAY* pSA; DWORD dwSize; if ( ( pVarBlob == NULL ) || (pVarBlob->vt != VT_BLOB) && ( pVarBlob->vt != VT_CF ) || ( pVarByteArray == NULL ) ) return E_UNEXPECTED; // Identify the size if ( pVarBlob->vt == VT_BLOB ) dwSize = pVarBlob->blob.cbSize; else dwSize = pVarBlob->pclipdata->cbSize; if ((dwSize) && (dwSize < 0x800000)) { // Create a vector array the size of the blob or clipdata... pSA = SafeArrayCreateVector(VT_UI1, 0, dwSize); if ( pSA != NULL ) { // Copy the data over to the vector BYTE *pByte = NULL; hr = SafeArrayAccessData( pSA, (void**)&pByte ); if ( SUCCEEDED(hr) ) { SEH_TRY if ( pVarBlob->vt == VT_BLOB ) memcpy( pByte, (BYTE*)(pVarBlob->blob.pBlobData), dwSize ); else memcpy( pByte, (BYTE*)(pVarBlob->pclipdata->pClipData), dwSize ); SEH_EXCEPT(hr) SafeArrayUnaccessData( pSA ); } }
static void test_XMLHTTP(void) { static const char bodyA[] = "mode=Test"; static const char urlA[] = "http://crossover.codeweavers.com/posttest.php"; static const char xmltestA[] = "http://crossover.codeweavers.com/xmltest.xml"; static const char referertesturl[] = "http://test.winehq.org/tests/referer.php"; static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0}; static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n"; static const WCHAR norefererW[] = {'n','o',' ','r','e','f','e','r','e','r',' ','s','e','t',0}; IXMLHttpRequest *xhr; IObjectWithSite *obj_site, *obj_site2; BSTR bstrResponse, str, str1; VARIANT varbody, varbody_ref; VARIANT dummy; LONG state, status, bound; IDispatch *event; void *ptr; HRESULT hr; HGLOBAL g; xhr = create_xhr(); VariantInit(&dummy); V_VT(&dummy) = VT_ERROR; V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND; hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL); EXPECT_HR(hr, S_OK); hr = IXMLHttpRequest_abort(xhr); EXPECT_HR(hr, S_OK); V_VT(&varbody) = VT_I2; V_I2(&varbody) = 1; hr = IXMLHttpRequest_get_responseBody(xhr, &varbody); EXPECT_HR(hr, E_PENDING); ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody)); ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody)); V_VT(&varbody) = VT_I2; V_I2(&varbody) = 1; hr = IXMLHttpRequest_get_responseStream(xhr, &varbody); EXPECT_HR(hr, E_PENDING); ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody)); ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody)); /* send before open */ hr = IXMLHttpRequest_send(xhr, dummy); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); /* initial status code */ hr = IXMLHttpRequest_get_status(xhr, NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); status = 0xdeadbeef; hr = IXMLHttpRequest_get_status(xhr, &status); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); ok(status == READYSTATE_UNINITIALIZED || broken(status == 0xdeadbeef) /* <win8 */, "got %d\n", status); hr = IXMLHttpRequest_get_statusText(xhr, &str); ok(hr == E_FAIL, "got 0x%08x\n", hr); /* invalid parameters */ test_open(xhr, NULL, NULL, E_INVALIDARG); test_open(xhr, "POST", NULL, E_INVALIDARG); test_open(xhr, NULL, urlA, E_INVALIDARG); hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL); EXPECT_HR(hr, E_INVALIDARG); hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1")); EXPECT_HR(hr, E_INVALIDARG); hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1")); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_readyState(xhr, NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); state = -1; hr = IXMLHttpRequest_get_readyState(xhr, &state); EXPECT_HR(hr, S_OK); ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state); httpreq = xhr; event = create_dispevent(); EXPECT_REF(event, 1); hr = IXMLHttpRequest_put_onreadystatechange(xhr, event); EXPECT_HR(hr, S_OK); EXPECT_REF(event, 2); g_unexpectedcall = g_expectedcall = 0; test_open(xhr, "POST", urlA, S_OK); ok(g_unexpectedcall == 0, "unexpected disp event call\n"); ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n"); /* status code after ::open() */ status = 0xdeadbeef; hr = IXMLHttpRequest_get_status(xhr, &status); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); ok(status == READYSTATE_UNINITIALIZED || broken(status == 0xdeadbeef) /* <win8 */, "got %d\n", status); state = -1; hr = IXMLHttpRequest_get_readyState(xhr, &state); EXPECT_HR(hr, S_OK); ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state); hr = IXMLHttpRequest_abort(xhr); EXPECT_HR(hr, S_OK); state = -1; hr = IXMLHttpRequest_get_readyState(xhr, &state); EXPECT_HR(hr, S_OK); ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */, "got %d, expected READYSTATE_UNINITIALIZED\n", state); test_open(xhr, "POST", urlA, S_OK); hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1")); EXPECT_HR(hr, S_OK); hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1")); EXPECT_HR(hr, E_INVALIDARG); hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1")); EXPECT_HR(hr, E_INVALIDARG); V_VT(&varbody) = VT_BSTR; V_BSTR(&varbody) = _bstr_(bodyA); hr = IXMLHttpRequest_send(xhr, varbody); if (hr == INET_E_RESOURCE_NOT_FOUND) { skip("No connection could be made with crossover.codeweavers.com\n"); IXMLHttpRequest_Release(xhr); return; } EXPECT_HR(hr, S_OK); /* response headers */ hr = IXMLHttpRequest_getAllResponseHeaders(xhr, NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str); EXPECT_HR(hr, S_OK); /* status line is stripped already */ ok(memcmp(str, _bstr_("HTTP"), 4*sizeof(WCHAR)), "got response headers %s\n", wine_dbgstr_w(str)); ok(*str, "got empty headers\n"); hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str1); EXPECT_HR(hr, S_OK); ok(str1 != str, "got %p\n", str1); SysFreeString(str1); SysFreeString(str); hr = IXMLHttpRequest_getResponseHeader(xhr, NULL, NULL); EXPECT_HR(hr, E_INVALIDARG); hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), &str); EXPECT_HR(hr, S_OK); ok(*str != ' ', "got leading space in header %s\n", wine_dbgstr_w(str)); SysFreeString(str); /* status code after ::send() */ status = 0xdeadbeef; hr = IXMLHttpRequest_get_status(xhr, &status); EXPECT_HR(hr, S_OK); ok(status == 200, "got %d\n", status); hr = IXMLHttpRequest_get_statusText(xhr, NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_statusText(xhr, &str); EXPECT_HR(hr, S_OK); ok(!lstrcmpW(str, _bstr_("OK")), "got status %s\n", wine_dbgstr_w(str)); SysFreeString(str); /* another ::send() after completed request */ V_VT(&varbody) = VT_BSTR; V_BSTR(&varbody) = _bstr_(bodyA); hr = IXMLHttpRequest_send(xhr, varbody); ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse); EXPECT_HR(hr, S_OK); /* the server currently returns "FAILED" because the Content-Type header is * not what the server expects */ if(hr == S_OK) { ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse)); SysFreeString(bstrResponse); } /* POST: VT_VARIANT|VT_BYREF body */ test_open(xhr, "POST", urlA, S_OK); V_VT(&varbody_ref) = VT_VARIANT|VT_BYREF; V_VARIANTREF(&varbody_ref) = &varbody; hr = IXMLHttpRequest_send(xhr, varbody_ref); EXPECT_HR(hr, S_OK); /* GET request */ test_open(xhr, "GET", xmltestA, S_OK); V_VT(&varbody) = VT_EMPTY; hr = IXMLHttpRequest_send(xhr, varbody); if (hr == INET_E_RESOURCE_NOT_FOUND) { skip("No connection could be made with crossover.codeweavers.com\n"); IXMLHttpRequest_Release(xhr); return; } EXPECT_HR(hr, S_OK); hr = IXMLHttpRequest_get_responseText(xhr, NULL); ok(hr == E_POINTER || broken(hr == E_INVALIDARG) /* <win8 */, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse); EXPECT_HR(hr, S_OK); ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)), "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse)); SysFreeString(bstrResponse); hr = IXMLHttpRequest_get_responseBody(xhr, NULL); EXPECT_HR(hr, E_INVALIDARG); V_VT(&varbody) = VT_EMPTY; hr = IXMLHttpRequest_get_responseBody(xhr, &varbody); EXPECT_HR(hr, S_OK); ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1); ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody))); bound = -1; hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound); EXPECT_HR(hr, S_OK); ok(bound == 0, "got %d, expected zero bound\n", bound); hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr); EXPECT_HR(hr, S_OK); ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n"); SafeArrayUnaccessData(V_ARRAY(&varbody)); VariantClear(&varbody); /* get_responseStream */ hr = IXMLHttpRequest_get_responseStream(xhr, NULL); EXPECT_HR(hr, E_INVALIDARG); V_VT(&varbody) = VT_EMPTY; hr = IXMLHttpRequest_get_responseStream(xhr, &varbody); ok(V_VT(&varbody) == VT_UNKNOWN, "got type %d\n", V_VT(&varbody)); EXPECT_HR(hr, S_OK); EXPECT_REF(V_UNKNOWN(&varbody), 1); g = NULL; hr = GetHGlobalFromStream((IStream*)V_UNKNOWN(&varbody), &g); EXPECT_HR(hr, S_OK); ok(g != NULL, "got %p\n", g); IDispatch_Release(event); /* test if referrer header is sent */ test_open(xhr, "GET", referertesturl, S_OK); V_VT(&varbody) = VT_EMPTY; hr = IXMLHttpRequest_send(xhr, varbody); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_responseText(xhr, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, norefererW), "got response text %s\n", wine_dbgstr_w(str)); SysFreeString(str); /* interaction with object site */ hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site); EXPECT_HR(hr, S_OK); hr = IObjectWithSite_SetSite(obj_site, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2); EXPECT_HR(hr, S_OK); ok(obj_site == obj_site2 || broken(obj_site != obj_site2), "got new instance\n"); IObjectWithSite_Release(obj_site2); set_xhr_site(xhr); test_open(xhr, "GET", "tests/referer.php", S_OK); str1 = a2bstr("http://test.winehq.org/"); V_VT(&varbody) = VT_EMPTY; hr = IXMLHttpRequest_send(xhr, varbody); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXMLHttpRequest_get_responseText(xhr, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, str1), "got response text %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(str1)); SysFreeString(str); SysFreeString(str1); /* try to set site another time */ hr = IObjectWithSite_SetSite(obj_site, &testsite); EXPECT_HR(hr, S_OK); IObjectWithSite_Release(obj_site); IXMLHttpRequest_Release(xhr); free_bstrs(); }
WXDLLEXPORT bool wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant) { bool ok = true; if ( oleVariant.vt & VT_ARRAY ) { // Compute the total number of elements in all array dimensions int cElements = 1; for ( int cDims = 0; cDims < oleVariant.parray->cDims; cDims++ ) cElements *= oleVariant.parray->rgsabound[cDims].cElements; // Get a pointer to the data void* pvdata; HRESULT hr = SafeArrayAccessData(oleVariant.parray, &pvdata); if ( FAILED(hr) ) return false; switch (oleVariant.vt & VT_TYPEMASK) { case VT_VARIANT: { variant.ClearList(); VARIANTARG *variant_data=(VARIANTARG*)pvdata; for ( int i = 0; i < cElements; i++ ) { VARIANTARG& oleElement = variant_data[i]; wxVariant vElement; if ( !wxConvertOleToVariant(oleElement, vElement) ) { ok = false; variant.ClearList(); break; } variant.Append(vElement); } } break; case VT_BSTR: { wxArrayString strings; BSTR *string_val=(BSTR*)pvdata; for ( int i = 0; i < cElements; ++i ) { wxString str=wxConvertStringFromOle(*string_val); strings.Add(str); ++string_val; } variant=strings; } break; default: wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"), oleVariant.vt & VT_TYPEMASK); variant = wxVariant(); ok = false; break; } SafeArrayUnaccessData(oleVariant.parray); } else if ( oleVariant.vt & VT_BYREF ) { switch ( oleVariant.vt & VT_TYPEMASK ) { case VT_VARIANT: { VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref); if (!wxConvertOleToVariant(oleReference,variant)) return false; break; } default: wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"), oleVariant.vt); return false; } } else // simply type (not array or reference) { switch ( oleVariant.vt & VT_TYPEMASK ) { case VT_BSTR: { wxString str(wxConvertStringFromOle(oleVariant.bstrVal)); variant = str; } break; case VT_DATE: #if wxUSE_DATETIME { SYSTEMTIME st; VariantTimeToSystemTime(oleVariant.date, &st); wxDateTime date; date.SetFromMSWSysTime(st); variant = date; } #endif // wxUSE_DATETIME break; case VT_I4: variant = (long) oleVariant.lVal; break; case VT_I2: variant = (long) oleVariant.iVal; break; case VT_BOOL: variant = oleVariant.boolVal != 0; break; case VT_R8: variant = oleVariant.dblVal; break; case VT_DISPATCH: variant = (void*) oleVariant.pdispVal; break; case VT_NULL: variant.MakeNull(); break; case VT_EMPTY: break; // Ignore Empty Variant, used only during destruction of objects default: wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"), oleVariant.vt,oleVariant.vt&VT_TYPEMASK); return false; } } return ok; }
WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) { VariantInit(&oleVariant); if (variant.IsNull()) { oleVariant.vt = VT_NULL; return true; } wxString type(variant.GetType()); if (type == wxT("long")) { oleVariant.vt = VT_I4; oleVariant.lVal = variant.GetLong() ; } else if (type == wxT("char")) { oleVariant.vt=VT_I1; // Signed Char oleVariant.cVal=variant.GetChar(); } else if (type == wxT("double")) { oleVariant.vt = VT_R8; oleVariant.dblVal = variant.GetDouble(); } else if (type == wxT("bool")) { oleVariant.vt = VT_BOOL; oleVariant.boolVal = variant.GetBool(); } else if (type == wxT("string")) { wxString str( variant.GetString() ); oleVariant.vt = VT_BSTR; oleVariant.bstrVal = wxConvertStringToOle(str); } #if wxUSE_DATETIME else if (type == wxT("datetime")) { wxDateTime date( variant.GetDateTime() ); oleVariant.vt = VT_DATE; SYSTEMTIME st; date.GetAsMSWSysTime(&st); SystemTimeToVariantTime(&st, &oleVariant.date); } #endif else if (type == wxT("void*")) { oleVariant.vt = VT_DISPATCH; oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr(); } else if (type == wxT("list") || type == wxT("stringlist")) { oleVariant.vt = VT_VARIANT | VT_ARRAY; SAFEARRAY *psa; SAFEARRAYBOUND saBound; VARIANTARG *pvargBase; VARIANTARG *pvarg; int i, j; int iCount = variant.GetCount(); saBound.lLbound = 0; saBound.cElements = iCount; psa = SafeArrayCreate(VT_VARIANT, 1, &saBound); if (psa == NULL) return false; SafeArrayAccessData(psa, (void**)&pvargBase); pvarg = pvargBase; for (i = 0; i < iCount; i++) { // copy each string in the list of strings wxVariant eachVariant(variant[i]); if (!wxConvertVariantToOle(eachVariant, * pvarg)) { // memory failure: back out and free strings alloc'ed up to // now, and then the array itself. pvarg = pvargBase; for (j = 0; j < i; j++) { SysFreeString(pvarg->bstrVal); pvarg++; } SafeArrayDestroy(psa); return false; } pvarg++; } SafeArrayUnaccessData(psa); oleVariant.parray = psa; } else { oleVariant.vt = VT_NULL; return false; } return true; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d X T R N I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadXTRNImage reads a XTRN image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadXTRNImage method is: % % Image *ReadXTRNImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadXTRNImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to an ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadXTRNImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; ImageInfo *clone_info; void *param1, *param2, *param3; param1 = param2 = param3 = (void *) NULL; image = (Image *) NULL; clone_info=CloneImageInfo(image_info); if (clone_info->filename == NULL) { DestroyImageInfo(clone_info); ThrowReaderException(OptionError,MissingAnImageFilename,image); } /* DebugString("ReadXTRN CODER: %s\n",clone_info->filename); */ if (LocaleCompare(image_info->magick,"XTRNFILE") == 0) { image=ReadImage(clone_info,exception); /* this should not be needed since the upstream code should catch any excetpions thrown by ReadImage */ if (exception->severity != UndefinedException) MagickWarning2(exception->severity,exception->reason,exception->description); } else if (LocaleCompare(image_info->magick,"XTRNIMAGE") == 0) { Image **image_ptr; #ifdef ALL_IMAGEINFO ImageInfo **image_info_ptr; #endif (void) sscanf(clone_info->filename,"%lx,%lx",¶m1,¶m2); image_ptr=(Image **) param2; if (*image_ptr != (Image *)NULL) image=CloneImage(*image_ptr,0,0,False,&(*image_ptr)->exception); #ifdef ALL_IMAGEINFO image_info_ptr=(ImageInfo **) param1; if (*image_info_ptr != (ImageInfo *)NULL) image_info=*image_info_ptr; #endif } else if (LocaleCompare(image_info->magick,"XTRNBLOB") == 0) { char **blob_data; size_t *blob_length; char filename[MaxTextExtent]; (void) sscanf(clone_info->filename,"%lx,%lx,%s",¶m1,¶m2,&filename); blob_data=(char **) param1; blob_length=(size_t *) param2; image=BlobToImage(clone_info,*blob_data,*blob_length,exception); if (exception->severity != UndefinedException) MagickWarning2(exception->severity,exception->reason,exception->description); } else if (LocaleCompare(image_info->magick,"XTRNARRAY") == 0) { SAFEARRAY *pSafeArray; char *blob_data; size_t blob_length; long lBoundl, lBoundu; HRESULT hr; char filename[MaxTextExtent]; filename[0] = '\0'; (void) sscanf(clone_info->filename,"%lx,%s",¶m1,&filename); hr = S_OK; pSafeArray = (SAFEARRAY *) param1; if (pSafeArray) { hr = SafeArrayGetLBound(pSafeArray, 1, &lBoundl); if (SUCCEEDED(hr)) hr = SafeArrayGetUBound(pSafeArray, 1, &lBoundu); if (SUCCEEDED(hr)) { blob_length = lBoundu - lBoundl + 1; hr = SafeArrayAccessData(pSafeArray, (void**)&blob_data); if(SUCCEEDED(hr)) { if (filename[0] != '\0') (void) strcpy(clone_info->filename, filename); else clone_info->filename[0] = '\0'; *clone_info->magick = '\0'; image=BlobToImage(clone_info,blob_data,blob_length,exception); hr = SafeArrayUnaccessData(pSafeArray); if (exception->severity != UndefinedException) MagickWarning2(exception->severity,exception->reason, exception->description); } } } } DestroyImageInfo(clone_info); return(image); }
static void on_before_navigate2(DocHost *This, LPCWSTR url, const BYTE *post_data, ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel) { VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers; DISPPARAMS dispparams; VARIANTARG params[7]; dispparams.cArgs = 7; dispparams.cNamedArgs = 0; dispparams.rgdispidNamedArgs = NULL; dispparams.rgvarg = params; This->busy = VARIANT_TRUE; V_VT(params) = VT_BOOL|VT_BYREF; V_BOOLREF(params) = cancel; V_VT(params+1) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(params+1) = &var_headers; V_VT(&var_headers) = VT_BSTR; V_BSTR(&var_headers) = headers; V_VT(params+2) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(params+2) = &var_post_data2; V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(&var_post_data2) = &var_post_data; VariantInit(&var_post_data); if(post_data_len) { SAFEARRAYBOUND bound = {post_data_len, 0}; void *data; V_VT(&var_post_data) = VT_UI1|VT_ARRAY; V_ARRAY(&var_post_data) = SafeArrayCreate(VT_UI1, 1, &bound); SafeArrayAccessData(V_ARRAY(&var_post_data), &data); memcpy(data, post_data, post_data_len); SafeArrayUnaccessData(V_ARRAY(&var_post_data)); } V_VT(params+3) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(params+3) = &var_frame_name; V_VT(&var_frame_name) = VT_BSTR; V_BSTR(&var_frame_name) = NULL; V_VT(params+4) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(params+4) = &var_flags; V_VT(&var_flags) = VT_I4; V_I4(&var_flags) = 0; V_VT(params+5) = (VT_BYREF|VT_VARIANT); V_VARIANTREF(params+5) = &var_url; V_VT(&var_url) = VT_BSTR; V_BSTR(&var_url) = SysAllocString(url); V_VT(params+6) = (VT_DISPATCH); V_DISPATCH(params+6) = This->disp; call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams); SysFreeString(V_BSTR(&var_url)); if(post_data_len) SafeArrayDestroy(V_ARRAY(&var_post_data)); }
HRESULT CAtmoLightFilter::Transform(IMediaSample *pSample) { CheckPointer(pSample,E_POINTER); if(!m_bitmap_header || !m_bitmap_header) return NOERROR; BITMAPINFOHEADER *bmiHeader = NULL; RECT rect; AM_MEDIA_TYPE *pMT; if((pSample->GetMediaType(&pMT) == S_OK) && pMT) { log("CAtmoLightFilter::Transform: MediaType changed!\n"); CMediaType temp(*pMT, NULL); LogMediaType("From",&m_pInput->CurrentMediaType()); LogMediaType("Changed to", &temp); m_pInput->SetMediaType( &temp ); DeleteMediaType(pMT); } if( IsEqualGUID( *m_pInput->CurrentMediaType().FormatType(), FORMAT_VideoInfo) ) { VIDEOINFO* pVI = (VIDEOINFO*) m_pInput->CurrentMediaType( ).Format( ); CheckPointer(pVI,E_UNEXPECTED); rect = pVI->rcSource; if(pVI->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) bmiHeader = &pVI->bmiHeader; else return NOERROR; } else if( IsEqualGUID( *m_pInput->CurrentMediaType().FormatType(), FORMAT_VideoInfo2) ) { VIDEOINFOHEADER2* pVI = (VIDEOINFOHEADER2*) m_pInput->CurrentMediaType( ).Format( ); CheckPointer(pVI, E_UNEXPECTED); rect = pVI->rcSource; if(pVI->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) bmiHeader = &pVI->bmiHeader; else return NOERROR; } else { log("Error: no Format_VideoInfo structure."); return NOERROR; } unsigned char *pBuffer = NULL; if( pSample->GetPointer( (LPBYTE*) &pBuffer ) != S_OK || !pBuffer ) return NOERROR; m_FrameCounter++; OleInitialize( NULL ); int stride = (((bmiHeader->biWidth * bmiHeader->biBitCount) + 31) & ~31) >> 3; //http://msdn.microsoft.com/en-us/library/aa904813(VS.80).aspx if( m_pfTransform ) { IAtmoLiveViewControl *liveControl = getAtmoLiveViewControl(); if(liveControl) { unsigned char *rgb_buffer; if(SafeArrayAccessData(m_pixel_buffer,(void **)&rgb_buffer) == S_OK) { (this->*m_pfTransform)( pSample, pBuffer, rect, bmiHeader, stride, rgb_buffer ); if(m_LogLevel>=2 && (m_FrameCounter % 25) == 0) { char fn[MAX_PATH]; sprintf( fn, "%simg_%d.bmp", m_pszImageLogPath, m_FrameCounter/25+100000 ); SaveBitmap( fn, rgb_buffer, m_atmo_capture_width, m_atmo_capture_height); } SafeArrayUnaccessData( m_pixel_buffer ); liveControl->setPixelData(m_bitmap_header, m_pixel_buffer); } liveControl->Release(); } } OleUninitialize(); return NOERROR; }
HRESULT CAtmoLightFilter::StartStreaming() { log("\n\nCAtmoLightFilter::StartStreaming\n"); if(!m_AtmoInitialized) { OleInitialize(NULL); IAtmoRemoteControl *remoteControl = getAtmoRemoteControl(); if(remoteControl) { log("atmo: found running atmowin\n"); remoteControl->getEffect( &m_CurrentAtmoEffect ); if(m_CurrentAtmoEffect != cemLivePicture) { remoteControl->setEffect( cemLivePicture, &m_CurrentAtmoEffect ); log("set live mode\n"); } IAtmoRemoteControl2 *remoteControl2 = getAtmoRemoteControl2(); if(remoteControl2) { remoteControl2->getLiveViewRes(&m_atmo_capture_width,&m_atmo_capture_height); remoteControl2->Release(); atmo_capture_height = m_atmo_capture_height + 1; atmo_capture_width = m_atmo_capture_width + 1; log("atmo: got res %d x %d\n", m_atmo_capture_width, m_atmo_capture_height ); } IAtmoLiveViewControl *liveControl = getAtmoLiveViewControl(); if(liveControl) { liveControl->setLiveViewSource( lvsExternal ); liveControl->Release(); log("atmo: set live source extern\n"); } remoteControl->Release(); // m_atmo_capture_width = 512; // m_atmo_capture_height = 384; m_pixel_buffer = SafeArrayCreateVector(VT_UI1,0, m_atmo_capture_width * m_atmo_capture_height * 4); if(!m_pixel_buffer) log("Error: SafeArrayCreateVector Pixelbuffer failed."); m_bitmap_header = SafeArrayCreateVector(VT_UI1,0,sizeof(BITMAPINFOHEADER)); if(!m_bitmap_header) log("Error: SafeArrayCreateVector BitmapHeader failed."); BITMAPINFOHEADER *header; SafeArrayAccessData(m_bitmap_header,(void **)&header); header->biSize = sizeof(BITMAPINFOHEADER); header->biWidth = m_atmo_capture_width; header->biHeight = m_atmo_capture_height; header->biBitCount = 32; header->biCompression = BI_RGB; SafeArrayUnaccessData(m_bitmap_header); m_AtmoInitialized = true; } OleUninitialize(); } return CTransInPlaceFilter::StartStreaming(); }
/* * ReleaseVariant * * Clears a particular variant structure and releases any external objects * or memory contained in the variant. Supports the data types listed above. */ int CXLAutomation::ReleaseVariant(VARIANTARG *pvarg) { VARTYPE vt; VARIANTARG *pvargArray; long lLBound, lUBound, l; vt = pvarg->vt & 0xfff; // mask off flags // check if an array. If so, free its contents, then the array itself. if (V_ISARRAY(pvarg)) { // variant arrays are all this routine currently knows about. Since a // variant can contain anything (even other arrays), call ourselves // recursively. if (vt == VT_VARIANT) { SafeArrayGetLBound(pvarg->parray, 1, &lLBound); SafeArrayGetUBound(pvarg->parray, 1, &lUBound); if (lUBound > lLBound) { lUBound -= lLBound; SafeArrayAccessData(pvarg->parray, (void**)&pvargArray); for (l = 0; l < lUBound; l++) { ReleaseVariant(pvargArray); pvargArray++; } SafeArrayUnaccessData(pvarg->parray); } } else { return 1; // non-variant type // MessageBox(NULL, _T("ReleaseVariant: Array contains non-variant type"), "Failed", MB_OK | MB_ICONSTOP); } // Free the array itself. SafeArrayDestroy(pvarg->parray); } else { switch (vt) { case VT_DISPATCH: //(*(pvarg->pdispVal->lpVtbl->Release))(pvarg->pdispVal); pvarg->pdispVal->Release(); break; case VT_BSTR: SysFreeString(pvarg->bstrVal); break; case VT_I2: case VT_BOOL: case VT_R8: case VT_ERROR: // to avoid erroring on an error return from Excel // no work for these types break; default: return 2; //unknonw type // MessageBox(NULL, _T("ReleaseVariant: Unknown type"), "Failed", MB_OK | MB_ICONSTOP); break; } } ClearVariant(pvarg); return 0; }
void CCopyDlg::OnBnClickedBugtraqbutton() { m_tooltips.Pop(); // hide the tooltips CString sMsg = m_cLogMessage.GetText(); if (m_BugTraqProvider == NULL) return; ATL::CComBSTR parameters; parameters.Attach(m_bugtraq_association.GetParameters().AllocSysString()); ATL::CComBSTR commonRoot; commonRoot.Attach(m_path.GetWinPathString().AllocSysString()); CBstrSafeVector pathList(1); pathList.PutElement(0, m_path.GetSVNPathString()); ATL::CComBSTR originalMessage; originalMessage.Attach(sMsg.AllocSysString()); ATL::CComBSTR temp; m_revProps.clear(); // first try the IBugTraqProvider2 interface CComPtr<IBugTraqProvider2> pProvider2 = NULL; HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2); if (SUCCEEDED(hr)) { ATL::CComBSTR repositoryRoot; repositoryRoot.Attach(m_wcURL.AllocSysString()); ATL::CComBSTR bugIDOut; GetDlgItemText(IDC_BUGID, m_sBugID); ATL::CComBSTR bugID; bugID.Attach(m_sBugID.AllocSysString()); CBstrSafeVector revPropNames; CBstrSafeVector revPropValues; if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp))) { OnComError(hr); } else { if (bugIDOut) { m_sBugID = bugIDOut; SetDlgItemText(IDC_BUGID, m_sBugID); } m_cLogMessage.SetText((LPCTSTR)temp); BSTR HUGEP *pbRevNames; BSTR HUGEP *pbRevValues; HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames); if (SUCCEEDED(hr1)) { HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues); if (SUCCEEDED(hr2)) { if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements) { for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++) { m_revProps[pbRevNames[i]] = pbRevValues[i]; } } SafeArrayUnaccessData(revPropValues); } SafeArrayUnaccessData(revPropNames); } } } else { // if IBugTraqProvider2 failed, try IBugTraqProvider CComPtr<IBugTraqProvider> pProvider = NULL; hr = m_BugTraqProvider.QueryInterface(&pProvider); if (FAILED(hr)) { OnComError(hr); return; } if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp))) { OnComError(hr); } else m_cLogMessage.SetText((LPCTSTR)temp); } m_sLogMessage = m_cLogMessage.GetText(); if (!m_ProjectProperties.sMessage.IsEmpty()) { CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage); if (!sBugID.IsEmpty()) { SetDlgItemText(IDC_BUGID, sBugID); } } m_cLogMessage.SetFocus(); }
///////////////////////////////////////////////////////////////////////////// // AdaptorInfo() // // The function is used to elicit relevant info about the current HW.. //..configuration from the HW API. // The info to extract is: //..1)number of boards installed //..2)board names //..3)supported subsystems (AnalogInput, AnalogOutput, DigitalIO) // The function is called by the engine in response to the ML user.. //..command DAQHWINFO ///////////////////////////////////////////////////////////////////////////// HRESULT Cadvantechadapt::AdaptorInfo(IPropContainer * Container) { LONG lDriverHandle = (LONG)NULL; // driver handle PT_DeviceGetFeatures ptDevFeatures; // Devfeatures table DEVFEATURES DevFeatures; // structure for device features int i = 0; // Index variable // Get the name of the adaptor module TCHAR name[256]; GetModuleFileName(_Module.GetModuleInstance(),name,256); // null returns MATLAB version (non existant) RETURN_HRESULT(Container->put_MemberValue(L"adaptordllname",CComVariant(name))); // Place the adaptor name in the appropriate struct in the engine. RETURN_HRESULT(Container->put_MemberValue(L"adaptorname",variant_t(ConstructorName))); // Find board IDs // Start by obtaining the DeviceList. Not stored. short numDevices; // Number of devices DEVLIST deviceList[MaxDev]; // Space to store device information. CComVariant var; // General CComVariant to return info to adaptor engine. RETURN_ADVANTECH(DRV_DeviceGetList((DEVLIST far *)&deviceList[0], MaxDev, &numDevices)); // Create storage for board IDs, bord names and constructors. TSafeArrayVector<CComBSTR> IDs; // Create A SafeArrayVector to store the IDs in IDs.Allocate(numDevices); // Allocate the memory for the number of devices TSafeArrayVector<CComBSTR> Names; // Create A SafeArrayVector to store the Names in Names.Allocate(numDevices); // Allocate the memory for the number of devices SAFEARRAY *ps; // SafeArray for the subsystem support [nDx3 CComBStrs] CComBSTR *subsystems; SAFEARRAYBOUND arrayBounds[2]; arrayBounds[0].lLbound = 0; arrayBounds[0].cElements = numDevices; arrayBounds[1].lLbound = 0; arrayBounds[1].cElements = 3; // AnalogInput, AnalogOutput, DigitalIO subsystems. ps = SafeArrayCreate(VT_BSTR, 2, arrayBounds); if (ps==NULL) return E_FAIL; // Set up the variant to contain subsystem constructor SafeArray var.parray = ps; var.vt = VT_ARRAY | VT_BSTR; HRESULT hRes = SafeArrayAccessData(ps, (void **)&subsystems); if (FAILED (hRes)) { SafeArrayDestroy (ps); return hRes; } // Now loop through each device, getting the ID, BoardName and subsystem support. wchar_t str[40]; for (i=0; i < numDevices; i++) { // Allocate the ID char* string; string = new char[20]; _ltoa(deviceList[i].dwDeviceNum, string, 10); IDs[i] = CComBSTR(string); // Open Device RETURN_ADVANTECH(DRV_DeviceOpen(deviceList[i].dwDeviceNum,(LONG far *)&lDriverHandle)); // Get BoardNames info Names[i] = CComBSTR(deviceList[i].szDeviceName); // Check to see which subsystems the current board supports. // Get device features ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures; ptDevFeatures.size = sizeof(DEVFEATURES); RETURN_ADVANTECH(DRV_DeviceGetFeatures(lDriverHandle, (LPT_DeviceGetFeatures)&ptDevFeatures)); if ((DevFeatures.usMaxAIDiffChl + DevFeatures.usMaxAISiglChl) > 0) { swprintf(str, L"analoginput('%s',%s)", (wchar_t*)ConstructorName, (wchar_t*)IDs[i]); subsystems[i]=str; } if (DevFeatures.usMaxAOChl > 0) { swprintf(str, L"analogoutput('%s',%s)", (wchar_t*)ConstructorName, (wchar_t*)IDs[i]); subsystems[i + numDevices]=str; } if ((DevFeatures.usMaxDIChl + DevFeatures.usMaxDOChl) > 0) { swprintf(str, L"digitalio('%s',%s)",(wchar_t*) ConstructorName, (wchar_t*)IDs[i]); subsystems[i + 2*numDevices] = str; } // Close device RETURN_ADVANTECH(DRV_DeviceClose((LONG far *)&lDriverHandle)); } // Return Object Constructor Names since they're in var already. SafeArrayUnaccessData (ps); RETURN_HRESULT(Container->put_MemberValue(L"objectconstructorname",var)); // Return the board names var.Clear(); // resuse the same 'var' variable for the boardnames. Names.Detach(&var); RETURN_HRESULT(Container->put_MemberValue(L"boardnames",var)); // Return the board numbers var.Clear(); //reuse the same 'var' variable for the IDs[] IDs.Detach(&var); RETURN_HRESULT(Container->put_MemberValue(L"installedboardids",var)); return S_OK; } // end of AdaptorInfo()
//下载头像 bool CDataBaseSink::OnRequestDownloadFace(WORD wRequestID, DWORD dwContextID, VOID * pData, WORD wDataSize) { //校验参数 ASSERT(wDataSize == sizeof(DBR_GP_DownloadCustomFace)); if ( wDataSize != sizeof(DBR_GP_DownloadCustomFace)) return false; //类型转换 DBR_GP_DownloadCustomFace *pDownloadCustomFace = (DBR_GP_DownloadCustomFace*)pData; LONG lReturnValue=-1; long lSize=0; bool bRet = false; try { lReturnValue=SPDownloadFace(pDownloadCustomFace->dwUserID); //读取数据 if ( lReturnValue==0 ) { DWORD dwImageSize=0; dwImageSize=m_AccountsDBAide.GetValue_DWORD(TEXT("ImgSize")); //读取数据 IDataBase * pIDataBase=m_AccountsDBModule.GetInterface(); _variant_t vtFld; pIDataBase->GetRecordsetValue(TEXT("CustomFaceImage"), vtFld); BYTE * pcbBuf=NULL; SafeArrayAccessData(vtFld.parray,(LPVOID *)&pcbBuf); //投递请求 DBR_GP_DownloadFaceSuccess DownloadFaceSuccess; ZeroMemory(&DownloadFaceSuccess, sizeof(DownloadFaceSuccess)); DownloadFaceSuccess.dwToltalSize = dwImageSize; DownloadFaceSuccess.dwUserID = pDownloadCustomFace->dwUserID; DWORD dwSendSize = 0; while( dwSendSize <dwImageSize ) { //设置数据 if ( 1024 < dwImageSize - dwSendSize ) DownloadFaceSuccess.dwCurrentSize = 1024; else DownloadFaceSuccess.dwCurrentSize = dwImageSize - dwSendSize ; CopyMemory(DownloadFaceSuccess.bFaceData, pcbBuf+dwSendSize, DownloadFaceSuccess.dwCurrentSize); //投递消息 WORD wPostSize = WORD(sizeof(DownloadFaceSuccess)-sizeof(DownloadFaceSuccess.bFaceData)+DownloadFaceSuccess.dwCurrentSize); m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBR_GP_DOWNLOADFACE_SUCCESS, dwContextID, &DownloadFaceSuccess, wPostSize); //递增变量 dwSendSize += DownloadFaceSuccess.dwCurrentSize; } //释放资源 SafeArrayUnaccessData(vtFld.parray); } } catch (IDataBaseException * pIException) { //错误信息 LPCTSTR pszDescribe=pIException->GetExceptionDescribe(); CTraceService::TraceString(pszDescribe,TraceLevel_Exception); } return true; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d X T R N I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadXTRNImage() reads a XTRN image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadXTRNImage method is: % % Image *ReadXTRNImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: Specifies a pointer to an ImageInfo structure. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadXTRNImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; ImageInfo *clone_info; void *param1, *param2, *param3; param1 = param2 = param3 = (void *) NULL; image = (Image *) NULL; clone_info=CloneImageInfo(image_info); if (clone_info->filename == NULL) { clone_info=DestroyImageInfo(clone_info); ThrowReaderException(FileOpenWarning,"No filename specified"); } if (LocaleCompare(image_info->magick,"XTRNFILE") == 0) { image=ReadImage(clone_info,exception); CatchException(exception); } else if (LocaleCompare(image_info->magick,"XTRNIMAGE") == 0) { Image **image_ptr; #ifdef ALL_IMAGEINFO ImageInfo **image_info_ptr; #endif (void) sscanf(clone_info->filename,"%lx,%lx",¶m1,¶m2); image_ptr=(Image **) param2; if (*image_ptr != (Image *)NULL) image=CloneImage(*image_ptr,0,0,MagickFalse,&(*image_ptr)->exception); #ifdef ALL_IMAGEINFO image_info_ptr=(ImageInfo **) param1; if (*image_info_ptr != (ImageInfo *)NULL) image_info=*image_info_ptr; #endif } else if (LocaleCompare(image_info->magick,"XTRNBLOB") == 0) { char **blob_data; size_t *blob_length; char filename[MaxTextExtent]; (void) sscanf(clone_info->filename,"%lx,%lx,%s",¶m1,¶m2,&filename); blob_data=(char **) param1; blob_length=(size_t *) param2; image=BlobToImage(clone_info,*blob_data,*blob_length,exception); CatchException(exception); } else if (LocaleCompare(image_info->magick,"XTRNSTREAM") == 0) { #ifdef IMPLEMENT_THIS MagickBooleanType status; #endif char filename[MaxTextExtent]; size_t (*fifo)(const Image *,const void *,const size_t); (void) sscanf(clone_info->filename,"%lx,%lx,%s",¶m1,¶m2,&filename); fifo=(size_t (*)(const Image *,const void *,const size_t)) param1; clone_info->client_data=param2; #ifdef IMPLEMENT_THIS status=ReadStream(clone_info,fifo,exception); CatchException(exception); #endif } else if (LocaleCompare(image_info->magick,"XTRNARRAY") == 0) { SAFEARRAY *pSafeArray; char *blob_data; size_t blob_length; long lBoundl, lBoundu; HRESULT hr; char filename[MaxTextExtent]; filename[0] = '\0'; (void) sscanf(clone_info->filename,"%lx,%s",¶m1,&filename); hr = S_OK; pSafeArray = (SAFEARRAY *) param1; if (pSafeArray) { hr = SafeArrayGetLBound(pSafeArray, 1, &lBoundl); if (SUCCEEDED(hr)) hr = SafeArrayGetUBound(pSafeArray, 1, &lBoundu); if (SUCCEEDED(hr)) { blob_length = lBoundu - lBoundl + 1; hr = SafeArrayAccessData(pSafeArray, (void**)&blob_data); if(SUCCEEDED(hr)) { if (filename[0] != '\0') { (void) CopyMagickString(clone_info->filename,filename, MaxTextExtent); (void) CopyMagickString(clone_info->magick,filename, MaxTextExtent); } else { *clone_info->magick = '\0'; clone_info->filename[0] = '\0'; } image=BlobToImage(clone_info,blob_data,blob_length,exception); hr = SafeArrayUnaccessData(pSafeArray); CatchException(exception); } } } } else if (LocaleCompare(image_info->magick,"XTRNBSTR") == 0) { BSTR bstr; char *blob_data; size_t blob_length; HRESULT hr; char filename[MaxTextExtent]; filename[0] = '\0'; (void) sscanf(clone_info->filename,"%lx,%s",¶m1,&filename); hr = S_OK; bstr = (BSTR) param1; blob_length = SysStringLen(bstr) * 2; blob_data = (char *)bstr; if ((blob_data != (char *)NULL) && (blob_length>0)) { if (filename[0] != '\0') { (void) CopyMagickString(clone_info->filename,filename, MaxTextExtent); (void) CopyMagickString(clone_info->magick,filename, MaxTextExtent); } else { *clone_info->magick = '\0'; clone_info->filename[0] = '\0'; } image=BlobToImage(clone_info,blob_data,blob_length,exception); CatchException(exception); } } clone_info=DestroyImageInfo(clone_info); return(image); }
HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags, const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers) { PBYTE post_data = NULL; ULONG post_data_len = 0; LPWSTR headers = NULL; HRESULT hres = S_OK; TRACE("navigating to %s\n", debugstr_w(url)); if((Flags && V_VT(Flags) != VT_EMPTY) || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY)) FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n", Flags, Flags ? V_VT(Flags) : -1, TargetFrameName, TargetFrameName ? V_VT(TargetFrameName) : -1); if(PostData && V_VT(PostData) == (VT_ARRAY | VT_UI1) && V_ARRAY(PostData)) { SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data); post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements; } if(Headers && V_VT(Headers) == VT_BSTR) { headers = V_BSTR(Headers); TRACE("Headers: %s\n", debugstr_w(headers)); } set_doc_state(This, READYSTATE_LOADING); This->ready_state = READYSTATE_LOADING; if(This->doc_navigate) { WCHAR new_url[INTERNET_MAX_URL_LENGTH]; if(PathIsURLW(url)) { new_url[0] = 0; }else { DWORD size; size = sizeof(new_url)/sizeof(WCHAR); hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT); if(FAILED(hres)) { WARN("UrlApplyScheme failed: %08x\n", hres); new_url[0] = 0; } } hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data, post_data_len, TRUE); }else { task_navigate_bsc_t *task; task = heap_alloc(sizeof(*task)); task->bsc = create_callback(This, url, post_data, post_data_len, headers); push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL); } if(post_data) SafeArrayUnaccessData(V_ARRAY(PostData)); return hres; }
static void test_parse_filter_data(void) { static const BYTE data_block[] = { 0x02,0x00,0x00,0x00,0xff,0xff,0x5f,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x70,0x69,0x33, 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x30,0x74,0x79,0x33,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x31,0x70,0x69,0x33, 0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x30,0x74,0x79,0x33,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x76,0x69,0x64,0x73, 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; BYTE *prgbRegFilter2 = NULL; REGFILTER2 *pRegFilter = NULL; IFilterMapper2 *pMapper = NULL; SAFEARRAYBOUND saBound; SAFEARRAY *psa = NULL; LPBYTE pbSAData = NULL; HRESULT hr; IAMFilterData *pData = NULL; hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper); ok((hr == S_OK || broken(hr != S_OK)), "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = IFilterMapper2_QueryInterface(pMapper, &IID_IAMFilterData, (LPVOID*)&pData); ok((hr == S_OK || broken(hr != S_OK)), "Unable to find IID_IAMFilterData interface\n"); if (FAILED(hr)) goto out; saBound.lLbound = 0; saBound.cElements = sizeof(data_block); psa = SafeArrayCreate(VT_UI1, 1, &saBound); ok(psa != NULL, "Unable to create safe array\n"); if (!psa) goto out; hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData); ok(hr == S_OK, "Unable to access array data\n"); if (FAILED(hr)) goto out; memcpy(pbSAData, data_block, sizeof(data_block)); hr = IAMFilterData_ParseFilterData(pData, pbSAData, sizeof(data_block), &prgbRegFilter2); /* We cannot do anything here. prgbRegFilter2 is very unstable */ /* Pre Vista, this is a stack pointer so anything that changes the stack invalidats it */ /* Post Vista, it is a static pointer in the data section of the module */ pRegFilter =((REGFILTER2**)prgbRegFilter2)[0]; ok (hr==S_OK,"Failed to Parse filter Data\n"); ok(IsBadReadPtr(prgbRegFilter2,sizeof(REGFILTER2*))==0,"Bad read pointer returned\n"); ok(IsBadReadPtr(pRegFilter,sizeof(REGFILTER2))==0,"Bad read pointer for FilterData\n"); ok(pRegFilter->dwMerit == 0x5fffff,"Incorrect merit returned\n"); out: if (pRegFilter) CoTaskMemFree(pRegFilter); if (psa) { SafeArrayUnaccessData(psa); SafeArrayDestroy(psa); } if (pData) IAMFilterData_Release(pData); if (pMapper) IFilterMapper2_Release(pMapper); }