Solved

CMap and STL coexistence...

Posted on 2000-03-31
5
258 Views
Last Modified: 2013-11-20
I'm trying to make use of a CMap in a project which uses STL (set, multiset). The problem is that the CMap constructor never gets called for the static CMap member variable.

in the application header:
     COXSound m_oxSound;

in the header of the COXSound class:

protected:
     static CMap<COXSound*, COXSound*, DWORD, DWORD> m_allSoundObjects;

in the COXSound impl. file:

#include "OXSound.h"
IMPLEMENT_SERIAL(COXSound, CObject, 1)

/////////////////////////////////////
// Definition of static members
CMap<COXSound*, COXSound*, DWORD, DWORD> COXSound::m_allSoundObjects;


in the application's InitInstance():

     m_oxSound.SetCallbackWnd(m_pMainWnd);

     // can this machine playback waves?
     if (m_oxSound.CanPlay())
     {
          // call constructor just to init member stuff...
          COXSound* pSound = new COXSound;
          delete pSound;
          pSound = NULL;
   
         if (m_oxSound.Open(_T("thx.wav")))
         {
          m_oxSound.Play(FALSE, TRUE);
         } // end if
     } // end if

The code in the COXSound constructor gets called without the CMap constructor having been called, and the code ASSERTs within afxtempl.h attempting to do the SetAt() call.

Is it possible that STL is interfering with this, or what other things should I look for??


0
Comment
Question by:captainkirk
  • 3
5 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
Since m_allSoundObjects is a static member variable, the constructor is called at the very beginning of the program. The constructor should have been called. There is something else wrong. Give us more information.
0
 
LVL 4

Author Comment

by:captainkirk
Comment Utility
chensu - the CRT code which calls the constructors specific to the app does not recognize that the CMap constructor needs to be called and bypasses it. If I take the m_oxSound variable out and any references to it, then the CMap constructor gets called. I can post the sound player code here if you want - it's a bit lengthy...
0
 
LVL 4

Accepted Solution

by:
abancroft earned 150 total points
Comment Utility
I wonder if it has anything to do with you CWinApp class being a global member at file scope...?

Can you replace CMap with std::map?
0
 
LVL 4

Author Comment

by:captainkirk
Comment Utility
abancroft - ya know, replacing the CMap might be worth a try - I hadn't thought of that, but if it has anything to do with STL interference, that just might make it go away...
0
 
LVL 4

Author Comment

by:captainkirk
Comment Utility
I haven't actually tried the solution - I've been busy on other aspects of my project, but I'm pretty confident that the suggestion will work...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
cat dog challenge 18 122
iSeries FTP Exit Program 8 113
Replacement selected text 2 47
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: 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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

17 Experts available now in Live!

Get 1:1 Help Now