Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Problems with CAnimateCtrl::Open(resourceID)

Posted on 1997-06-03
Medium Priority
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.

Question by:bhiggs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1

Expert Comment

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.

Author Comment

ID: 1301958
Edited text of question

Expert Comment

ID: 1301959
You can try to call AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
*every* time you want to load a resource. Worked for me.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

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

Expert Comment

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 ?

Author Comment

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!

Accepted Solution

cnasarre earned 600 total points
ID: 1301963
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

Expert Comment

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

Author Comment

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!



Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

610 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