我有一个动态链接库,里面用sendmessage发送个结构体给VC6.0 win32应用程序,我在消息循环那里可以获得系统消息WM_COPYDATA,但是不知道怎么取得sendmessage发送的结构体。大侠们帮我下吧,我是新手!
解决方案 »
- VC中用到ODBC数据库出现FROM子句语法错误?????
- 边缘检测之后断边、伪边的处理问题
- SendMessage的用法,大家帮看下
- ADO连数据库的链接字段里数据库实例的链接字段是什么?
- VC下的数据库开发问题---如何把数学符号存入数据库
- Socket编程问题
- 在窗体上动态创建ListCtrl控件,改变窗体大小时ListCtrl闪烁的厉害,怎么解决?????
- 如何用VC处理CorelDraw,AutoCAD的图形?有现成的类库吗?
- 菜鸟求救:鼠标位置捕获问题。
- 如何响应CListCtrl控件的改变列宽的消息?我重载过几个函数,但都没有反应!
- 编辑框的内容叠加
- 昨天三点睡的,早上7点起来看nba,有这样的精神进来
struct COPYDATASTRUCT {
DWORD dwData; // whatever you want
DWORD cbData; // length of data
PVOID lpData; // ptr to data
};
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
const char* lpText = (const char*)pcds->lpData;
DWORD len = pcds->cbData;
//m_file.Write(lpText, len);
HWND hWnd, // handle to destination window
UINT Msg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
你将struct作为wParam或lParam传过去,在那边直接Msg.wParam或Msg.lParam就可以取到了啊
To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) WM_COPYDATA, // message ID (WPARAM) wParam, // = (WPARAM) () wParam; (LPARAM) lParam // = (LPARAM) () lParam; );
ParameterswParam
Handle to the window passing the data.
lParam
Pointer to a COPYDATASTRUCT structure that contains the data to be passed.
Return ValueIf the receiving application processes this message, it should return TRUE; otherwise, it should return FALSE.
ResThe data being passed must not contain pointers or other references to objects not accessible to the application receiving the data. While this message is being sent, the referenced data must not be changed by another thread of the sending process. The receiving application should consider the data read-only. The lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
const char* lpText = (const char*)pcds->lpData;
DWORD len = pcds->cbData;
//m_file.Write(lpText, len);
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
typedef int(* lpsFun)(DWORD,HWND);
HINSTANCE hdll;
lpsFun InstallHOOK;
hdll = LoadLibrary("Hdll.dll");
if(hdll != NULL)
{
InstallHOOK = (lpsFun)GetProcAddress(hdll,"InstallHOOK");
if(InstallHOOK !=NULL)
{
InstallHOOK(3723,hWnd);
}
}
FreeLibrary(hdll);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COPYDATA:(在这里可以收到WM_COPYDATA,但是我动态链接库里发过来的结构体,我就不知道怎么接收了)
~~~~~~~~
break;
2>.dll中如何把结构放在这里?const YourStr* lpYourStr = (const YourStr*)pcds->lpData;
3>.长度应该等于sizeof(YourStr),DWORD len = pcds->cbData;
“你将struct作为wParam或lParam传过去,在那边直接Msg.wParam或Msg.lParam就可以取到了啊”
PCOPYDATASTRUCT data;
data=(PCOPYDATASTRUCT)lParam;
if (data->dwData==TYPE_RegCreateKeyExA)
{
MessageBox(NULL,"dwdata成功!","ccc",MB_OK);
}
PARAMS* params = (PARAMS*)data->lpData;(这一句存在错误,error C2361: initialization of 'params' is skipped by 'default' label)
PARAMS* params
定义的地方不对。2个办法:
1>把定义移到switch前。
2>把case用{}括起来。