Skip navigation
sabin_black
Currently Being Moderated

Load swf from memory

Mar 6, 2007 2:21 PM

Hi,
I was wondering how to load swfs from memory? I believe it is possible because there are paid software (wrappers for flash) out there that claim to be able to do this (load swf from any source), and they say that it's all in memory and no temporary files.

I tried using the res: protocol, put_MovieData, and put_InlineData, but all those don't seem to work at all.

If I had to guess, using custom protocols will not work because flash probably only supports a few well-known protocols (such as rtmp, http, etc) for security reason. But with put_MovieData and put_InlineData, I have no idea why neither of these things do anything even if the function itself returns a success code. Also there seems to be no documentation for these functions (maybe it's been phased out?).
 
Replies
  • Currently Being Moderated
    Jun 20, 2012 10:38 AM   in reply to sabin_black

    MS VC ATL sample (have built with VS 2010 SP1 + Windows SDK 7.1 and tested on Windows 7 SP1 64-bit with Flash64_11_3_300_257.ocx / Flash32_11_3_300_257.ocx and on Windows XP SP3 32-bit with Flash32_11_3_300_257.ocx):

     

    #pragma pack(push, 1)

     

    typedef struct _FLASH_STREAM_HEADER
    {
        DWORD m_dwSignature;
        DWORD m_dwDataSize;
    } FLASH_STREAM_HEADER, *PFLASH_STREAM_HEADER;

     

    #pragma pack(pop)

     

    static HRESULT LoadFlashMovieFromResource(ATL::CComPtr<IShockwaveFlash>& spShockwaveFlash,
        UINT nResourceID, LPCTSTR pszResourceType = RT_RCDATA)
    {
        HMODULE hModule = ATL::_AtlBaseModule.GetModuleInstance();
        ATLASSUME(hModule != NULL);

     

        //HINSTANCE hResourceInstance = ATL::AtlFindResourceInstance(nResourceID, pszResourceType);
        //HRSRC hResource = ::FindResource(hResourceInstance, MAKEINTRESOURCE(nResourceID),
        //    pszResourceType);

     

        HRSRC hResource = ::FindResource(hModule, MAKEINTRESOURCE(nResourceID), pszResourceType);

     

        if (hResource == NULL)
            return HRESULT_FROM_WIN32(::GetLastError());

     

        DWORD dwResourceDataSize = ::SizeofResource(hModule, hResource);

     

        if (dwResourceDataSize == 0)
            return HRESULT_FROM_WIN32(::GetLastError());

     

        HGLOBAL hResourceLoaded = ::LoadResource(hModule, hResource);

     

        if (hResourceLoaded == NULL)
            return HRESULT_FROM_WIN32(::GetLastError());

     

        ATL::CComPtr<IStream> spStream;

        HRESULT hResult = ::CreateStreamOnHGlobal(NULL, TRUE, &spStream);

     

        if (FAILED(hResult))
            return hResult;

     

        FLASH_STREAM_HEADER fsh = {0x55665566, dwResourceDataSize};

        ULARGE_INTEGER uli = {sizeof (fsh) + dwResourceDataSize};

     

        hResult = spStream->SetSize(uli);

     

        if (FAILED(hResult))

            return hResult;

     

        hResult = spStream->Write(&fsh, sizeof (fsh), NULL);

     

        if (FAILED(hResult))
            return hResult;

     

        hResult = spStream->Write(reinterpret_cast<void*>(hResourceLoaded), dwResourceDataSize, NULL);

     

        if (FAILED(hResult))
            return hResult;

     

        uli.QuadPart = 0;

     

        hResult = spStream->Seek(*reinterpret_cast<PLARGE_INTEGER>(&uli), STREAM_SEEK_SET, NULL);

     

        if (FAILED(hResult))
            return hResult;

     

        ATL::CComPtr<IPersistStreamInit> spPersistStreamInit;

        hResult = spShockwaveFlash.QueryInterface(&spPersistStreamInit);

     

        if (SUCCEEDED(hResult))
            hResult = spPersistStreamInit->Load(spStream);

     

        return hResult;
    }

     

    References:

     

    http://stackoverflow.com/questions/423166/flash-activex-how-to-load-mo vie-from-memory-or-resource-or-stream;

    http://www.flasher.ru/forum/blog.php?b=386.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)