Solved

Problems with CAnimateCtrl::Open(resourceID)

Posted on 1997-06-03
9
585 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
Comment Utility
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
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

by:yonat
Comment Utility
You can try to call AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
*every* time you want to load a resource. Worked for me.
0
 
LVL 4

Expert Comment

by:AVaulin
Comment Utility
Can you send sources to me (I'm at av@protec.kiev.ua)? May be I'll help you...
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now