⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memoryrw.cpp

📁 两台PC电脑间数据的通讯,这是接受端的VC源码,与发送端配合使用,两台PC使用局域网连接,可高速传送数据
💻 CPP
字号:
// MemoryRW.cpp: implementation of the CMemoryRW class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MemoryRW.h"
#include "Winio.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMemoryRW::CMemoryRW()
{
	bTrueAddress=true;
}

CMemoryRW::~CMemoryRW()
{

}

BOOL CMemoryRW::init()
{
	BOOL b_ok=false;
 	if(bTrueAddress)
    {
		b_ok=InitializeWinIo();
		BOOL PciCfg;
		PciCfg = GetPciCfg(&adsbase);
		if(!PciCfg)
			adsbase = 0xd8000;
		return b_ok;
	}
	else
		lpMsg= MemShare.MemShareWrite (ShareName,Max_MenLength);
	return true;
}

void CMemoryRW::WriteMemory(long TrueAddress,long VirtualAddress, short m_store, long ValueType)
{
	switch(ValueType)
	{ 
	//写物理内存 
	case  1:
     SetPhysByte(TrueAddress+adsbase-0xd8000,(PBYTE)(&m_store),2);
	 break;
    case  2:
      memcpy(lpMsg+VirtualAddress-0xd8000,&m_store,2);	
	 break;
     case  3:
       SetPhysByte(TrueAddress+adsbase-0xd8000,(PBYTE)(&m_store),2);
	  memcpy(lpMsg+VirtualAddress-0xd8000,&m_store,2);	
	 break;
	 default:
	   break;
    
	}

}

unsigned short CMemoryRW::ReadMemory(long TrueAddress,long VirtualAddress, long ValueType)
{ 
    unsigned short m_store;
	m_store=(short)0x8000;
  	switch(ValueType)
	{ 
	//物理内存 
	case  1:
     GetPhysByte(TrueAddress+adsbase-0xd8000,(PBYTE)(&m_store),2);
	 break;
    case  2:
      memcpy((PBYTE)(&m_store),lpMsg+VirtualAddress-0xd8000,2);	
	 break;
     case  3:
       GetPhysByte(TrueAddress+adsbase-0xd8000,(PBYTE)(&m_store),2);
	  memcpy((PBYTE)(&m_store),lpMsg+VirtualAddress-0xd8000,2);	
	 break;
	 default:
	   break;
   	}
	
	return  m_store;
}

unsigned short CMemoryRW::GetMemory(long Address)
{
    unsigned short m_store;
	//读物理内存 暂时存在m_store
 	if(bTrueAddress)
		GetPhysByte(Address+adsbase-0xd8000,(PBYTE)(&m_store),2);
	else
		memcpy((PBYTE)(&m_store),lpMsg+Address-0xd8000,2);	
	return  m_store;
}

void CMemoryRW::SetOnTrueAddress(BOOL flag)
{
	bTrueAddress=flag;
}

void CMemoryRW::SetMemory(long Address, short m_store)
{
	//写物理内存 
	if(bTrueAddress)
		SetPhysByte(Address+adsbase-0xd8000,(PBYTE)(&m_store),2);
	else
		memcpy(lpMsg+Address-0xd8000,&m_store,2);	
}

⌨️ 快捷键说明

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