I have a program that works on Windows XP but when I try to run it on Windows 7 I get this error.

Debug Assertion Failed!

File: c:\program files\microsoft visual studio .net 2003\vc7\atlmfc\include\atlcomcli.h
Line: 148

Expression: p!=0


I've googled for hours.

Dani AI

Generated

As hinted, that assertion in atlcomcli.h (Line 148) is the ATL check p!=0 inside the smart-pointer dereference (CComPtr/CComQIPtr operator->). It means a COM-interface smart pointer is NULL when code tries to dereference it. The immediate task is to find where that smart pointer should have been filled and why it was not.

Practical diagnostic steps: run under the debugger, reproduce the assert, open the call stack and inspect the caller frame to see which CComPtr is being dereferenced. Check every HRESULT-returning call that should populate it (CoCreateInstance, QueryInterface, etc.) and log or print those HRESULTs before dereferencing. Also confirm the thread called CoInitialize/CoInitializeEx before any COM use. Example patterns to add around the creation and use:

HRESULT hr = sp.CoCreateInstance(CLSID_MyObject);
if (FAILED(hr)) {
    printf("CoCreateInstance failed: 0x%08X\n", hr);
} else {
    sp->DoSomething();
}
CoInitialize(NULL); // or CoInitializeEx(...)
...
CoUninitialize();

On Windows 7 vs XP the usual platform-specific causes are: the COM server/component is not registered on the Win7 machine; registration was done with the wrong bitness (on x64 use %windir%\SysWOW64\regsvr32.exe for 32-bit DLLs); UAC prevented proper registration; or code runs without COM initialization. Given only sees the failure on Win7, re-register the COM component as administrator and verify the CLSID/ProgID entries, and/or build/test the client explicitly as x86.

Useful tools: the debugger (call stack + locals), Process Monitor (watch registry access for the CLSID), and Dependency Walker (missing native dependencies). The fix is to handle failed HRESULTs, ensure proper CoInitialize and registration, and avoid dereferencing an empty CComPtr (use if (sp) checks or log and return when creation fails).

Recommended Answers

All 3 Replies

have you tried it in Linux? Or do you only use Windows 7 and XP?

Only those 2. I will not attempt on Linux.

Any ideas guys?

Yes: Look on line 148 of the file c:\program files\microsoft visual studio .net 2003\vc7\atlmfc\include\atlcomcli.h, and there you will find a variable named p, probably a pointer, that is zero when it shouldn't be.

Now figure out how that variable got that way and fix it. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.