简体   繁体   English

使用Visual Studio 2010的32位C ++到64位C ++

[英]32-bit C++ to 64-bit C++ using Visual Studio 2010

I recently want to convert a 32-bit C++ project to 64-bit, but I am stuck with the first try. 最近,我想将32位C ++项目转换为64位,但是我坚持第一次尝试。 Could you point out any suggestions/checklist/points when converting 32-bit C++ to 64-bit in VS (like converting 32-bit Delphi to 64-bit). 在VS中将32位C ++转换为64位时(例如将32位Delphi转换为64位),您能指出任何建议/清单吗?

int GetVendorID_0(char *pVendorID,int iLen)
{
#ifdef WIN64  // why WIN64 is not defined switching to Active (x64) ?
    // what to put here?
#else
    DWORD   dwA,dwB,dwC,dwD;
    __asm
    {
        PUSHAD
        MOV     EAX,0
        CPUID   //CPUID(EAX=0),
        MOV     dwA,EAX
        MOV     dwC,ECX
        MOV     dwD,EDX
        MOV     dwB,EBX
        POPAD
    }
    memset( pVendorID,      0,iLen);
    memcpy( pVendorID,      &dwB,4);
    memcpy(&pVendorID[4],   &dwD,4);
    memcpy(&pVendorID[8],   &dwC,4);
    return dwA;
#endif
}

Microsoft's compilers (some of them, anyway) have a flag to point out at least some common problems where code will probably need modification to work as 64-bit code. Microsoft的编译器(无论如何还是其中的一些)都有一个标志,指出至少一些常见的问题,其中的代码可能需要修改才能用作64位代码。

As far as your GetVendorID_0 function goes, I'd use Microsoft's _cpuid function, something like this: 就您的GetVendorID_0函数而言,我将使用Microsoft的_cpuid函数,如下所示:

int GetVendorID_0(char *pVendorID, int iLen) { 
    DWORD data[4];

    _cpuid(0, data);
    memcpy(pVendorID, data+1, 12);
    return data[0];
}

That obviously doesn't replace all instances of inline assembly language. 显然,这并不能取代内联汇编语言的所有实例。 You choices are fairly simple (though not necessarily easy). 您的选择相当简单(尽管不一定很容易)。 One is to find an intrinsic like this to do the job. 一种是找到这样的内在要素来完成这项工作。 The other is to move the assembly code into a separate file and link it with your code in C++ (and learn the x64 calling convention). 另一种是将汇编代码移动到一个单独的文件中,并将其与C ++中的代码链接(并学习x64调用约定)。 The third is to simply forego what you're doing now, and write the closest equivalent you can with more portable code. 第三是简单地放弃您现在正在做的事情,并使用可移植的代码编写与您最接近的等价物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++ Visual Studio 2008,将项目从64位迁移到32位 - C++ Visual Studio 2008, moving a project from 64-bit to 32-bit 在64位C ++程序中使用32位库 - Using 32-bit library in 64-bit C++ program 如何使Visual Studio 2012调用本机64位Visual C ++编译器而不是32位x64交叉编译器? - How to make Visual Studio 2012 call the native 64-bit Visual C++ compiler instead of the 32-bit x64 cross-compiler? 从c / c ++应用程序确定32位操作系统还是64位操作系统 - determine 32-bit OS or 64-bit OS from c/c++ application 从32位C#到64位C ++的PostMessage参数 - PostMessage params from 32-bit C# to 64-bit C++ 具有C#的64位解决方案ASP.NET和一个C ++中的32位项目 - 64-bit solution ASP.NET with C# and one project 32-bit in C++ 在Windows 7 64位中开发32位C ++应用程序 - Developing 32-bit C++ application in Windows 7 64-bit 从源代码在64位计算机上构建32位mysql c ++连接器 - Building 32-bit mysql c++ connector from source on a 64-bit machine C ++,用于检查软件是否在32位或64位系统上运行的函数 - C++, function that checks if software runs on 32-bit or 64-bit system "如何从 32 位 C++ 应用程序启动 64 位 Java 应用程序?" - How to start 64-bit Java application from 32-bit C++ application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM