**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。
这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
一年前关闭。
这篇文章是编辑并提交审查7天前.
Improve this question的
我正在尝试创建一个程序,它将为一堆消息框生成随机数,然后蓝屏。不要担心,它实际上不会伤害任何人的文件或程序。我一直无法运行我的程序,因为WinEventProc
有一个错误,说a block-scope function may only have extern storage class
。我一直在main内部声明我的函数。换句话说,我一直把我的整个程序放在main()
里面,所以我想知道我是否不能这样做。
#include <iostream>
#include <random>
#include <Windows.h>
#include <winternl.h>
#include "Uh_Oh.h"
using namespace std;
typedef NTSTATUS(NTAPI* pdef_NtRaiseHardError)(NTSTATUS ErrorStatus, ULONG NumberOfParameters, ULONG UnicodeStringParameterMask OPTIONAL, PULONG_PTR Parameters, ULONG ResponseOption, PULONG Response);
typedef NTSTATUS(NTAPI* pdef_RtlAdjustPrivilege)(ULONG Privilege, BOOLEAN Enable, BOOLEAN CurrentThread, PBOOLEAN Enabled);
int main()
{
// Random #'s generated and put in variables
random_device dev;
mt19937 rng(dev());
uniform_int_distribution<std::mt19937::result_type> distx(1, 1920); // distribution for x in range [1, 1920]
uniform_int_distribution<std::mt19937::result_type> disty(1, 1080); // distribution for y in range [1, 1080]
int randomx;
int randomy;
randomx = distx(rng);
randomy = disty(rng);
thread_local int MsgBox_X;
thread_local int MsgBox_Y;
static void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
SetWindowPos(hwnd, NULL, MsgBox_X, MsgBox_Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
int MessageBoxPos(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, int X, int Y)
{
HWINEVENTHOOK hHook = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, NULL, &WinEventProc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
MsgBox_X = X;
MsgBox_Y = Y;
int result = MessageBox(hWnd, lpText, lpCaption, uType);
if (hHook) UnhookWinEvent(hHook);
return result;
}
void _MessageBox()
{
UhOh = MessageBoxPos(NULL, TEXT("Uh Oh!"), TEXT("Your computer ran out of memory! Windows will now crash."), MB_ICONERROR | MB_OK, randomx, randomy);
// ... call same MessageBoxPos function a bunch of more times
// UhOh2
// UhOh3
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
typedef NTSTATUS(NTAPI* pdef_NtRaiseHardError)(NTSTATUS ErrorStatus, ULONG NumberOfParameters, ULONG UnicodeStringParameterMask OPTIONAL, PULONG_PTR Parameters, ULONG ResponseOption, PULONG Response);
typedef NTSTATUS(NTAPI* pdef_RtlAdjustPrivilege)(ULONG Privilege, BOOLEAN Enable, BOOLEAN CurrentThread, PBOOLEAN Enabled);
BOOLEAN bEnabled;
ULONG uResp;
LPVOID lpFuncAddress = GetProcAddress(LoadLibraryA("ntdll.dll"), "RtlAdjustPrivilege");
LPVOID lpFuncAddress2 = GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtRaiseHardError");
pdef_RtlAdjustPrivilege NtCall = (pdef_RtlAdjustPrivilege)lpFuncAddress;
pdef_NtRaiseHardError NtCall2 = (pdef_NtRaiseHardError)lpFuncAddress2;
NTSTATUS NtRet = NtCall(19, TRUE, FALSE, &bEnabled);
NtCall2(STATUS_FLOAT_MULTIPLE_FAULTS, 0, 0, 0, 6, &uResp);
return 0;
}
字符串
1条答案
按热度按时间uklbhaso1#
你必须移动所有这些代码:
字符串
行前
型
不能在其他函数中定义函数。