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...
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:
COM .cpp file:
class __declspec(dllexport) Util
static bool Log(std::string debugText, std::string filepath = "log.txt");
static bool ClearLog(std::string filepath = "log.txt");
bool X3D::Util::Log(std::string debugText, std::string file)
std::ofstream out(file.c_str(), std::ios::out | std::ios::app);
out << debugText << std::endl;
bool X3D::Util::ClearLog(std::string file)
std::ofstream out(file.c_str(), std::ios::out);