解决WDK7里没有intrin.h的问题 驱动编程

大理寺少卿 · · Windows程序设计
0 0 0

本文共计2889个字,预计阅读时长11.6分钟。

Theme: Solve the problem of missing "intrin.h" in WDK7. Thema: Lösen das Problem des fehlenden "intrin.h" in WDK7. WDK7有个奇怪的BUG,如果在C语言的驱动程序里调用__readmsr,则毫无问题,但如果在C++语言的驱动程序里调用__readmsr,则在编译时报错。 __readmsr之类的“指令函数”(把汇编指令封装成的C风格函数)都在intrin.h里,但WDK7的CRT库里没有intrin.h。 如果直接从VS2010的CRT库里把这个文件复制过去,你会发现编译时报告的错误更多了。 
解决方案是要魔改VS2010的intrin.h。


 /***  
 * intrin.h - declarations/definitions for platform specific intrinsic functions.  *
 * Copyright (c) Microsoft Corporation. All rights reserved. Modified by M5HOME.  
 *  
 *Purpose:  
 * This include file contains the declarations for platform specific intrinsic  
 * functions, or will include other files that have declaration of intrinsic  
 * functions. Also there will be some platform specific macros to be used with  
 * intrinsic functions.  
 *Usage:  
 * Copy this file to "C:\WinDDK\7600.16385.1\inc\crt" or your project directory.  
 * You can add more function declarations above the second "#if defined(__cplusplus)".  
 *  
 ****/
 #pragma once
 #define __INTRIN_H_  
 #ifndef RC_INVOKED  
 #ifndef __midl  
 #if defined(__cplusplus)  
 extern "C"   
 {
 #endif
 /*
 ** __MACHINE  : everything  
 ** __MACHINEX86 : x86 only  
 ** __MACHINEX64 : x64 only  
 ** __MACHINEX86_X64 : x86 and x64 only  
 */  
 #define __MACHINEX86 __MACHINE  
 #define __MACHINEX64 __MACHINE  
 #define __MACHINEX86_X64 __MACHINE  
 /*
 Most intrinsics not available to pure managed code 
 */  
 #if defined(_M_CEE_PURE)  
 #define __MACHINE(X)  __MACHINEZ(X)  
 #define __MACHINEWVMPURE(X) X;  
 #else  #define __MACHINE(X)  X;  
 #define __MACHINEWVMPURE(X) __MACHINEZ(X)  
 #endif  #define __MACHINEZ(X)   
 /* NOTHING */  
 #if !defined(_M_IX86)  
 #undef __MACHINEX86  
 #define __MACHINEX86  __MACHINEZ  
 #endif  
 #if !defined(_M_X64)  
 #undef __MACHINEX64  
 #define __MACHINEX64  __MACHINEZ  
 #endif  
 #if !(defined(_M_IX86) || defined(_M_X64))  
 #undef __MACHINEX86_X64  
 #define __MACHINEX86_X64  __MACHINEZ  
 #endif  __MACHINEX86_X64(void __invlpg(void*))  __MACHINE(void * _AddressOfReturnAddress(void))  __MACHINEX64(unsigned __int64 __readmsr(unsigned long))  
 #if defined(__cplusplus)  }  
 #endif  
 #endif  
 #endif 
 
 
 在魔改版文件里,我只保留了我自己要用的函数。如果你还需要用其他函数,则找一个VS原版的intrin.h,然后把自己所需函数的声明复制进去即可。

最后于 22小时前 被admin编辑 ,原因: