c++ - 从 IIS 7.5 Web 应用程序调用 Win32 CreateEvent() 失败

标签 c++ winapi interop zeromq

我正在使用本地库 ( libzmq ),它由 C# 包装器 ( clrzmq ) 调用。 IIS Web 应用程序(IIS 7.5、Windows Server 2008 R2、ASP.NET MVC 3)正在使用它。

native 库调用 CreateEvent()但是在使用 ApplicationPoolIdentity 运行 Web 应用程序时失败。如果我改用 LocalSystem 帐户,它会起作用,但我不想这样做。

我已经尝试过使用和不使用事件名称的“Global\”前缀。

有没有办法为 ApplicationPoolIdentity 提供所需的权限?

相关代码片段如下:

//  Make the following critical section accessible to everyone.
SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof (sa);
sa.bInheritHandle = FALSE;
SECURITY_DESCRIPTOR sd;
BOOL ok = InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
win_assert (ok);
ok = SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE);
win_assert (ok);
sa.lpSecurityDescriptor = &sd;

//  This function has to be in a system-wide critical section so that
//  two instances of the library don't accidentally create signaler
//  crossing the process boundary.
HANDLE sync = CreateEvent (&sa, FALSE, TRUE,
    "Global\\zmq-signaler-port-sync");
win_assert (sync != NULL);

它在最后一行失败,因为 sync 为空。

供引用:

// Provides convenient way to check GetLastError-style errors on Windows.
#define win_assert(x) \
    do {\
        if (unlikely (!(x))) {\
            char errstr [256];\
            zmq::win_error (errstr, 256);\
            fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
                __FILE__, __LINE__);\
            zmq::zmq_abort (errstr);\
        }\
    } while (false)

#endif

最佳答案

关于c++ - 从 IIS 7.5 Web 应用程序调用 Win32 CreateEvent() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11118493/

相关文章:

c++ - 逐步将 Delphi 移植到 C++

c++ - 为什么 C++ 模运算符对 -1 % str.size() 返回 0?

c++ - 如何在 SendInput 中使用扩展扫描码

c++ - waitforsingleobject 等待一个已经发出信号的事件

interop - FHIR 互操作平台选择

c++ - 使用 Qt C++ 写入文本文件

c++ - 使用 OpenCV 通过直方图查找 HSV 阈值

perl - 如何停止使用 Win32::Daemon 启动的 Win32 服务?

c# - 在 Web 浏览器控件中控制 Excel

WPF-DirectX 互操作问题(D3DImage)