1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   | // Named Pipe creation
pipe = CreateNamedPipe(
	pipe_name, // name of the pipe
	PIPE_ACCESS_DUPLEX, // Read/Write
	PIPE_TYPE_BYTE, // send data as a byte stream
	1, // only allow 1 instance of this pipe
	0, // no outbound buffer
	0, // no inbound buffer
	0, // use default wait time
	NULL // use default security attributes
);
if(pipe == NULL || pipe == INVALID_HANDLE_VALUE)
{
	printf("Failed to create the named pipe '%s'!\n", pipe_name);
	CloseHandle(pipe);
	return 6;
}
 
// Write the restore_data on the named pipe
result = WriteFile(
	pipe, // handle to our generic write pipe
	restore_data, // data to send
	sizeof_data, // length of data to send (bytes)
	&numBytesWritten, // will store actual amount of data sent
	NULL // not using overlapped IO
);
if(!result)
{
	printf("Error while sending data to the named pipe: %d\n", GetLastError()); // Affiche : 109
	printf("SizeOfData: %d\tNumBytesWritten: %d\n", sizeof_data, numBytesWritten); // Affiche : Le réel montant et 0.
	CloseHandle(pipe);
	return 2;
} | 
Partager