Andrei
Andrei

Reputation: 8894

simple way to detect that [console] app is running under MSVC

This is for debugging purposes, my C++ console app needs to behave a little differently when it runs under MSVC (2008) vs when it is run notunder MSVC.

Is there simple way to detect that it runs under msvc ?

Thanks

Upvotes: 0

Views: 249

Answers (2)

opc0de
opc0de

Reputation: 11767

You can find out easily if it's being debugged using IsDebuggerPresent api.

http://msdn.microsoft.com/en-us/library/ms680345(v=vs.85).aspx

Then you could do a findwindow to see if the visual studio window is present...

Or as ben said you could enumerate the processes using tlhelp32.h functions Process32First and Process32Next get the parent process of your application (PID) then use GetModuleFileNameEx to check process name equals to visual studio executable file...

Upvotes: 2

Praetorian
Praetorian

Reputation: 109079

The IsDebuggerPresent function returns true when running under the debugger. Here's a list of all available debugger related functions.

Upvotes: 4

Related Questions