mslcli.c

来自「day la chuong rtrinh mail slot」· C语言 代码 · 共 49 行

C
49 行
字号
// Client.cpp

#include <windows.h>
#include <stdio.h>
#include <conio.h>

void main(int argc, char *argv[])
{
    HANDLE Mailslot;
    DWORD BytesWritten;
    CHAR ServerName[256];
    char s[100];
    FILE *f;
    // Accept a command line argument for the server to send
    // a message to
   // if (argc < 2)
    //{
      //  printf("Usage: client <server name>\n");
        //return;
//    }

   // sprintf(ServerName, "\\\\%s\\Mailslot\\Myslot", argv[1]);
	//printf("%s",ServerName);

    if ((Mailslot = CreateFile("\\\\.\\Mailslot\\Myslot", GENERIC_WRITE,
        FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
        NULL)) == INVALID_HANDLE_VALUE)
    {
        printf("CreateFile failed with error %d\n", GetLastError());
        return;
    }


//    void docfile(FILE *f){

if ((f=fopen("c:\\a.txt","r"))==NULL) printf ("Loi !");
else {	while ((s[0]=getc(f))!=EOF) {
	  //	printf("%c",s);
      if (WriteFile(Mailslot,s,1,&BytesWritten, NULL) == 0)  {
	        printf("WriteFile failed with error %d\n", GetLastError());
   	     return;
	    }
		}
	}
	fclose(f);
  CloseHandle(Mailslot);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?