37#ifndef __FlashHandler_H__
38#define __FlashHandler_H__
43#import "../../../../redist/bin/Flash.ocx" named_guids
51inline void replaceAll(std::wstring &sourceStr,
const std::wstring &replaceWhat,
const std::wstring &replaceWith)
53 for(
size_t i = sourceStr.find(replaceWhat); i != std::wstring::npos; i = sourceStr.find(replaceWhat, i + replaceWith.length()))
55 sourceStr.erase(i, replaceWhat.length());
56 sourceStr.insert(i, replaceWith);
62 std::wstring temp(
str.length(), L
' ' );
63 std::copy(
str.begin(),
str.end(), temp.begin() );
74 return value.
getBool()? L
"<true/>" : L
"<false/>";
77 static std::wstringstream converter;
82 return L
"<number>" + converter.str() + L
"</number>";
96 return L
"<string>" + str2 + L
"</string>";
110 return L
"<string>" + str2 + L
"</string>";
119 if(valueStr == L
"<null/>")
121 else if(valueStr == L
"<true/>")
123 else if(valueStr == L
"<false/>")
126 if(valueStr.substr(0, 8) == L
"<string>")
128 std::wstring stringVal = valueStr.substr(8, valueStr.find(L
"</string>", 8) - 8);
138 else if(valueStr.substr(0, 8) == L
"<number>")
140 static std::wstringstream converter;
144 converter.str(valueStr.substr(8, valueStr.find(L
"</number>", 8) - 8));
145 converter >> numValue;
157 result += L
"<invoke name=\"" + funcName + L
"\" returntype=\"xml\">";
161 result += L
"<arguments>";
162 for(Arguments::const_iterator i = args.begin(); i != args.end(); i++)
164 result += L
"</arguments>";
167 result += L
"</invoke>";
177 if((indexA = xmlString.find(L
"<invoke name=\"")) == std::wstring::npos)
180 if((indexB = xmlString.find(L
"\"", indexA + 14)) == std::wstring::npos)
183 funcName = xmlString.substr(indexA + 14, indexB - (indexA + 14));
186 if((indexA = xmlString.find(L
"<arguments>", indexB)) == std::wstring::npos)
190 std::wstring argString(xmlString.substr(indexA, xmlString.find(L
"</arguments>", indexA) - indexA));
192 for(indexA = 0, indexB = 0;
true;)
194 if((indexA = argString.find(L
"<", indexB)) == std::wstring::npos)
197 if((indexB = argString.find(L
">", indexA)) == std::wstring::npos)
200 if(argString[indexB-1] != L
'/')
202 if((indexB = argString.find(L
">", indexB + 1)) == std::wstring::npos)
206 args.push_back(
deserializeValue(argString.substr(indexA, indexB + 1 - indexA)));
212class FlashHandler :
public ShockwaveFlashObjects::_IShockwaveFlashEvents
235 HRESULT result = NOERROR;
236 LPCONNECTIONPOINTCONTAINER cPointContainer = 0;
238 if((
owner->
flashInterface->QueryInterface(IID_IConnectionPointContainer, (
void**)&cPointContainer) == S_OK) &&
239 (cPointContainer->FindConnectionPoint(__uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents), &
connectionPoint) == S_OK))
241 IDispatch* dispatch = 0;
246 result =
connectionPoint->Advise((ShockwaveFlashObjects::_IShockwaveFlashEvents *)dispatch, &
cookie);
252 cPointContainer->Release();
259 HRESULT result = S_OK;
280 if(riid == IID_IUnknown)
282 *ppv = (LPUNKNOWN)
this;
286 else if(riid == IID_IDispatch)
288 *ppv = (IDispatch*)
this;
292 else if(riid == __uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents))
294 *ppv = (ShockwaveFlashObjects::_IShockwaveFlashEvents*)
this;
324 virtual HRESULT STDMETHODCALLTYPE
GetTypeInfo(
UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
329 virtual HRESULT STDMETHODCALLTYPE
GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
UINT cNames, LCID lcid,DISPID* rgDispId)
334 virtual HRESULT STDMETHODCALLTYPE
Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
335 WORD wFlags, ::DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult,
336 ::EXCEPINFO __RPC_FAR *pExcepInfo,
UINT __RPC_FAR *puArgErr)
343 if((pDispParams->cArgs == 2) && (pDispParams->rgvarg[0].vt == VT_BSTR) && (pDispParams->rgvarg[1].vt == VT_BSTR))
344 FSCommand(pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal);
347 if((pDispParams->cArgs == 1) && (pDispParams->rgvarg[0].vt == VT_BSTR))
348 FlashCall(pDispParams->rgvarg[0].bstrVal);
350 case DISPID_READYSTATECHANGE:
353 return DISP_E_MEMBERNOTFOUND;
std::wstring getWString() const
std::string getString() const
virtual void handleFlashCall(const std::wstring &xmlString)=0
ShockwaveFlashObjects::IShockwaveFlash * flashInterface
HRESULT OnProgress(long percentDone)
virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
HRESULT FSCommand(_bstr_t command, _bstr_t args)
ULONG STDMETHODCALLTYPE Release()
virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, ::DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, ::EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr)
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppv)
HRESULT FlashCall(_bstr_t request)
LPCONNECTIONPOINT connectionPoint
virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo)
HRESULT Init(IFlashControl *owner)
ULONG STDMETHODCALLTYPE AddRef()
HRESULT OnReadyStateChange(long newState)
FlashValue deserializeValue(const std::wstring &valueStr)
void replaceAll(std::wstring &sourceStr, const std::wstring &replaceWhat, const std::wstring &replaceWith)
std::wstring ConvertToWString(const std::string &str)
std::wstring serializeValue(const FlashValue &value)
std::wstring serializeInvocation(const std::wstring &funcName, const Arguments &args)
bool deserializeInvocation(const std::wstring &xmlString, std::wstring &funcName, Arguments &args)
_HikariExport std::vector< FlashValue > Arguments
STBI_EXTERN unsigned long const char * str