C#接受C++dll的方法发送的消息
C++代码
SendMessage(picture_Handle, 1024 + 1, 0, 0);//picture_Handle是窗口的句柄。
C#代码
public MainWindow()
{
this.SourceInitialized += new EventHandler(win_SourceInitialized);
InitializeComponent();
}
//声明拦截挂钩函数
private void win_SourceInitialized(object sender, EventArgs e)
{
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
if (hwndSource != null)
{
hwndSource.AddHook(new HwndSourceHook(this.WndProc));
}
}
//消息处理函数
unsafe private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
int i = 0;
if (1024 + 0 == msg)
{
i = 0;
Camera.GetCameraData(out pcamdata1, out sFrInfo[i], out CamPixFormat[i], i);
Camera.ShowCameraData(1280, 1024, ref pcamdata1, sFrInfo[i], this.PictureBox1.Handle, i);
//mDrawImage(camdata[i], CamPixFormat[i], i);
//this->PaintBox1->Canvas->Draw(0, 0, m_bmp[i]);
}
.....
其它代码
}
当我使用bcb时,可以接收到dll方法发送的消息。用C#代码不行,调试的时候发现msg的信息不是1024,而是其他数值,一直在变化。
请大神解惑。