Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 针对Visual Studio 2012中的Windows XP_C++_Visual Studio 2012_Windows Xp Sp3 - Fatal编程技术网

C++ 针对Visual Studio 2012中的Windows XP

C++ 针对Visual Studio 2012中的Windows XP,c++,visual-studio-2012,windows-xp-sp3,C++,Visual Studio 2012,Windows Xp Sp3,大家好, 我最近升级到VisualStudio2012,我喜欢改进的C++11支持和黑暗主题。然而,我正试图编写一个在WindowsXP及更高版本上运行的程序,我遇到了一些奇怪的问题 第一次尝试在XP虚拟机上运行程序时,我收到“这不是有效的Win32程序”错误消息。一些谷歌搜索显示,我需要将更新1应用到VS中,才能针对Windows XP。我搜索了它,但找到了更新2。我应用了它,并将平台工具集设置为v110_xp,然后重新编译我的程序并尝试再次运行它。这一次我没有收到错误消息,但在尝试启动程序时

大家好,

我最近升级到VisualStudio2012,我喜欢改进的C++11支持和黑暗主题。然而,我正试图编写一个在WindowsXP及更高版本上运行的程序,我遇到了一些奇怪的问题

第一次尝试在XP虚拟机上运行程序时,我收到“这不是有效的Win32程序”错误消息。一些谷歌搜索显示,我需要将更新1应用到VS中,才能针对Windows XP。我搜索了它,但找到了更新2。我应用了它,并将平台工具集设置为v110_xp,然后重新编译我的程序并尝试再次运行它。这一次我没有收到错误消息,但在尝试启动程序时,我听到XP的错误声音(与使用MB_ICONERROR调用MessageBox时听到的声音相同),然后什么也没有发生。在Windows XP的事件查看器中也没有提及任何内容

我认为更新2可能会弄糟其他东西,所以我完全卸载了VS2012,包括它留下的所有MS SQL垃圾,重新安装了它,只应用了更新1。再次使用XP工具集编译了我的代码,但同样的事情发生了。尝试启动程序时发出错误声音但没有消息

更多的谷歌搜索显示,我必须将PSAPI_版本定义为1,以针对Windows7之前版本的Process API,所以我这样做了,但问题仍然存在

我开始认为我的代码有问题,所以我制作了最基本的Hello World程序,但它仍然存在同样的问题。所以我现在没有主意了

以下是我用来编译Hello World程序的代码:

main.cpp:

#include "winapi.h"

int WINAPI wWinMain(HINSTANCE inst, HINSTANCE prev, wchar_t *cmdline, int show)
{
    MessageBox(HWND_DESKTOP, L"Let's hope this works in Windows XP...", L"Testing 1... 2... 3...", MB_ICONERROR);

    return 0;
}
winapi.h:

#ifndef WINAPI_H_INCLUDED
#define WINAPI_H_INCLUDED

#ifdef _WIN32

// WINDOWS DEFINES /////////////////////////////////////////////////////////////

// If this is not a console program, let the linker include a manifest to
// enable visual styles.
#ifndef _CONSOLE
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif // _CONSOLE

// Shorten compile time by only including the most basic Windows definitions.
#define WIN32_LEAN_AND_MEAN

#define NOGDICAPMASKS       // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOSYSMETRICS        // SM_*
#define NOICONS             // IDI_*
#define NOKEYSTATES         // MK_*
#define NOSYSCOMMANDS       // SC_*
#define NORASTEROPS         // Binary and Tertiary raster ops
#define OEMRESOURCE         // OEM Resource values (OCR_NORMAL and related constants)
#define NOATOM              // Atom Manager routines
#define NOCLIPBOARD         // Clipboard routines
#define NODRAWTEXT          // DrawText() and DT_*
#define NOKERNEL            // All KERNEL defines and routines
#define NONLS               // All NLS defines and routines
#define NOMEMMGR            // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMETAFILE          // typedef METAFILEPICT
#define NOMINMAX            // Macros min(a,b) and max(a,b)
#define NOOPENFILE          // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
#define NOSERVICE           // All Service Controller routines, SERVICE_ equates, etc.
#define NOSOUND             // Sound driver routines
#define NOTEXTMETRIC        // typedef TEXTMETRIC and associated routines
#define NOWH                // SetWindowsHook and WH_*
#define NOCOMM              // COMM driver routines
#define NOKANJI             // Kanji support stuff.
#define NOHELP              // Help engine interface.
#define NOPROFILER          // Profiler interface.
#define NODEFERWINDOWPOS    // DeferWindowPos routines
#define NOMCX               // Modem Configuration Extensions

// Enable strict typechecking on Windows types like HANDLE, HWND and HDC.
#define STRICT

// Enable targetting of pre-Win7 Process API functions when compiling on
// VS2012 or higher.
#if _MSC_VER >= 1700
# define PSAPI_VERSION 1
#endif // _MSC_VER

// Specify the minimum versions of Windows and Internet Explorer supported
// by this code.
#define NTDDI_VERSION       NTDDI_WIN2K
#define _WIN32_WINNT        _WIN32_WINNT_WIN2K
#define WINVER              _WIN32_WINNT_WIN2K
#define _WIN32_IE           _WIN32_IE_IE50

// WINDOWS INCLUDES ////////////////////////////////////////////////////////////

#include <Windows.h>

#else // _WIN32
// OTHER OS ////////////////////////////////////////////////////////////////////
#error This software has been written with Visual C++ in mind.
////////////////////////////////////////////////////////////////////////////////

#endif // _WIN32

#endif // WINAPI_H_INCLUDED
就像我说的,我完全没有主意了。。。我已经尝试了我能想到的一切。任何有帮助的评论都将不胜感激

问候,

Gerard

在包含任何Windows标题之前,请确保具有以下定义:

#ifndef WINVER
#define WINVER 0x0501
#endif

#ifndef _WIN32_WINNT   // Specifies that the minimum required platform is Windows XP.
#define _WIN32_WINNT 0x0501
#endif

如果您想查看其他替代方案,则仅此而已。

谢谢您的回复,罗杰,但从我问题中的代码中可以看出,我已经定义了WINVER、\u WIN32\u WINNT以及更多。@Jehjoa-doh!对不起,应该仔细看看-大脑衰退!当它失败时,事件日志中是否有条目?
#ifndef WINVER
#define WINVER 0x0501
#endif

#ifndef _WIN32_WINNT   // Specifies that the minimum required platform is Windows XP.
#define _WIN32_WINNT 0x0501
#endif