F-IN-BOX DLL Edition Help >> Extensions >> Functions

FPC_AddOnLoadExternalResourceHandler

Syntax

[ C++ ]
  1. typedef HRESULT (WINAPI *PLOAD_EXTERNAL_RESOURCE_HANDLER)(LPCTSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam);  
  2. DWORD WINAPI FPC_AddOnLoadExternalResourceHandler(HFPC hFPC, PLOAD_EXTERNAL_RESOURCE_HANDLER pHandler, LPARAM lParam);  

Description

Adds new handler. This handler is calling when flash loads external resource by full path. Don't forget to remove the handler using FPC_RemoveOnLoadExternalResourceHandler.

You can provide the content inside the handler by changing the passed pointer.

  • Return S_OK

[ C++ ]
  1. m_dwHandlerCookie =   
  2.    FPC_AddOnLoadExternalResourceHandler(hFPC,   
  3.                                         &OnLoadExternalResourceHandler,   
  4.                                         0);  
  5.   
  6. HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC)  
  7. {  
  8.     HRESULT hr = E_FAIL;  
  9.   
  10.     if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))  
  11.     {  
  12.         IStream* pMemStream = NULL;  
  13.         CreateStreamOnHGlobal(NULL, TRUE, &pMemStream);  
  14.   
  15.         while (...)  
  16.             pMemStream->Write(...);  
  17.           
  18.         *ppStream = pMemStream;  
  19.   
  20.         hr = S_OK;  
  21.     }  
  22.   
  23.     return hr;  
  24. }  

You can provide the content inside the handler by writing to the passed IStream:

  • Return S_OK
  • Don't release passed IStream

[ C++ ]
  1. m_dwHandlerCookie =   
  2.    FPC_AddOnLoadExternalResourceHandler(hFPC,   
  3.                                         &OnLoadExternalResourceHandler,   
  4.                                         0);  
  5.   
  6. HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC)  
  7. {  
  8.     HRESULT hr = E_FAIL;  
  9.   
  10.     if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))  
  11.     {  
  12.         while (...)  
  13.             (*ppStream)->Write(...);  
  14.   
  15.         hr = S_OK;  
  16.     }  
  17.   
  18.     return hr;  
  19. }  

If the size of resource is big, you can provide content in a separate thread:

  • Return S_ASYNCHRONOUS
  • Use CoMarshalInterThreadInterfaceInStream
  • Call CoInitialize / CoUninitialize in a thread
  • If Write of the passed IStream returns not S_OK, the loading should be stopped (for example, if another movie is loading or a flash player is closing)

[ C++ ]
  1. m_dwHandlerCookie =   
  2.    FPC_AddOnLoadExternalResourceHandler(hFPC,   
  3.                                         &OnLoadExternalResourceHandler,   
  4.                                         0);  
  5.   
  6. HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam)  
  7. {  
  8.     HRESULT hr = E_FAIL;  
  9.   
  10.     if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))  
  11.     {  
  12.         IStream* pStream = *ppStream;  
  13.   
  14.         IStream* pStreamForMarshalling;  
  15.         CoMarshalInterThreadInterfaceInStream(IID_IStream, pStream, &pStreamForMarshalling);  
  16.   
  17.         DWORD dwThreadId;  
  18.         HANDLE hThread = CreateThread(NULL, 0, &FlashContentProviderThread, (LPVOID)pStreamForMarshalling, 0, &dwThreadId);  
  19.         CloseHandle(hThread);  
  20.   
  21.         return S_ASYNCHRONOUS;  
  22.     }  
  23.   
  24.     return hr;  
  25. }  
  26.   
  27. DWORD WINAPI FlashContentProviderThread(LPVOID lpParameter)  
  28. {  
  29.     CoInitialize(NULL);  
  30.   
  31.     IStream* pStreamForMarshalling = (IStream*)lpParameter;  
  32.   
  33.     IStream* pStream;  
  34.     CoUnmarshalInterface(pStreamForMarshalling, IID_IStream, (void**)&pStream);  
  35.   
  36.     while (...)  
  37.     {  
  38.         if (S_OK != pStream->Write(...))  
  39.             break;  
  40.     }  
  41.   
  42.     pStreamForMarshalling->Release();  
  43.     pStream->Release();  
  44.   
  45.     CoUninitialize();  
  46.   
  47.     return 1;  
  48. }  


Copyright © Softanics. All rights reserved.
F-IN-BOX is a trademark of Softanics.
Macromedia and Shockwave Flash are trademarks of Adobe