Making intellisense acknowledge variables declared inside macros | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 5, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.