資格情報プロバイダーで名前付きパイプを介して 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);
}
間違った場所に配置したり、Windows サービスからの受信メッセージをリッスンするように CP を初期化したりしない限り、これは明らかに機能しませんか? どうすればいいですか?