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

  • SEARCH
  • Home
  • 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 7531131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:05:51+00:00 2026-05-30T05:05:51+00:00

I have a function BOOL AltairListDialog::GetDocuments() { CComQIPtr<AXAPILib::ICollection> m_Collection; HRESULT hr = m_Collection.CoCreateInstance(LAxapi.Collection); AXAPILib::ICollection

  • 0

I have a function

BOOL AltairListDialog::GetDocuments()
{
    CComQIPtr<AXAPILib::ICollection> m_Collection;
    HRESULT hr = m_Collection.CoCreateInstance(L"Axapi.Collection");
    AXAPILib::ICollection *indices = (AXAPILib::ICollection*) m_Collection.p;

    int status;
    COleVariant ind;
    ind.vt = VT_DISPATCH;
    ind.pdispVal = (IDispatch*) indices;

    return TRUE;
}

I use a DLL which implements AXAPILib::ICollection. The function returns “Access violation” after “return TRUE;” but I don’t know why. Any suggestions?

  • 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-30T05:05:52+00:00Added an answer on May 30, 2026 at 5:05 am

    Well, fishing for suggestions does not really fit Stack Overflow’s question and answer format, so it would not be unright to vote to close the question. On the other hand, many others may be doing the same Bad Things™, and could benefit from being told about it. So:

    1. Don’t use C style casts like (AXAPILib::ICollection*) m_Collection.p. If it does not compile without the cast, then it is simply wrong. Adding the cast then hides a bug.

      In this case particular case removing the cast should not have any effect. But it is wholly ungood to have such casts in the code. They not only hide bugs (by suppressing warnings and errors), they actively introduce bugs.

    2. Don’t use C style casts like (IDispatch*) indices. If the code does not compile wihout the cast, then it is simply wrong. Adding the cast then hides a bug.

      For this second cast, removing the cast may have a drastic effect, or not. The potential drastic effect is that the code no longer compiles. In that case, you know what’s wrong (although most likely there’s nothing wrong here except the cast itself).

    3. Don’t mix smart pointers and “raw” pointers unless you really, Really REALLY know what you’re doing.

      Here the smart pointer’s destructor automatically Release()es the object on return from the function. The object is newly created and has no other references to it. Hence its reference count goes to zero now, and it is destroyed.

    After the function return, referring to the destroyed object is Undefined Behavior and very likely to produce the undesired behavior that you have observed.

    One CURE FOR THAT is to ask the smart pointer to give away its ownership of the contained raw pointer.

    For the particular Microsoft smart pointer that you’re using its MSDN Library documentation says that you can do that by calling the Detach() member function. Confusingly, wrt. naming, for the C++ standard library’s smart pointers, and as a general convention, it’s done by calling a release() member. It’s worth noting that Microsoft Release() and standard library release() are two very different operations, respectively ref count decrement versus, uh, detach…

    Finally, it is a good idea to not use the Windows API’s BOOL, and instead use C++ bool. One reason is just to avoid eye-searing all uppercase in the code. And a more technical reason is that bool has just two valid values, namely false and true, while BOOL has a zillion different valid values, which, when a novice programmer writes things like expression() == TRUE, likely leads to bugs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
I have a function with the following definition: virtual bool Process(wtdaFileHandler &daHandler, wtdaGather &daGather);
I have the following structure $('foo').click( function() { var bool = false; $('bar').animate( function()
I have a function which takes several boolean template arguments: template<bool par1, bool par2,
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
I have the following higher-order function: public static Func<T, bool> Not<T>(Func<T, bool> otherFunc) {
Say I have the following function: bool foo (int a); // This method declaration
I have the following function (which worked in Visual Studio): bool Plane::contains(Vector& point){ return
Let's say I have this code: int function(bool b) { // execution path 1
In a switch statement inside a bool function I have this. Do I add

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.