2016-06-21 6 views
0

자격 증명 공급자의 명명 된 파이프를 통해 Windows 서비스와 통신하려고하지만 COM 인터페이스의 구조 내에 명명 된 파이프 코드를 어디에 둘 것인지 잘 모르겠습니다. 내가 테스트 베드로서 (Microsoft에서) SampleHardwareEventCredentialProvider를 사용하고, 나는 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를 초기화 하시겠습니까? 어떻게하면 좋을까요?

답변

1

Windows 서비스에서 파이프를 만듭니다. SampleHardwareEventCredentialProvider 샘플을 언급하고 있으므로 CommandWindow.h 및 해당 cpp 파일이 있습니다.

CCommandWindow :: _ InitInstance 메서드에서 CreateFile 함수를 사용하여 만든 파이프를 열어야합니다.

그러면 WriteFile 및 ReadFile 기능을 사용하여 파이프를 쉽게 읽고 쓸 수 있습니다.

의심의 여지가 있으면 언제든지 문의하십시오