gpt4 book ai didi

c++ - 凭据提供程序和命名管道

转载 作者:行者123 更新时间:2023-11-28 05:37:20 25 4
gpt4 key购买 nike

我正在尝试通过凭据提供程序中的命名管道与 Windows 服务进行通信,但我不太确定将命名管道代码放置在 COM 接口(interface)结构中的什么位置。我使用 SampleHardwareEventCredentialProvider(来自 Microsoft)作为测试台,并在 CSampleCredential.cpp 中创建了以下代码:

// Initializes one credential with the field information passed in.
// Set the value of the SFI_USERNAME field to pwzUsername.

HRESULT CSampleCredential::Initialize(
CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* rgcpfd,
const FIELD_STATE_PAIR* rgfsp
)
{
HRESULT hr = S_OK;

_cpus = cpus;

// Copy the field descriptors for each field. This is useful if you want to vary the field
// descriptors based on what Usage scenario the credential was created for.
for (DWORD i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(_rgCredProvFieldDescriptors); i++)
{
_rgFieldStatePairs[i] = rgfsp[i];
hr = FieldDescriptorCopy(rgcpfd[i], &_rgCredProvFieldDescriptors[i]);
}

// Initialize named pipe
if (SUCCEEDED(hr)) {
HANDLE pipe = CreateNamedPipe("\\\\.\\pipe\\PipeData", PIPE_ACCESS_INBOUND | PIPE_ACCESS_OUTBOUND, PIPE_WAIT, 1, 1024, 1024, 120 * 1000, NULL);
if (pipe == INVALID_HANDLE_VALUE)
{
cout << "Error: " << GetLastError();
}

char data[1024];
DWORD numRead;


ConnectNamedPipe(pipe, NULL);

ReadFile(pipe, data, 1024, &numRead, NULL);
}

这显然不起作用,除非我把它放在错误的位置或者没有初始化 CP 来监听来自 Windows 服务的传入消息?我该怎么做?

最佳答案

在您的 Windows 服务中创建管道。由于您指的是 SampleHardwareEventCredentialProvider 示例,因此存在 CommandWindow.h 及其 cpp 文件。

因为您需要在 CCommandWindow::_InitInstance 方法中使用 CreateFile 函数打开创建的管道。

然后,您可以使用 WriteFile 和 ReadFile 函数轻松地写入和读取管道。

有疑问欢迎追问

关于c++ - 凭据提供程序和命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37953884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com