结果在以下代码中加了一个 _asm int 3 语句 (size_t i 位于 _asm int 3 之后), WDK 始终编译报错,
error C2143: syntax error : missing ';' before 'type'
error C2065: 'i' : undeclaredidentifier
多次尝试之后, 将局部变量的定义语句, 移到了汇编语句之前, 结果就编译成功了.
WHY?? 这个太奇怪了, 不知道哪位大侠能指点一下??
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
//编译成功
size_t i; //局部变量定义必须放在 _asm int 3 之前
#if DBG
_asm int 3
#endif
//编译报错
size_t i; //局部变量定义必须放在 _asm int 3 之前
// 所有的分发函数都设置成一样的。
for(i=0;i<IRP_MJ_MAXIMUM_FUNCTION;i++)
{
driver->MajorFunction[i] = ccpDispatch;
}
// 支持动态卸载。
driver->DriverUnload = ccpUnload;
// 绑定所有的串口。
ccpAttachAllComs(driver);
// 直接返回成功即可。
return STATUS_SUCCESS;
}
4 个解决方案
#1
我也发现同样的问题了。
#2
直接用api吧
void WINAPI DebugBreak(void);
#3
c89 必须在函数开始声明变量
#4
__asm int 3
DebugBreak
The DebugBreak function causes a breakpoint exception to occur in the current process so that the calling thread can signal the debugger and force it to take some action. If the process is not being debugged, the search logic of a standard exception handler is used. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception.
VOID DebugBreak(VOID)
Parameters
This function has no parameters.
Return Values
This function does not return a value.
Microsoft Specific
Causes a breakpoint in your code, where the user will be prompted to run the debugger.
void __debugbreak();
Requirements
Intrinsic
Architecture
__debugbreak
x86, IPF, x64
Header file <intrin.h>
Remarks
The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint.
Note:
When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native. For more information, see __asm.
DebugBreak
The DebugBreak function causes a breakpoint exception to occur in the current process so that the calling thread can signal the debugger and force it to take some action. If the process is not being debugged, the search logic of a standard exception handler is used. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception.
VOID DebugBreak(VOID)
Parameters
This function has no parameters.
Return Values
This function does not return a value.
Microsoft Specific
Causes a breakpoint in your code, where the user will be prompted to run the debugger.
void __debugbreak();
Requirements
Intrinsic
Architecture
__debugbreak
x86, IPF, x64
Header file <intrin.h>
Remarks
The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint.
Note:
When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native. For more information, see __asm.
#1
我也发现同样的问题了。
#2
直接用api吧
void WINAPI DebugBreak(void);
#3
c89 必须在函数开始声明变量
#4
__asm int 3
DebugBreak
The DebugBreak function causes a breakpoint exception to occur in the current process so that the calling thread can signal the debugger and force it to take some action. If the process is not being debugged, the search logic of a standard exception handler is used. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception.
VOID DebugBreak(VOID)
Parameters
This function has no parameters.
Return Values
This function does not return a value.
Microsoft Specific
Causes a breakpoint in your code, where the user will be prompted to run the debugger.
void __debugbreak();
Requirements
Intrinsic
Architecture
__debugbreak
x86, IPF, x64
Header file <intrin.h>
Remarks
The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint.
Note:
When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native. For more information, see __asm.
DebugBreak
The DebugBreak function causes a breakpoint exception to occur in the current process so that the calling thread can signal the debugger and force it to take some action. If the process is not being debugged, the search logic of a standard exception handler is used. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception.
VOID DebugBreak(VOID)
Parameters
This function has no parameters.
Return Values
This function does not return a value.
Microsoft Specific
Causes a breakpoint in your code, where the user will be prompted to run the debugger.
void __debugbreak();
Requirements
Intrinsic
Architecture
__debugbreak
x86, IPF, x64
Header file <intrin.h>
Remarks
The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint.
Note:
When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native. For more information, see __asm.