开发者

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 msv开发者_运维问答c ?

Thanks


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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