c++ - 我的项目在 vs2008 中编译没有任何问题,但在 2010 中却没有?

标签 c++ visual-studio-2010 visual-studio-2008 multibyte

我有一个 C++ 项目,在 2008 年可以正常编译,但在 2010 年就无法编译。

在 2010 年,如果我将其字符集更改为多字节,它将进行编译,但没有任何字符串可以正常工作,可以准确描述它发生的情况,如果我不更改它,则会显示以下代码错误和警告。

2008 年,它编译并运行得很好,没有出现任何问题。

我在 C++ 方面不是很聪明,所以如果可能的话,尽可能详细、易于理解的响应将帮助我非常了解正在发生的事情并可能修复它。

以下是非多字节时的错误和警告:

    12  IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCWSTR"
    13  IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCWSTR"
Error   10  error C2664: 'URLDownloadToFileW' : cannot convert parameter 2 from 'char [255]' to 'LPCWSTR'
Error   2   error C2664: 'strcmp' : cannot convert parameter 1 from 'WCHAR [256]' to 'const char *'
Error   3   error C2664: 'SetConsoleTitleW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR'
Error   4   error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
Error   5   error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
Error   11  error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [15]' to 'LPCWSTR'
Error   6   error C2664: 'CreateEventW' : cannot convert parameter 4 from 'const char [20]' to 'LPCWSTR'
Error   9   error C2664: 'CCmdHandler::AddMessageBytes' : cannot convert parameter 1 from 'TCHAR *' to 'char *'
Error   7   error C2440: 'initializing' : cannot convert from 'const char [16]' to 'LPTSTR'
Error   8   error C2440: 'initializing' : cannot convert from 'const char [16]' to 'LPTSTR'
Error   1   error C2440: '<function-style-cast>' : cannot convert from 'WCHAR [256]' to 'std::string'

C++ 项目文件:

