进程间通讯总结 (1)

The Windowsoperating system provides mechanisms for facilitating communications and datasharing between applications. Collectively, the activities enabled by thesemechanisms are calledinterprocess communications (IPC). 有些机制只能实现同一computer上运行的进程间通讯,还有一些能够实现跨网络的进程间通讯。

After youdecide that your application would benefit from IPC, you must decide which ofthe available IPC methods to use. 答案取决于以下几个方面:

·        进程间通讯是否跨网络 (between applications on the localcomputer or across computers on a network)?

·        是否跨系统平台(operating systems)?

·        跟已知的特定Application交流还是跟不确指的Application交流?

·        对通讯内容的format是否有特殊要求?

·        Isperformance a critical aspect of the application? All IPC mechanisms includesome amount of overhead.

·        是解决遗留系统间的通讯吗?当前的新技术(WCF)适用吗?

Using the Clipboard for IPC

The clipboardacts as a central depository for data sharing among applications. The clipboardis a very loosely coupled exchange medium, where applications need only agreeon the data format.

对于Window来说, the clipboard is a set of functions and messages thatenable applications to transfer data.The applications can reside on thesame computer or on different computers on a network.

In fact, theclipboard is a software facility used for short-term data storage and/or datatransfer between documents or applications。是底层技术封装后的功能,并以接口的形式暴露给GUI程序使用!

Earlyimplementations of the clipboard stored data as plain text withoutmeta-information such as typeface, type style or color. More recentimplementations support the multiple types of data, allowing complex datastructures to be stored. These range from styled text formats such as RTF orHTML, through a variety of bitmap and vector image formats to complex datatypes like spreadsheets and database entries.

In Windows inparticular, the internal clipboard functionality of the operating system willautomatically translate data from known advanced formats to simpler formats(such as RTF to plain text, or Unicode to ANSI Text), increasing the likelihoodthat any given application can interpret some form of the original data.

ClipboardMessages:WM_CLEAR, WM_COPY, WM_CUT, WM_PASTE

Using DDE for IPC

DDE is aprotocol that enables applications to exchange data in a variety of formats.Applications can use DDE for one-time data exchanges or for ongoing exchangesin which the applications update one another as new data becomes available.

The dataformats used by DDE are the same as those used by the clipboard. DDE can bethought of as an extension of the clipboard mechanism. The clipboard is almostalways used for a one-time response to a user command, such as choosing thePaste command from a menu. DDE is also usually initiated by a user command, butit often continues to function without further user interaction. You can alsodefine custom DDE data formats for special-purpose IPC between applicationswith more tightly coupled communications requirements.

DDE exchangescan occur between applications running on the same computer or on differentcomputers on a network.

Key Point:  DDE is not as efficient as newertechnologies. However, you can still use DDE if other IPC mechanisms are notsuitable or if you must interface with an existing application that onlysupports DDE. For more information, seeDynamic Data Exchange and Dynamic Data ExchangeManagement Library.

using themessage-based DDE protocol are fully compatible with those that use the DDEML;

The Dynamic DataExchange Management Library (DDEML) provides an interface that simplifies thetask of adding DDE capability to an application. Instead of sending, posting,and processing DDE messages directly, an application uses the functionsprovided by the DDEML to manage DDE conversations.

DDE是对剪切板机制的延伸,提供持续不断通讯的机制。DDEML是对DDE动能以类库的形式加以包装从而更加方便使用。

以了解为主,毕竟有很多更新更方便是有的新技术。

Using Data Copy for IPC

Data copyenables an application to send information to another application using theWM_COPYDATA message. This methodrequires cooperation between the sending application and the receivingapplication. The receiving application must know the format of the informationand be able to identify the sender.

To useWM_COPYDATA, SendMessage is called as follows :

SendMessage(hwReceiver, WM_COPYDATA, (WPARAM) hwSender, (LPARAM) pData );

KeyPoint:  Datacopy can be used to quickly send information to another application usingWindows messaging

例子:

Click "Send Copy Msg" menu to send one WM_COPYDATA message with custom data:MYREC MyRec to the destination window. The destination window's title is "WinTitleInOtherProcess"

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			//......
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case ID_FILE_SEND:
		{							 
							 #define MYDISPLAY 1
							 typedef struct tagMYREC
							 {
								 wchar_t  s1[80];
								 wchar_t  s2[80];
								 DWORD n;
							 } MYREC;
							 COPYDATASTRUCT MyCDS;
							 MYREC MyRec;
							 HRESULT hResult;							 

							 wchar_t szFirstName[100] = _T("Nick");
							 wchar_t szLastName[100] = _T("Liu");
							 int nAge = 37;

							 hResult = StringCbCopy(MyRec.s1, sizeof(MyRec.s1), szFirstName);							 
							 hResult = StringCbCopy(MyRec.s2, sizeof(MyRec.s2), szLastName);							 
							 MyRec.n = nAge;


							 //
							 // Fill the COPYDATA structure
							 // 
							 MyCDS.dwData = MYDISPLAY;          // function identifier
							 MyCDS.cbData = sizeof(MyRec);  // size of data
							 MyCDS.lpData = &MyRec;           // data structure
							 //
							 // Call function, passing data in &MyCDS
							 //
							 //Retrieves a handle to the top - level window(can across process) whose class name and window name match the specified strings.
							 HWND hwDispatch = FindWindow(NULL, _T("WinTitleInOtherProcess"));
							 if (hwDispatch != NULL)
								 SendMessage(hwDispatch,
								 WM_COPYDATA,
								 (WPARAM)(HWND)hWnd,
								 (LPARAM)(LPVOID)&MyCDS);
							 else
								 MessageBox(hWnd, _T("Can't send WM_COPYDATA"), _T("MyApp"), MB_OK);	

							 break;
		}
			
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

In another process (MFC dialog based application), add code to pass the data inside WM_COPYDATA message handler. Use the info from message to value the UI controls.
BOOL CMFCDLGApplicationDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
	// TODO: Add your message handler code here and/or call default

#define MYDISPLAY 1
	typedef struct tagMYREC
	{
		wchar_t  s1[80];
		wchar_t  s2[80];
		DWORD n;
	} MYREC;
	

	
	switch (pCopyDataStruct->dwData)
	{
	case MYDISPLAY:	

		MYREC* pData = (MYREC *)(pCopyDataStruct->lpData);
		
		SetDlgItemText(IDC_EDIT_FIRSTNAME, pData->s1);
		SetDlgItemText(IDC_EDIT_LASTNAME, pData->s2);
		
		char CStr[25];
		_itoa_s(pData->n, CStr, 10);
		size_t len = strlen(CStr) + 1;
		size_t converted = 0;
		wchar_t *WStr;
		WStr = (wchar_t*)malloc(len*sizeof(wchar_t));

		mbstowcs_s(&converted, WStr, len, CStr, _TRUNCATE);

		SetDlgItemText(IDC_EDIT_AGE, WStr);
	}



	return CDialogEx::OnCopyData(pWnd, pCopyDataStruct);
}


The Result as below:



内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项误差源分析,旨在帮助工程师更好地理解应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收泄漏电流等因素对测量准确性的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值