Making intellisense acknowledge variables declared inside macros

The time-saving technology of intellisense is a real bonus for all of us who use variables with a little more meaning to their names than m_nOad. Among other things, it allows for parameter info (far less F1 inquiries) and member info. However, if the variable you are trying to use Intellisense on is not explicitly defined, but rather defined in some kind of macro (as is the case in certain MFC and ATL macros), one cannot use that variable with intellisense.

The simplest way of avoiding that problem is using Intellisense's own disadvantages to our advantage. Take for example the following MFC custom interface implementation code:


HRESULT CSomeClass::XSomeInterface::SomeMethod(long SomeParam)
{
 METHOD_PROLOGUE(CSomeClass,SomeInterface);

 // If I were to write pThis-> now, I would
 //not get the expected drop down list of members.
}
To solve this, we will actually define the variable, only make the compiler ignore it:

HRESULT CSomeClass::XSomeInterface::SomeMethod(long SomeParam)
{
 METHOD_PROLOGUE(CSomeClass,SomeInterface);
#ifdef SOMETHING_WHICH_IS_NOT_DEFINED
CSomeClass* pThis;
#endif
 // If I were to write pThis-> now, the list would
 // pop-up and give me the list of members. Problem solved.
}
Now, this will make your code a little less readable, and is a drag to write each time. Instead, we can do the same thing to define something that intellisense will recognize as a "global variable":

In your implementation code, at it's beginning, repeat that same #ifdef sequence.


#include "this.h"
#include "and_that.h"
#ifdef SOMETHING_WHICH_IS_NOT_DEFINED
CSomeClass* pThis;
#endif
Now, in your method implementation:

HRESULT CSomeClass::XSomeInterface::SomeMethod(long SomeParam)
{
 METHOD_PROLOGUE(CSomeClass,SomeInterface);

 // If I were to write pThis-> now, I would
 // get the expected drop down list of members without
 // "declaring" that variable again and again.
}
Note: The example given here was about MFC's implementation of custom interfaces, however, it's true for every place you have macros defining variables. The global method, when not applied correctly, will yield unexpected intellisense behavior.

Date Last Updated: February 4, 1999


Comments

  • Alternative to Intelisense

    Posted by Legacy on 09/28/2000 12:00am

    Originally posted by: Tony Bloomer

    This is probably not very relevant to many people, however any of you out there who are annoyed with the limitations of intellisence may be interested to know that there is an alternative that is pretty damn good. www.wholetomato.com have a product that replaces all of intellisence's functionalitly and adds a great deal more. Including macro parameters and function definitions from any library that your project is using not just the standard ones. Needs a pretty fast PC to run it without irritating delays but well worth it for Lazy people. Not sure as to the price.

    I know I can't spell intellisen(c/s)e proberly, or anything else so don't bother telling me.

    Cheers

    Tony

    Reply
  • Shark

    Posted by Legacy on 09/16/2000 12:00am

    Originally posted by: Sharon Leon

    Shahar Prish, ata pashut karish!

    Reply
  • Very helpful

    Posted by Legacy on 03/24/1999 12:00am

    Originally posted by: Michael Borysenko

    Despite that other guys (rude) comments, I found this tip quite useful. I am using smart pointers and now I can finally get IntelliSense to give me the proper tooltips on them!

    Reply
  • Whatever...

    Posted by Legacy on 02/12/1999 12:00am

    Originally posted by: Warren Marshall

    "The time-saving technology of intellisense is a real bonus for all of us who use variables with a little more meaning to their names than m_nOad."

    Yeah. Intellisense is of absolutely no use to those of us who like to know the scope and type of our variables is. Thanks for the lesson in coding style... appreciated.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 29, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this eSeminar, Gene Kim will discuss these survey findings and will share woeful tales of artifact management gone wrong! Gene will also share examples of how …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds