📄 imagemagickobject.cpp
字号:
CSAVector<VARIANT> v(m_coll.size()); if( !v ) { //m_coll.clear(); return E_OUTOFMEMORY; } else { // WARNING: This nested code block is required because // CSAVectorData ctor performs a SafeArrayAccessData // and you have to make sure the SafeArrayUnaccessData // is called (which it is in the CSAVectorData dtor) // before you use the CSAVector::DetachTo(...). CSAVectorData<VARIANT> msgs(v); if( !msgs ) { //m_coll.clear(); return E_OUTOFMEMORY; } else { for(int index = 0; index < m_coll.size(); ++index) { CComVariant vt(m_coll[index]); HRESULT hr = vt.Detach(&msgs[index]); } } } V_VT(pVar) = VT_ARRAY | VT_VARIANT; V_ARRAY(pVar) = v.Detach(); //m_coll.clear(); }#endif return hr;}STDMETHODIMP MagickImage::Add(SAFEARRAY **pArrayVar, VARIANT *pVar){ return S_OK;}STDMETHODIMP MagickImage::Remove(VARIANT varIndex){ USES_CONVERSION; HRESULT hr = E_INVALIDARG; VARIANTARG *pvarIndex = &varIndex; VARTYPE vt = V_VT(pvarIndex); while (vt == (VT_VARIANT|VT_BYREF)) { pvarIndex = V_VARIANTREF(pvarIndex); vt = V_VT(pvarIndex); } if (V_ISARRAY(pvarIndex)) return hr; switch(vt & ~VT_BYREF) { case VT_BSTR: { if (!V_ISBYREF(pvarIndex)) { CComVariant var; LPTSTR lpszNext; LPTSTR lpszVal = W2T(V_BSTR(pvarIndex)); var = _T(""); if (lpszVal) { MagickLib::Image *image; MagickLib::ExceptionInfo exception; long id; lpszNext = StrChr(lpszVal, _T('.')); if (lpszNext == NULL) lpszNext = _T("%w,%h,%m"); else *lpszNext++ = _T('\0'); // lookup the registry id using token and pass the image in MagickLib::GetExceptionInfo(&exception); image=MagickLib::GetImageFromMagickRegistry(lpszVal, &id, &exception); if (image != (MagickLib::Image *) NULL) { MagickLib::DestroyImageList(image); if (MagickLib::DeleteMagickRegistry(id)) hr = S_OK; } } } break; } case VT_UI1: { long id = V_UI1(pvarIndex); if (MagickLib::DeleteMagickRegistry(id)) hr = S_OK; } case VT_I2: { long id = V_I2(pvarIndex); if (MagickLib::DeleteMagickRegistry(id)) hr = S_OK; } case VT_I4: { long id = V_I4(pvarIndex); if (MagickLib::DeleteMagickRegistry(id)) hr = S_OK; } } return hr;}HRESULT MagickImage::Perform(unsigned int (*func)(MagickLib::ImageInfo *image_info, const int argc,LPTSTR *argv,LPTSTR *text,MagickLib::ExceptionInfo *exception), SAFEARRAY **pArrayVar, VARIANT *pVar,MagickLib::ExceptionInfo *exception){ bool bDebug = false; HRESULT hr = E_INVALIDARG; char *text;#ifdef _DEBUG //DebugBreak();#endif LogInformation(methodName,"enter"); //text = (char *) 0xffffffffL; //char c = *text; // causes and access violation text = (char *)NULL; if( !pArrayVar ) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Argument list is NULL"); } CComSafeArray<VARIANT> rg(*pArrayVar); if( !rg ) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Argument list is bad"); } if( rg.GetDimensions() != 1 ) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Multi dimensional array passed"); } if( rg.GetType() != VT_VARIANT ) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Non VARIANT array type passed"); } int iLastVal = rg.GetCount(); bool bFoundOption = false; for( int i = 0; i < iLastVal; ++i ) { VARIANT &varIndex = rg[i]; VARIANTARG *pvarIndex = &varIndex; VARTYPE vt = V_VT(pvarIndex); while (vt == (VT_VARIANT|VT_BYREF)) { pvarIndex = V_VARIANTREF(pvarIndex); vt = V_VT(pvarIndex); }//-> if (V_ISARRAY(pvarIndex)) { TCHAR sz[128]; SAFEARRAY *psa; if (V_ISBYREF(pvarIndex)) psa = *V_ARRAYREF(pvarIndex); else psa = V_ARRAY(pvarIndex);//-----> {//-------> if (psa) { VARTYPE vatype = (V_VT(pvarIndex) & ~(VT_ARRAY | VT_BYREF)); int ndim = SafeArrayGetDim(psa); if (ndim != 1) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Multi-dimensional arrays not supported"); } if (i < (iLastVal-1))//------------> { bool bFoundIt = false; // This is any array that is not the last one in the arg // list. This means it must be an input so we just pass // it along. switch(vatype)//---------------> { case VT_UI1: { wsprintf(sz, _T("xtrnarray:0x%lx,"),(unsigned long)(psa)); hr = AddArgs(sz); break; } default://-----------------> { CComSafeArray<VARIANT> vals(psa); if (vals)//---------------------> { VARIANT &varFirst = vals[0]; VARIANTARG *pvarFirst = &varFirst; if (V_VT(pvarFirst) == VT_BSTR)//-------------------------> { VARIANT &varSecond = vals[1]; VARIANTARG *pvarSecond = &varSecond; if (V_ISARRAY(pvarSecond))//---------------------------> { if (V_ISBYREF(pvarSecond)) { VARTYPE vatype2 = (V_VT(pvarSecond) & ~(VT_ARRAY | VT_BYREF)); if (vatype2 == VT_UI1) { SAFEARRAY *psax = *V_ARRAYREF(pvarSecond); int ndim2 = SafeArrayGetDim(psax); if (ndim2 != 1) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Input blob support requires a 1d array (1)"); } CW2T str(pvarFirst->bstrVal); wsprintf(sz, _T("xtrnarray:0x%lx,%s"), (unsigned long)(psax),(LPCTSTR)str); hr = AddArgs(sz); } } else { VARTYPE vatype2 = (V_VT(pvarSecond) & ~(VT_ARRAY)); if (vatype2 == VT_UI1) { SAFEARRAY *psax = V_ARRAY(pvarSecond); int ndim2 = SafeArrayGetDim(psax); if (ndim2 != 1) { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Input blob support requires a 1d array (2)"); } else { LPCWSTR pReturnBuffer = NULL; long size = SafeArraySize(psax); hr = SafeArrayAccessData(psax, (void**)&pReturnBuffer); if(SUCCEEDED(hr)) hr = SafeArrayUnaccessData(psax); } CW2T str(pvarFirst->bstrVal); wsprintf(sz, _T("xtrnarray:0x%lx,%s"), (unsigned long)(psax),(LPCTSTR)str); hr = AddArgs(sz); } }//---------------------------> } // end of V_ISARRAY//-------------------------> } // end of == VT_BSTR else { wsprintf(sz, _T("xtrnarray:0x%lx,"),(unsigned long)(psa)); hr = AddArgs(sz); } //vals.UnaccessData(); vals.Detach(); break;//---------------------> } // end of vals not NULL//-----------------> } // end of default case//---------------> } // end of the switch//-------------> } else { // This is the last thing in the arg list and thus must // the output array. We check the contents to a string of // characters that says what format to encode the data in. if (vatype == VT_UI1) { // the output is passed as an array of bytes - this // is the way that VB does it. LPCWSTR pReturnBuffer = NULL; long size = SafeArraySize(psa); long sizeneeded; char *ptrANSI; hr = SafeArrayAccessData(psa, (void**)&pReturnBuffer); if(SUCCEEDED(hr)) { sizeneeded = WideCharToMultiByte( CP_ACP, 0, pReturnBuffer, size/2, (LPSTR)NULL, 0, NULL, NULL); if (sizeneeded) { ptrANSI = new char [sizeneeded + 1]; WideCharToMultiByte( CP_ACP, 0, pReturnBuffer, size, (LPSTR)ptrANSI, sizeneeded, NULL, NULL); ptrANSI[sizeneeded]='\0'; hr = SafeArrayUnaccessData(psa); SafeArrayDestroy(psa); SAFEARRAY* pSafeArray = SafeArrayCreateVector(VT_UI1,0,0); wsprintf(sz, _T("xtrnarray:0x%lx,%s"), (unsigned long)(pSafeArray),ptrANSI); hr = AddArgs(sz); if (ptrANSI) delete ptrANSI; if (V_ISBYREF(pvarIndex)) { V_VT(pvarIndex) = VT_ARRAY | VT_UI1 | VT_BYREF; *V_ARRAYREF(pvarIndex) = pSafeArray; } else { V_VT(pvarIndex) = VT_ARRAY | VT_UI1; V_ARRAY(pvarIndex) = pSafeArray; } } else { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Output array for blob did not specify image format"); } } else { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Output array for blob must be 1d"); } } else { // the output is passed as a variant that is a BSTR // - this is the way that VBSCRIPT and ASP does it. CComSafeArray<VARIANT> vals(psa); if (vals) { VARIANT &varFirst = vals[0]; VARIANTARG *pvarFirst = &varFirst; if (V_VT(pvarFirst) == VT_BSTR) { CW2T str(pvarFirst->bstrVal); //vals.UnaccessData(); SafeArrayDestroy(psa); SAFEARRAY* pSafeArray = SafeArrayCreateVector(VT_UI1,0,0); wsprintf(sz, _T("xtrnarray:0x%lx,%s"), (unsigned long)(pSafeArray),(LPCTSTR)str); hr = AddArgs(sz); if (V_ISBYREF(pvarIndex)) { V_VT(pvarIndex) = VT_ARRAY | VT_UI1 | VT_BYREF; *V_ARRAYREF(pvarIndex) = pSafeArray; } else { V_VT(pvarIndex) = VT_ARRAY | VT_UI1; V_ARRAY(pvarIndex) = pSafeArray; } } } else { ThrowPerformException(exception,MagickLib::ErrorException, "Perform","Output array for blob is invalid"); } } } } else {//-------> ThrowPerformException(exception,MagickLib::ErrorException, "Perform","A passed array is not a valid array"); } }//-----> }//-> // V_ISARRAY else { switch(vt) { case VT_VARIANT: // invalid, should never happen case VT_EMPTY: case VT_NULL: bFoundOption = false; break; case VT_BSTR: case VT_BSTR | VT_BYREF: { LPTSTR lpszVal; LPTSTR lpszNext; CW2T str(V_ISBYREF(pvarIndex) ? *V_BSTRREF(pvarIndex) : V_BSTR(pvarIndex)); lpszVal = (LPTSTR)str; bFoundOption = false; // is this a command line option argument? if ((*lpszVal == _T('+')) || (*lpszVal == _T('-'))) { bFoundOption = true; lpszNext = StrChr(lpszVal, _T('=')); if (lpszNext == NULL) hr = AddArgs(V_BSTR(pvarIndex)); else { int nLength = lpszNext - lpszVal; if (nLength > 16) hr = AddArgs(V_BSTR(pvarIndex)); else { *lpszNext = _T('\0'); hr = AddArgs(lpszVal); hr = AddArgs(++lpszNext); } break; } } else hr = AddArgs(lpszVal); break; } case VT_UI1: case VT_UI1 | VT_BYREF: case VT_I2: case VT_I2 | VT_BYREF:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -