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

📄 dllcom.cpp

📁 《Windows应用程序捆绑核心编程》配套源码
💻 CPP
字号:
// dllcom.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "dllcom.h"
#include "DllObj.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DllCom object code

#pragma data_seg("SHARED")
char m_strString[256]=TEXT(""); 
volatile bool bInCriticalSection=FALSE;
#pragma data_seg()

#pragma comment(linker,"/SECTION:SHARED,RWS")

CCriticalSection cs;

// 从内存中读取字符串.
__DLLCOM__ LPSTR GetValueString()
{
	while(bInCriticalSection) // 等待.
		Sleep(1);

	return m_strString;
}

// 把字符串存储到共享内存中.
__DLLCOM__  void SetValueString(LPCSTR str)
{ 
	while(bInCriticalSection) // 等待.
		Sleep(1);
	
	cs.Lock();
	bInCriticalSection = TRUE;
	strcpy(m_strString,str);
	bInCriticalSection = FALSE;
	cs.Unlock();
}


/////////////////////////////////////////////////////////////////////////////
// CDllcomApp

BEGIN_MESSAGE_MAP(CDllcomApp, CWinApp)
	//{{AFX_MSG_MAP(CDllcomApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDllcomApp construction

CDllcomApp::CDllcomApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CDllcomApp object

CDllcomApp theApp;

⌨️ 快捷键说明

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