Solved

CMap and STL coexistence...

Posted on 2000-03-31
5
264 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
Add content to output file 4 63
Separate into files by filename 12 83
"Black Box" Testing of Control System Software 2 53
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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