#pragma once
#include "enums.h"
class CMessages
{
public:
static DWORD sm_dwNotificationMessage;
static HWND sm_hWndNotification;
static void PostMessage(NOTIFICATION_
};
//enum.h
enum NOTIFICATION_MESSAGES
{
DISCOVERY_COMPLETE=0x100,
PAIRING_COMPLETE,
PAIRING_ERROR,
DISCOVERY_ERROR,
SERVICE_DISCOVERY_COMPLETE,
SERVICE_DISCOVERY_ERROR,
};
2. Message.cpp
#include "StdAfx.h"
#include "Messages.h"
DWORD CMessages::sm_
HWND CMessages::sm_
void CMessages::PostMessage(
{
::PostMessage(CMessages::sm_
}
3. Usage:
CMessages::PostMessage(
Exported functions:
MYLIB_API unsigned WINAPI GetNotificationMessage();
MYLIB_API void WINAPI SetNotificationWindow(HWND hWndNotify) ;
CMessages m_CMessages;
HWND GetNotificationWnd() {return m_CMessages.sm_
DWORD GetNotificationMessage() {return m_CMessages.sm_
void SetNotificationWindow(HWND hWndNotify) {m_CMessages.sm_
4. In exe, using C#
#region MessageFunctions
//> ------------------------------
//> Class: NotificationWindow
//> Purpose: target window for bluetooth device events
//> ------------------------------
public class NotificationWindow : MessageWindow
{
// Create an instance of the form.
private Form1 m_FormConnWizard;
// Save a reference to the form so it can
// be notified when messages are received.
public NotificationWindow(Form1 formConnWizard)
{
this.m_FormConnWizard = formConnWizard;
}
// handle window messages from the bluetooth dll
protected override void WndProc(ref Message msg)
{
if (msg.Msg == m_FormConnWizard.
{
// call back to the form to handle this message
m_FormConnWizard.
}
else{}
// Call the base WndProc method
// to process any messages not handled.
base.WndProc(ref msg);
}
}
private int GetMyNotificationMessage()
{
return (int)GetNotificationMessage();
}
private void NotificationMessage(Message msg)
{
switch ((uint)msg.WParam)
{
case (uint)NOTIFICATION_MESSAGES.
{
KillSearchingTimer();
MessageBox.Show("DISCOVERY COMPLETE!");
break;
}
case (uint)NOTIFICATION_MESSAGES.
{
//dx: revise the message
MessageBox.Show("...");
break;
}
case (uint)NOTIFICATION_MESSAGES.
{
break;
}
case (uint)NOTIFICATION_MESSAGES.
{
//MessageBox.Show(Properties.
break;
}
}
}
#endregion
public partial class Form1 : Form
{
NotificationWindow m_NotificationWindow;
public Form1()
{
m_NotificationWindow = new NotificationWindow(this);
SetNotificationWindow(m_
InitializeComponent();
}
..
}
[DllImport("xxx.dll", EntryPoint = "SetNotificationWindow", SetLastError = true)]
private extern static void SetNotificationWindow(IntPtr hWndNotify);
[DllImport("xxx.dll", EntryPoint = "GetNotificationMessage", SetLastError = true)]
private extern static uint GetNotificationMessage();
No comments:
Post a Comment