使用外部dll函数时C ++访问冲突

时间:2019-10-07 04:14:48

标签: c# c++

我正在尝试将我的代码从c#转换为c ++。 C#代码在win32u.dll中调用本机函数。它在c#中有效,但是当我运行c ++函数时,出现此错误:https://gyazo.com/694d768a7392ed67f849f4db4988d7e9

C#代码:

[DllImport("win32u.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern IntPtr NtTokenManagerCreateFlipObjectReturnTokenHandle(int code, void* param1, void* param2, void* param3);

    public static void StackOverflowExample()
    {
        NtTokenManagerCreateFlipObjectReturnTokenHandle(0, null, null, null);
    }

C ++代码:

void test(){

HMODULE hModule = LoadLibrary(L"win32u.dll");

void* procAddr = (void*)GetProcAddress(hModule, "NtTokenManagerCreateFlipObjectReturnTokenHandle");

using tFunction = intptr_t(__stdcall*)(int, void*, void*, void*);
const auto control = static_cast<tFunction>((void*)procAddr);

control(0, NULL, NULL, NULL);

}

0 个答案:

没有答案