Solved

Problems with CAnimateCtrl::Open(resourceID)

Posted on 1997-06-03
9
607 Views
Last Modified: 2013-11-20
I am having considerable trouble getting CAnimateCtrl::Open(ID) to work,
where ID is a resource ID.  Microsoft support seems totally clueless
about how to help me figure out what's wrong myself (I don't expect them
to tell me what's wrong, given the complexity of the program.)

Here's my scenario:

Windows NT 4.0
MFC SDI app
main executable contains only an icon resource
Several code DLLs which are all MFC Extension DLLs
A number of resource-only DLLs, which are also MFC Extension DLLs
The app's InitInstance method does the following:

  1. dynamically activates the two major resource-only DLLs (one
     contains our general message text, the other the resources for the
     app's GUI).  This is for Internationalization purposes.
  2. ...
  3. initializes our underlying 'workbench' code, which is a large
     amount of shared code in DLLs
  4. ...
  5. Calls OnFileNew
  6. ...

The app's mainframe::OnCreate() method does the following:

  1. calls the CFrameWnd::OnCreate() method
  2. calls the CreateToolBar method

The CreateToolBar method does the following:

  1. Creates the toolbar in the standard way
  2. expands one of the toolbar 'buttons' to the appropriate size for a
     small animation
  3. Sets up the button's window and rectangle, and does a
     CAnimateCtrl::Create() (the Toolbar class I'm using is derived from
     CToolBar, and includes a single member: a CAnimateCtrl.)
  4. At this point, the code tries to CAnimateCtrl::Open() the
     appropriate .AVI file.  If it opens a file, the animation works;
     If it opens the same AVI in a resource, it doesn't -- the Open returns FALSE,
     meaning it failed.

I have tried about 3 or 4 ways of entering the AVI file into the
resources:

  1. In the resource-only DLL that already contains the resources for
     the GUI
  2. In the main executable (added to the simple Icon resource)
  3. Directly, by editing the .RC file
  4. Through the MSDEV Insert Resource/Custom mechanism
  5. Through the MSDEV Import (file) mechanism
  6. Directly, by editing the .RC2 file in the \res directory

They all appear to be equivalent, but nothing changes -- the Open on the
resource ID always fails.  I have checked obvious things such as
uniqueness of the ID -- it is unique, and I've tried several different
values to make absolutely sure.

I'm assuming that the problem is that the resource isn't being found,
but I can't understand why.  The code just preceding the call to Open
contains things like:

     m_wndToolBar.LoadToolBar(IDR_TOOLBAR1)

and it finds the resource from the IDR_TOOLBAR1 id;  it's in the same
resource-only DLL as the resource ID for the AVI.

What makes it stranger is that I have modified the CMNCTRLS sample app
to test whether there might be a problem with CAnimateCtrl::Open(ID) --
it worked fine for that situation (the resource was added to the main
executable in that case).  Furthermore, we have another group that is
doing something very similar (main executable, with several DLLs,
including a resource-only DLL that they are dynamically activating).
Their AVI animation code works, and I am at a loss to figure out what is
different (they use a different code base, but the operations are
similar).

I've stepped into the Open and through the mystical forest of Afx
stuff.  I have a feeling that the problem might be related to the Afx
module state, but I can't figure out why one resource id is found in the
code just before, and this one isn't.

I'm pulling out my hair at this point.

Can anyone suggest how I might go about figuring out what's wrong?  Like
hook into the code (somewhere in the SDK, I believe) that can tell me
whether it's finding the resource ID, whether it's the right kind of
resource, whether it's corrupted, whatever -- so that I can figure out
what to do to fix it.

All suggestions much appreciated...

Bryan Higgs

More information:

I am using VC++ 4.2
I have tried setting the resouce handle before calling the CAnimateCtrl::Open(resourceID);  no luck.  
I also tried a number of variations using AFX_MANAGE_STATE(AfxSetStaticModuleState()) with no luck.


0
Comment
Question by:bhiggs
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:AVaulin
ID: 1301957
If you use VC 4.0 you can't do anything to solve your problem. I had such problem and solved it when became to use VC 4.1. Also be sure that before using CAnimateCtrl::Open resources handle set to your dll, ie use AfxSetResourceHandle function.
Good luck.
0
 

Author Comment

by:bhiggs
ID: 1301958
Edited text of question
0
 
LVL 5

Expert Comment

by:yonat
ID: 1301959
You can try to call AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
*every* time you want to load a resource. Worked for me.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 4

Expert Comment

by:AVaulin
ID: 1301960
Can you send sources to me (I'm at av@protec.kiev.ua)? May be I'll help you...
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1301961
I have also modified the CMNCTRLS sample and it works fine
You said that you have tried to add the AVI file in the application resources : it worked that way for me in CMNCTRLS.

A silly question : do you use a numeric resource ID for the AVI ?
if not, the control is searching for a file...

Could you send me your particular source code ?
(nasarre@col.bsf.alcatel.fr)
0
 

Author Comment

by:bhiggs
ID: 1301962
RE: Comment from cnasarre
Yes, I used a numeric resource ID.  It gets generated for me when
I add the resource.
Unfortunately, when I use a small app to try to reproduce the
problem, I can't.  I can't send you the source that does
reproduce the problem because it's huge, and also it's proprietary -- my employer would not like it if I sent it!  8^)

Thanks the the attempt to help!
0
 
LVL 1

Accepted Solution

by:
cnasarre earned 200 total points
ID: 1301963
Take a look at the source code in AFXCMN.INL for
CAnimateCtrl::Open(UINT nID) :
{
   ASSERT(::IsWindow(m_hWnd));
   return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, nID);
}

And it seems almost clear for me that Windows knows nothing
about MFC Extension DLLs that you might have defined and it
seems logical to think that it is just trying to retrieve %0
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1301964
As far as I can see, my aswer was cut down on the way :-(

I was explaining that Windows (which implements the control)
knows nothing about MFC Extension DLLs and might be using the
hInstance given at the control creation time (application)
to look for the resource

My solution is to use the second way to call Open()
(1) add the "AVI" in your DLL resource
(2) extract it as a temporary file
(3) call Open() with this temporary file name
(4) delete it when you no longer need your control

I have used custom resource this way to add a font
as a resource and use it at runtime. I can send you
the sample code if you need
0
 

Author Comment

by:bhiggs
ID: 1301965
RE: Comment from cnasarre

Thanks for the idea.

Your snippet of code is from the CAnimateCtrl code, which certainly ought to know about the possibility of MFC extension DLLs, since it's part of MFC.  But it does seem like it's a bug.

We've shipped the product that uses this code, so it's not as critical a problem as it once was (I just used the filename Open).  There are also may be advantages in allowing the customer to change the AVI that is played to something s/he may prefer.

Your comments and suggestions are appreciated!

Bryan

0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Separate files macro - Errors on larger data set 18 69
Macro to save highlighted rows as a separate file 5 43
FizzBuzz challenge 9 81
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question