我正在尝试通过凭据提供程序中的命名管道与 Windows 服务进行通信,但我不太确定将命名管道代码放置在 COM 接口结构中的哪个位置。我使用 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 服务的传入消息?我该怎么做?