We help IT Professionals succeed at work.

Problems with CAnimateCtrl::Open(resourceID)

bhiggs asked
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
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.

Watch Question

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.


Edited text of question

You can try to call AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
*every* time you want to load a resource. Worked for me.

Can you send sources to me (I'm at av@protec.kiev.ua)? 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 ?


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!
This one is on us!
(Get your first solution completely free - no credit card required)

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


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!


Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.