以下 C++ 代码会导致蓝屏。
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
#pragma comment(lib, "ntdll.lib")
using namespace std;
EXTERN_C NTSTATUS NTAPI RtlAdjustPrivilege(ULONG, BOOLEAN, BOOLEAN, PBOOLEAN);
EXTERN_C NTSTATUS NTAPI NtRaiseHardError(NTSTATUS, ULONG, ULONG, PULONG_PTR, ULONG, PULONG);
int main(int argc, char **argv)
{
BOOLEAN bl;
RtlAdjustPrivilege(19, TRUE, FALSE, &bl);
unsigned long response;
NtRaiseHardError(STATUS_ASSERTION_FAILURE, 0, 0, 0, 6, &response);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想为此使用 C#,所以我尝试使用 P/Invoke。但它不起作用。问题出在 NtRaiseHardError 签名上。我还没有在网上找到任何关于它的信息(例如 pinvoke.net 没有显示 NtRaiseHardError 因为它没有记录。)
这是我尝试过的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using …Run Code Online (Sandbox Code Playgroud) C#不允许我这样做.
foreach (Point point in filledPoints)
{
point.X = 0;
}
Run Code Online (Sandbox Code Playgroud)
filledPoints是一个List<Point>
它给了我一个编译器错误:"filledPoints是一个foreach迭代变量,因此无法编辑关联的成员"(对不起,该消息是德语,我很难翻译).但这有效:
foreach (Point point in filledPoints)
{
Point point2 = point;
point2.X = point2.X / oldSize.Width * Size.Width;
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用,是否有更优雅的方式绕过它?