Problems with CAnimateCtrl::Open(resourceID)

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
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

  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:


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

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
bhiggsAuthor Commented:
Edited text of question
You can try to call AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
*every* time you want to load a resource. Worked for me.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Can you send sources to me (I'm at May be I'll help you...
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 ?
bhiggsAuthor Commented:
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!
Take a look at the source code in AFXCMN.INL for
CAnimateCtrl::Open(UINT nID) :
   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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
bhiggsAuthor Commented:
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!


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.