loading .swf into dll

DLL Edition of the F-IN-BOX
tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

loading .swf into dll

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 6:02 pm

I'm attempting to embed a .swf file within a dll that hooks into wininet.dll. I want this swf file to use ExternalInterface to except invocations from the C++ code .

I'm using f-in-box to load the ocx, but I'm having a problem loading the swf file. I'm using Borlands C++ compiler and building my dll using make and a makefile.

I would like to use the loadfromresource method, but I'm not quite sure how to add a 'resource' using a makefile. Is there a way to load an external swf into a dll?

I've been searching for quite sometime, and I would appreciate any help at all.

Thanks!

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Wed Jul 02, 2008 6:46 pm

Thank you for your question.

If I understand you right, you would like to put SWF into resources of the DLL and load it in runtime.

To put SWF, you should use a resource compiler. It creates RES from RC file. Then link RES to the DLL.

To load SWF:

Code: Select all

FPCPutMovieFromResource(hwndFlashPlayerControl, GetModuleHandle("YourDll.dll"), "...", "...");   
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 6:47 pm

To load the swf I'm calling:

FPC_LoadMovie(hwnd, 0, _T("http:/host/file.swf");

And then later, I'm calling:

FPCCallFunction(hwnd, _T("<invoke....."), NULL, NULL);

The method it invokes should communicate to my AIR application through LocalConnection, but its not begin invoked. Any ideas? Thanks.

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 6:49 pm

Thank you for your quick reply. Actually, I dont mind if it gets loaded from a Resource or External (I chose Resource b/c that is what I saw in all of the example code).

Right now I'm trying to load it from an external site. My goal is to be able to load the swf and call a method within it using the external interface. I've got this to work using javascript/swf , but it doesn't seem to be working in my C++ code.

Thanks again for your help

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 6:54 pm

To further explain my code...here is some snippets...

The initialization of ocx and .swf:

m_hFPC = FPC_LoadRegisteredOCX();

if(NULL == m_hFPC){
OutputDebugString(_TEXT("LoadRegisteredOCX() failed"));
}else{
m_hwndFlashPlayerControl =
CreateWindow((LPCTSTR)FPC_GetClassAtom(m_hFPC),
NULL,
WS_CHILD | WS_VISIBLE,
0,
0,
0,
0,
m_hwndFlashPlayerControl,
NULL,
NULL,
NULL);

FPC_LoadMovie(m_hwndFlashPlayerControl, 0, _T("http://host/file.swf"));




And where I try to call external interface method:


FPCCallFunction(m_hwndFlashPlayerControl,
_T("<invoke name=\"sendURL\" returntype=\"xml\"><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>"),
NULL,
NULL);

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Wed Jul 02, 2008 7:25 pm

Looks right... OK.

Is it possible to check whether the function sendURL is really called or not?
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 7:49 pm

It looks like the swf isn't even being loaded. The method sendURL invokes the LocalConnection API and sends a message to my AIR application. For testing purposes, I call sendURL at the time the swf is being initialized, so, when I open the swf in a web brower, my AIR application is getting the message; however, when I run my C++ code, its not being initiated.

I have a feeling it may be due to where the code is running. I'm toying with hooking a DLL into the wininet.dll so that whenever IE goes to a new page, I can capture this event and send the URL to my AIR application. It doesn't look like my DLL is initializing the swf file properly.

Do you have any thoughts on the matter? I really appreciate your feedback.

Thanks!

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Wed Jul 02, 2008 8:05 pm

Just to quick test.

Could you please replace your swf with externalinterface.swf included in the demo zip and call it as shown below:

Code: Select all

void CSample07_ExternalInterfaceDlg::OnCallActionScriptFunction()
{
   BSTR bstrRequest = SysAllocString(L"<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>");
   BSTR bstrResponse;

   if (S_OK ==
      FPCCallFunctionBSTR(m_hwndFlashPlayerControl,
                       bstrRequest,
                     &bstrResponse))
   {
      USES_CONVERSION;

      CString str = OLE2T(bstrResponse);
      AfxMessageBox(CString(_T("The function returned: ")) + str);

      SysFreeString(bstrResponse);
   }

   SysFreeString(bstrRequest);
}


If it works well, you will see this text inside the movie.

Thank you.
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 8:31 pm

Well the problem is that there isn't any UI. Basically, I'm using Flash for its ExternalInterface & LocalConnection, and the AIR application has the UI. My code is in a dll which I hook into IE's calls to urlmod.dll & wininet.dll. Everything is behind the scenes. Currently, I am able to log each URL I navigate to in IE to the system console, but my goal is to push each URL into my .swf file which is able to push the URL to my AIR application.

This would require me to use ExternalInterface API to pass the URL to my .swf, and then my .swf to use LocalConnection API to pass it to my AIR application.

Since my code is sitting in a dll, is there a possibility that f-in-box wouldn't work for me? Or is there a chance that the way Windows initializes certain things would prohibit my .swf from initializing properly?

Thanks again

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Wed Jul 02, 2008 9:01 pm

Well I do see one problem...even after I initialize my hwndFlashPlayerControl, it is still null.

I check for null against it directly after I call FPC_CreateWindow. Is there a reason why the FPC_CreateWindow would return a null?

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Thu Jul 03, 2008 9:00 am

tmillhouse@gmail.com wrote:Well I do see one problem...even after I initialize my hwndFlashPlayerControl, it is still null.

I check for null against it directly after I call FPC_CreateWindow. Is there a reason why the FPC_CreateWindow would return a null?


Could you please check what returns GetLastError() after FPC_CreateWindow?
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Fri Jul 04, 2008 2:58 pm

Do you know of a good way to output the contents of GetLastError (again, sorry I'm fairly new to C/C++). I'm using this approach:

sprintf(msgbuf, "Error [err=%ld]\n", GetLastError());
OutputDebugString(msgbuf);

It is outputting '???????' (a series of question marks) to the debug console.

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Fri Jul 04, 2008 3:17 pm

I guess another question I could ask to help solve the problem is: where is m_hWnd defined? In the example 07 ExternalInterface example, the create window is being called as so:

CreateWindow((LPCTSTR)FPC_GetClassAtom(theApp.m_hFPC),
NULL,
WS_CHILD | WS_VISIBLE | FPCS_NEED_ALL_KEYS, // use FPCS_NEED_ALL_KEYS if you movie should handle all keyboard input (ENTER, TAB etc.)
rc.left,
rc.top,
rc.right - rc.left,
rc.bottom - rc.top,
m_hWnd,
NULL,
NULL,
NULL);

I've searched the entire folder, and I can't find where m_hWnd is being defined. In my code, I put NULL. Could this be a possible reason?

Thanks again for your help.

Tim

tmillhouse@gmail.com
Posts: 29
Joined: Wed Jul 02, 2008 5:54 pm

Postby tmillhouse@gmail.com » Fri Jul 04, 2008 3:51 pm

So I've been reading up on some probable causes, and it turns out that the borlands compiler (which I've been using) does not officially support MFC. So, it looks like I'm going to have to get my original code working under Visual Studio Express to compile with MFC. This is definitely a problem.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Fri Jul 04, 2008 4:22 pm

tmillhouse@gmail.com wrote:Do you know of a good way to output the contents of GetLastError (again, sorry I'm fairly new to C/C++). I'm using this approach:

sprintf(msgbuf, "Error [err=%ld]\n", GetLastError());
OutputDebugString(msgbuf);

It is outputting '???????' (a series of question marks) to the debug console.


Yes, for example:

sprintf(msgbuf, "Error [err=%d]\n", GetLastError());
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html


Return to “DLL Edition”

Who is online

Users browsing this forum: No registered users and 8 guests

cron