<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
    ProjectType="Visual C++"
    Version="9.00"
    Name="TheProject"
    ProjectGUID="{96791392-AA33-4460-BFEA-D766216ECAA8}"
    RootNamespace="TheProject"
    Keyword="Win32Proj"
    TargetFrameworkVersion="196613"
    >
    <Platforms>
        <Platform
            Name="Win32"
        />
    </Platforms>
    <ToolFiles>
    </ToolFiles>
    <Configurations>
        <Configuration
            Name="Debug|Win32"
            OutputDirectory="$(SolutionDir)$(ConfigurationName)"
            IntermediateDirectory="$(ConfigurationName)"
            ConfigurationType="2"
            CharacterSet="1"
            >
            <Tool
                Name="VCPreBuildEventTool"
            />
            <Tool
                Name="VCCustomBuildTool"
            />
            <Tool
                Name="VCXMLDataGeneratorTool"
            />
            <Tool
                Name="VCWebServiceProxyGeneratorTool"
            />
            <Tool
                Name="VCMIDLTool"
            />
            <Tool
                Name="VCCLCompilerTool"
                Optimization="0"
                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;THEPROJECT_EXPORTS;LOGTOCONSOLE"
                MinimalRebuild="true"
                BasicRuntimeChecks="3"
                RuntimeLibrary="3"
                UsePrecompiledHeader="2"
                WarningLevel="3"
                DebugInformationFormat="4"
            />
            <Tool
                Name="VCManagedResourceCompilerTool"
            />
            <Tool
                Name="VCResourceCompilerTool"
            />
            <Tool
                Name="VCPreLinkEventTool"
            />
            <Tool
                Name="VCLinkerTool"
                LinkIncremental="2"
                GenerateDebugInformation="true"
                SubSystem="2"
                TargetMachine="1"
            />
            <Tool
                Name="VCALinkTool"
            />
            <Tool
                Name="VCManifestTool"
            />
            <Tool
                Name="VCXDCMakeTool"
            />
            <Tool
                Name="VCBscMakeTool"
            />
            <Tool
                Name="VCFxCopTool"
            />
            <Tool
                Name="VCAppVerifierTool"
            />
            <Tool
                Name="VCPostBuildEventTool"
            />
        </Configuration>
        <Configuration
            Name="Release|Win32"
            OutputDirectory="$(SolutionDir)$(ConfigurationName)"
            IntermediateDirectory="$(ConfigurationName)"
            ConfigurationType="2"
            CharacterSet="2"
            WholeProgramOptimization="1"
            >
            <Tool
                Name="VCPreBuildEventTool"
            />
            <Tool
                Name="VCCustomBuildTool"
            />
            <Tool
                Name="VCXMLDataGeneratorTool"
            />
            <Tool
                Name="VCWebServiceProxyGeneratorTool"
            />
            <Tool
                Name="VCMIDLTool"
            />
            <Tool
                Name="VCCLCompilerTool"
                AdditionalOptions="-D_SCL_SECURE_NO_WARNINGS"
                Optimization="0"
                InlineFunctionExpansion="1"
                EnableIntrinsicFunctions="true"
                FavorSizeOrSpeed="1"
                AdditionalIncludeDirectories="&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include&quot;"
                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;THEPROJECT_EXPORT;LOGTOCONSOLE"
                ExceptionHandling="2"
                RuntimeLibrary="2"
                BufferSecurityCheck="false"
                EnableFunctionLevelLinking="false"
                UsePrecompiledHeader="2"
                WarningLevel="3"
                DebugInformationFormat="3"
            />
            <Tool
                Name="VCManagedResourceCompilerTool"
            />
            <Tool
                Name="VCResourceCompilerTool"
            />
            <Tool
                Name="VCPreLinkEventTool"
            />
            <Tool
                Name="VCLinkerTool"
                LinkIncremental="1"
                AdditionalLibraryDirectories="..\lib"
                GenerateDebugInformation="false"
                SubSystem="2"
                OptimizeReferences="2"
                EnableCOMDATFolding="2"
                TargetMachine="1"
            />
            <Tool
                Name="VCALinkTool"
            />
            <Tool
                Name="VCManifestTool"
            />
            <Tool
                Name="VCXDCMakeTool"
            />
            <Tool
                Name="VCBscMakeTool"
            />
            <Tool
                Name="VCFxCopTool"
            />
            <Tool
                Name="VCAppVerifierTool"
            />
            <Tool
                Name="VCPostBuildEventTool"
            />
        </Configuration>
    </Configurations>
    <References>
    </References>
    <Files>
        <Filter
            Name="Quelldateien"
            Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
            UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
            >
            <File
                RelativePath=".\CmdHandler.cpp"
                >
            </File>
            <File
                RelativePath=".\ConsoleCMD.cpp"
                >
            </File>
            <File
                RelativePath=".\dllmain.cpp"
                >
                <FileConfiguration
                    Name="Debug|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="0"
                        CompileAsManaged="0"
                    />
                </FileConfiguration>
                <FileConfiguration
                    Name="Release|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="0"
                        CompileAsManaged="0"
                    />
                </FileConfiguration>
            </File>
            <File
                RelativePath=".\EntiyManager.cpp"
                >
            </File>
            <File
                RelativePath=".\ICommand.cpp"
                >
            </File>
            <File
                RelativePath=".\MiscManager.cpp"
                >
            </File>
            <File
                RelativePath=".\PipeProtocol.cpp"
                >
            </File>
            <File
                RelativePath=".\Pipes.cpp"
                >
            </File>
            <File
                RelativePath=".\stdafx.cpp"
                >
                <FileConfiguration
                    Name="Debug|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>
                <FileConfiguration
                    Name="Release|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>
            </File>
        </Filter>
        <Filter
            Name="Headerdateien"
            Filter="h;hpp;hxx;hm;inl;inc;xsd"
            UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
            >
            <File
                RelativePath=".\CmdHandler.h"
                >
            </File>
            <File
                RelativePath=".\CommandIDList.h"
                >
            </File>
            <File
                RelativePath=".\ConsoleCMD.h"
                >
            </File>
            <File
                RelativePath=".\detours.h"
                >
            </File>
            <File
                RelativePath=".\EntiyManager.h"
                >
            </File>
            <File
                RelativePath=".\hide.h"
                >
            </File>
            <File
                RelativePath=".\ICommand.h"
                >
            </File>
            <File
                RelativePath=".\IOnFrameClient.h"
                >
            </File>
            <File
                RelativePath=".\Log.h"
                >
            </File>
            <File
                RelativePath=".\MiscManager.h"
                >
            </File>
            <File
                RelativePath=".\PipeProtocol.h"
                >
            </File>
            <File
                RelativePath=".\Pipes.h"
                >
            </File>
            <File
                RelativePath=".\stdafx.h"
                >
            </File>
            <File
                RelativePath=".\targetver.h"
                >
            </File>
        </Filter>
        <Filter
            Name="Ressourcendateien"
            Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
            UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
            >
        </Filter>
        <File
            RelativePath=".\ReadMe.txt"
            >
        </File>
    </Files>
    <Globals>
    </Globals>
</VisualStudioProject>

最佳答案

您的代码似乎不是为使用 UNICODE 字符串而编写的。因此,您应该检查您的项目设置并在“常规”部分中验证您使用的“字符集”。我想你有“使用 Unicode 字符集”,但你需要将其更改为“未设置”。 “使用多字节字符集”不一样。

关于c++ - 我的项目在 vs2008 中编译没有任何问题,但在 2010 中却没有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7051988/

相关文章:

c++ - 如何找到编译瓶颈?

c++ - 子串一个字符 C++

c# - 如何制作脚本/程序以使应用程序始终运行?

c# - Windows azure应用程序开发步骤失败

c# - VB.NET 不区分大小写;区分大小写好吗?

asp.net-mvc - ASP.Net MVC - View 中的编译器错误

vb.net - 从资源启动可执行应用程序而不将其保存在某处

C++ 三重等于?

code-signing - Visual Studio 2010 程序集签名 : An attempt was made to reference a token that does not exist

c++ - 如何使用 Visual Studio 2008 构建在普通旧 XP SP2 上运行且没有并排 DLL 的 C++ 应用程序?