在#include <msi.h>的前面必须引用windows.h
源码如下:
//stdafx.h
#pragma once
#include "targetver.h"
#include <Windows.h>
#include <msi.h>
#include <MsiQuery.h>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
//testmsi.cpp
#include "stdafx.h"
#pragma comment(lib,"Msi.lib")
int _tmain(int argc, _TCHAR* argv[])
{
INSTALLSTATE state = MsiQueryProductState(_T("{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}"));
if(state == INSTALLSTATE_ABSENT)
{
std::cout<<_T("The product is installed for a different user")<<std::endl;
}
else if(state == INSTALLSTATE_ADVERTISED)
{
std::cout<<_T("The product is advertised but not installed")<<std::endl;
}
else if(state == INSTALLSTATE_DEFAULT)
{
std::cout<<_T("The product is installed for the current user")<<std::endl;
}
else if(state == INSTALLSTATE_INVALIDARG)
{
std::cout<<_T("An invalid parameter was passed to the function")<<std::endl;
}
else if(state == INSTALLSTATE_UNKNOWN)
{
std::cout<<_T("The product is neither advertised or installed")<<std::endl;
}
std::cout<<state<<std::endl;
system("PAUSE");
return 0;
}