动态链接库.cpp

来自「这是操作系统的上机资料,关于通信和动态连接库的部分.」· C++ 代码 · 共 49 行

CPP
49
字号

#include "stdafx.h"

#include"stdio.h"
extern "C"  __declspec(dllexport)   void chuansong(HANDLE hPipeHandle1);

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}


 void chuansong(HANDLE hPipeHandle1)

{int err;
	char p[50];
	char q[50];
	BOOL rc;
	DWORD BytesRead,BytesWrite;
	BytesRead=20;//yhy add
printf("Handle in dll =%d\n",hPipeHandle1);
rc=ReadFile(hPipeHandle1,p,BytesRead,&BytesRead,(LPOVERLAPPED)NULL);//yhy add从管道中读取数据


	if (rc==0 && BytesRead==0 ) 
		{	err=GetLastError();
			printf("Server Read Pipe Fail!err=%d\n",err);
//	exit(3);
	}
	else 
	{
		printf("Server Read Pipe Success!\n");
			printf("客户方发送的消息为in dll:%s\n",p);
	}

		rc=strcmp(p,"end");
	//if (rc==0)	break; 	

                strcpy(q,"abcdef!");

		BytesWrite=strlen(q);//yhy add
		rc=WriteFile(hPipeHandle1,q,BytesWrite,&BytesWrite,(LPOVERLAPPED)NULL);//yhy add

		if (rc==0) printf("Server Write Pipe Fail!\n");
		else printf("Server Write Pipe Success!\n");
 }

⌨️ 快捷键说明

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