Solved

CMap and STL coexistence...

Posted on 2000-03-31
5
261 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
ID: 2674198
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
ID: 2687089
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
ID: 2687379
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
ID: 2687812
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
ID: 2701320
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
A short film showing how OnPage and Connectwise integration works.

914 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

16 Experts available now in Live!

Get 1:1 Help Now