Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:19:21+00:00 2026-05-23T01:19:21+00:00

I am using few CComVariant type variables to store interface pointers.However, sometime I need

  • 0

I am using few CComVariant type variables to store interface pointers.However, sometime I need to pass interface pointer as NULL.In this case when I do this:

CComVariant vAData,vBData;
......
....
CComQIPtr<IBData> pAData = vAData.punkVal; //vAData is {0, VT_I4} when I pass NULL 

CComQIPtr<IBData>pBData = vBData.punkVal;  //vBData is {0, VT_I4} when I pass NULL

The first line fails and throws exception since the vAData.punkVal = 0xffffffff00000000
But the second line passes fine with no error and it has valid vBData.punkVal value(0x0000000000000000).

I am wondering why the two punkVal are different when both are NULL??
Does anybody has any idea why this is happening??
This throws exception only on 64bit machines.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:19:22+00:00Added an answer on May 23, 2026 at 1:19 am

    CComVariant calls VariantInit() in constructor and that sets vt to VT_EMPTY, but leaves punkVal uninitialized (doesn’t make it null).

    What you try to do is therefore undefined behavior since you try to construct a CComQIPtr passing it an uninitialized pointer.

    If you want a CComVariant holding a null IUnknown* you can do this:

    CComVariant variant( static_cast<IUnknown*>( 0 ) ); // null IUnknown*, VT_UNKNOWN type
    

    now it’s perfectly legal to construct a CComQIPtr:

    CComQIPtr<IWhatever> whatever( variant.punkVal ); //punknVal is null - legal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a few commands to cat a few files, like this: cat somefile
So I have noticed this while using a few differnt languages on Windows XP,
Excuse the question title, couldn't think how to describe this.. Basically, using a few
I'm using a few (2 or 3) master pages in my ASP.NET MVC application
I'm using a few repository which I do not host myself and I thinking
I’m using a few custom MSBuild tasks that are checked into source control. I
I have run a few using batch jobs, but, I am wondering what would
Right now I'm using a few scripts to generate files that I'm including as
I want to encrypt few files using python what is the best way I
I've run into a few problems using a C# regex to implement a whitelist

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.