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

FPC_AddOnLoadExternalResourceHandler

Syntax

[ C++ ]
typedef HRESULT (WINAPI *PLOAD_EXTERNAL_RESOURCE_HANDLER)(LPCTSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam);
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++ ]
m_dwHandlerCookie = 
   FPC_AddOnLoadExternalResourceHandler(hFPC, 
                                        &OnLoadExternalResourceHandler, 
                                        0);

HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC)
{
	HRESULT hr = E_FAIL;

	if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
	{
		IStream* pMemStream = NULL;
		CreateStreamOnHGlobal(NULL, TRUE, &pMemStream);

		while (...)
			pMemStream->Write(...);
		
		*ppStream = pMemStream;

		hr = S_OK;
	}

	return hr;
}

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

  • Return S_OK
  • Don't release passed IStream

[ C++ ]
m_dwHandlerCookie = 
   FPC_AddOnLoadExternalResourceHandler(hFPC, 
                                        &OnLoadExternalResourceHandler, 
                                        0);

HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC)
{
	HRESULT hr = E_FAIL;

	if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
	{
		while (...)
			(*ppStream)->Write(...);

		hr = S_OK;
	}

	return hr;
}

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++ ]
m_dwHandlerCookie = 
   FPC_AddOnLoadExternalResourceHandler(hFPC, 
                                        &OnLoadExternalResourceHandler, 
                                        0);

HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam)
{
	HRESULT hr = E_FAIL;

	if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
	{
		IStream* pStream = *ppStream;

		IStream* pStreamForMarshalling;
		CoMarshalInterThreadInterfaceInStream(IID_IStream, pStream, &pStreamForMarshalling);

		DWORD dwThreadId;
		HANDLE hThread = CreateThread(NULL, 0, &FlashContentProviderThread, (LPVOID)pStreamForMarshalling, 0, &dwThreadId);
		CloseHandle(hThread);

		return S_ASYNCHRONOUS;
	}

	return hr;
}

DWORD WINAPI FlashContentProviderThread(LPVOID lpParameter)
{
	CoInitialize(NULL);

	IStream* pStreamForMarshalling = (IStream*)lpParameter;

	IStream* pStream;
	CoUnmarshalInterface(pStreamForMarshalling, IID_IStream, (void**)&pStream);

	while (...)
	{
		if (S_OK != pStream->Write(...))
			break;
	}

	pStreamForMarshalling->Release();
	pStream->Release();

	CoUninitialize();

	return 1;
}


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