我就加了一个检测是否为虚拟机的函数,像每次加多行汇编老是报错,求解
[Error] expected '(' before '{' token
[Error] 'push' was not declared in this scope
[Error] expected ')' before numeric constant
[Error] expected type-specifier before numeric constant
[Error] expected '{' before numeric constant
[Error] expected ';' before ')' token
BOOL IsInsideVMWare()
{
bool rc = true;
try
{
__asm
{
push edx
push ecx
push ebx
mov eax, 'VMXh'
mov ebx, 0 // any value but not the MAGIC VALUE
mov ecx, 10 // get VMWare version
mov edx, 'VX' // port number
in eax, dx // read port
// on return EAX returns the VERSION
cmp ebx, 'VMXh' // is it a reply from VMWare?
setz [rc] // set return value
pop ebx
pop ecx
pop edx
}
}catch(EXCEPTION_EXECUTE_HANDLER)
{
rc = false;
}
return rc;
}
/*
from https://www.codeproject.com/Articles/9823/Detect-if-your-program-is-running-inside-a-Virtual
*/
__asm是VC++的写法(以及汇编本身采用intel写法),不是什么“C++11”,楼下的回答纯属胡说。
devc++用的g++也可以嵌入汇编,用的是__asm__关键字和at&t语法。
Dev-C++不支持C++11,另外很多语言特性都不支持,已经过时了。现在一般是信息学奥赛会用,如果做应用程序开发还是要用VS、VC之类比较流行强大的环境。