简体   繁体   English

C ++ Windows代码链接为64位,但不是32位

[英]C++ windows code links in 64bit but not in 32bit

I have code written in C++ on windows. 我在Windows上用C ++编写了代码。 My code compiles and links when I compile it as x64 but not when I change the build configuration to x86. 当我将其编译为x64时,我的代码进行编译和链接,但是当我将构建配置更改为x86时,则不是。

The failure is a linking error. 失败是链接错误。

I'm using the function RtlIsNameInExpression from ntdll. 我正在使用来自ntdll的函数RtlIsNameInExpression。

When I compile it in 32bit mode I get a linkage error (LNK2019) of unresolved external. 当我以32位模式进行编译时,出现未解决的外部链接错误(LNK2019)。

Any ideas why this might happen? 任何想法为什么会发生这种情况?

10x 10倍

first of all - how you declare function and which symbol can not found linker ? 首先-如何声明函数以及找不到链接器的哪个符号?

declaration must be 声明必须是

extern "C" NTSYSAPI BOOLEAN NTAPI RtlIsNameInExpression(
                               _In_     PCUNICODE_STRING Expression,
                               _In_     PCUNICODE_STRING Name,
                               _In_     BOOLEAN         IgnoreCase,
                               _In_opt_ PWCH            UpcaseTable
                               );

i can guess that you miss NTAPI ie __stdacall keyword if you copy-paste from here . 我可以猜测,如果您从此处复制粘贴,您会错过NTAPI__stdacall关键字。 for x64 exist only one calling convention, but for x86 exist different between __stdcall and __cdecl for example. 对于x64,仅存在一个调用约定,但是对于x86,例如__stdcall__cdecl之间存在区别。 this can explain why this found in x64 but not found in x86 这可以解释为什么在x64找到但在x86找不到

what error give you linker (not compiler !) ? 什么错误给您的链接程序(不是编译器!)? unresolved external symbol __imp__RtlIsNameInExpression ? 未解析的外部符号__imp__RtlIsNameInExpression吗? (if yes you really forget __stdcall set) or __imp__RtlIsNameInExpression@16 ? (如果是,您真的忘记了__stdcall集)或__imp__RtlIsNameInExpression@16吗? in this case you declare function correct, but your ntdll.lib not containing this symbol. 在这种情况下,您声明函数正确,但您的ntdll.lib不包含此符号。 (may be you use old ntdll.lib for xp ? ) simply search __imp__RtlIsNameInExpression@16 string as is in ntdll[p].lib - are it found ? (可能是您将旧的ntdll.lib用于xp吗?)只需像在ntdll[p].lib一样搜索__imp__RtlIsNameInExpression@16字符串-是否找到了? if not you have old (xp) version of ntdll i guess. 如果没有,我想你有旧的(xp)版本的ntdll。

The answer is in the online documentation for that function: 答案在该功能的在线文档中:

This function has no associated header file. 该函数没有关联的头文件。 The associated import library, Ntdll.lib, is available in the Microsoft Windows Driver Kit (WDK). 关联的导入库Ntdll.lib在Microsoft Windows驱动程序工具包(WDK)中可用。 You can also call this function using the LoadLibrary and GetProcAddress functions to dynamically link to Ntdll.dll. 您还可以使用LoadLibrary和GetProcAddress函数调用此函数,以动态链接到Ntdll.dll。

If you can't add the ntdll.lib file from the WDK to your link command, then you need to use the LoadLibrary-GetProcAddress approach. 如果无法将WDK中的ntdll.lib文件添加到链接命令中,则需要使用LoadLibrary-GetProcAddress方法。

Also from the same section of documentation: 同样在文档的同一部分:

The functions and structures in Winternl.h are internal to the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release. Winternl.h中的功能和结构是操作系统的内部组件,可能会从一个Windows版本更改为另一个Windows版本,甚至可能在每个版本的Service Pack之间更改。 To maintain the compatibility of your application, you should use the equivalent public functions instead. 为了保持应用程序的兼容性,您应该使用等效的公共函数。 Further information is available in the header file, Winternl.h, and the documentation for each function. 有关更多信息,请参见头文件Winternl.h和每个功能的文档。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM