Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

preprocessors in visual studio

Posted on 2016-10-23
5
Medium Priority
?
81 Views
Last Modified: 2016-11-12
Hi


This is in context to visual studio and C++ questions. I notice that there are a few preprocessor definitions such as WIN32 , _WINDOWS etc in the Preprocessor section under C/C++.Is there somewhere else that more of these preprocessor definitions could be coming from? For example, in the code i see a check for WINAPI. If it is not listed here in the preprocessor definition, does it mean that it does not exist?

thanks
0
Comment
Question by:LuckyLucks
5 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 1004 total points (awarded by participants)
ID: 41856064
Others, such as WINAPI are defined in Windows headers files.
0
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 332 total points (awarded by participants)
ID: 41856065
You can use #define (and related ones ) to create or remove things that the compiler can use when building the code.

https://msdn.microsoft.com/en-us/library/teas0593.aspx
http://www.cplusplus.com/doc/tutorial/preprocessor/
0
 
LVL 31

Assisted Solution

by:Zoppo
Zoppo earned 332 total points (awarded by participants)
ID: 41856083
In Visual Studio you can use the built-in code browser to find those macros, i.e. right-click the word WINAPI and select Go To Definition ... from context menue, this fills the output with the found location (or a list of locations if multiple were found) where this symbol is defined.
0
 
LVL 35

Assisted Solution

by:sarabande
sarabande earned 332 total points (awarded by participants)
ID: 41857396
If it is not listed here in the preprocessor definition, does it mean that it does not exist?
no, as told by evilrix the macros are defined in header files and for  a non-trivial application you may have hundreds if not thousands of macros defined in header files, especially if you were using many c libraries and c headers. in c++ many macros could be replaced by other means, for example by templates. then the compiler would do the replacements and switches and not the precompiler.

the macros in the c/c++ preprocessor section are macros which are default for the whole project configuration rather than for some source files. for example the _DEBUG and DEBUG macro would be defined for debug builds. or, for a dll project you would define a unique macro what could be used in source code that the dll functions and dll classes were exported by the project. projects that want to use the dll would not define this macro and so they would import the functions and classes from the dll.

note, some configuration settings will also add macros which you don't see in the preprocessor section. for example if you decide for to using 'UNICODE' character set (more accurate: wide characters from UTF16) rather than 'Multi-byte', the visual c++ compiler will define UNICODE and _UNICODE macro. this macro would make all MS strings to be wide character strings (that normally works quite ok if you never try to make a change).  

in the code i see a check for WINAPI
WINAPI resolves to __stdcall (what rules how a function call was handling stack and arguments when being called). WINAPI is a constant (which never was changed and never must be changed). so actually sources would not 'check' on WINAPI but use WINAPI as a specifier if they want define functions with a __stdcall interface rather than with __cdecl what is default.

Sara
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41884549
I think all are relevant information
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question