Thread: COM Creation & Crashing Issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283

    COM Creation & Crashing Issue

    I have read some tutorials on creating COM objects using Visual C++ 2003. I am getting some errors though (expected). Say I threw in a .lib file, the .h file, and the dll in the debug folder. For example, there are two static member methods in the class X3D::Util. This line runs well...

    X3D::Util::ClearLog();

    However, say X3D::Util::Log in a if-condition, the program crashes. Does this have anything to do with the COM object being static? Why does the first once succeed?

    The output window reads:
    HEAP[T3D Console.exe]: Invalid Address specified to RtlValidateHeap( 00860000, 00883CC0 )
    Unhandled exception at 0x7c901230 in T3D Console.exe: User breakpoint.

    A user breakpoint is presented in the file dbgheap.c.

    This COM object worked fine in a small console program. When I put it into my Windows application, it just started causing this issue. Could it have anything to do with the way this DLL was compiled with this code? I can only think each member is static so the class is never really allocated globally, but its just used on the spot when needed (each member is static), so making an object of it doesn't make much sense.

    Side note too: Sometimes it works just fine. Other times it doesn't. In this case, if X3D::Util::Log() is in a if-block, it freaks out. Put this outside of the if-block, and it works just fine.

    Is there something I'm missing?

    COM .h file:
    Code:
    #ifndef _X3DUTIL_H_ 
    #define _X3DUTIL_H_ 
    
    #include <iostream> 
    #include <fstream> 
    #include <string> 
    #include <windows.h> 
    
    namespace X3D 
    { 
       class __declspec(dllexport) Util 
       { 
       public:  
          static bool Log(std::string debugText, std::string filepath = "log.txt"); 
          static bool ClearLog(std::string filepath = "log.txt"); 
       }; 
    } 
    
    #endif
    COM .cpp file:
    Code:
    #include "X3DUtil.h" 
      
    bool X3D::Util::Log(std::string debugText, std::string file) 
    { 
       std::ofstream out(file.c_str(), std::ios::out | std::ios::app); 
       if (!out.is_open()) 
          return false; 
    
       out << debugText << std::endl; 
       out.close(); 
    
       return true; 
    } 
      
    bool X3D::Util::ClearLog(std::string file) 
    { 
       std::ofstream out(file.c_str(), std::ios::out); 
       if (!out.is_open()) 
          return false; 
    
       out.close(); 
    
       return true; 
    }
    Last edited by dxfoo; 02-18-2008 at 07:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange windows STL crashing problem
    By kdmiller in forum C++ Programming
    Replies: 5
    Last Post: 06-23-2010, 02:25 PM
  2. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  3. type safe issue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:32 PM
  4. Newton + Einstein were wrong!
    By Jez in forum A Brief History of Cprogramming.com
    Replies: 64
    Last Post: 12-14-2004, 02:24 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM