我想将截获的消息再传递给调用程序,在DLL中设置了一个结构体作为共享数据段。
在DLL中如下定义:
#pragma data_seg("mydata")
struct ShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
struct ShareData sendMsg;
#pragma data_seg() extern "C" {ShareData sendMsg;}在DEF中如下声明:
EXPORTS
; Explicit exports can go here
ShareData CONSTANT
SECTIONS
mydata READ WRITE SHARED 编译出错:
error C2146: syntax error : missing ';' before identifier 'sendMsg'
error C2501: 'ShareData' : missing storage-class or type specifiers
error C2371: 'ShareData' : redefinition; different basic types
D:\MouseHook\MouseHook.cpp(27) : see declaration of 'ShareData'
fatal error C1004: unexpected end of file found Error executing cl.exe.是什么问题???
或者有什么更好的办法可以传递这些消息。谢谢!!
在DLL中如下定义:
#pragma data_seg("mydata")
struct ShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
struct ShareData sendMsg;
#pragma data_seg() extern "C" {ShareData sendMsg;}在DEF中如下声明:
EXPORTS
; Explicit exports can go here
ShareData CONSTANT
SECTIONS
mydata READ WRITE SHARED 编译出错:
error C2146: syntax error : missing ';' before identifier 'sendMsg'
error C2501: 'ShareData' : missing storage-class or type specifiers
error C2371: 'ShareData' : redefinition; different basic types
D:\MouseHook\MouseHook.cpp(27) : see declaration of 'ShareData'
fatal error C1004: unexpected end of file found Error executing cl.exe.是什么问题???
或者有什么更好的办法可以传递这些消息。谢谢!!
解决方案 »
- 对话框创建后看不见
- 在使用WSAAsyncSelect基于消息的异步I/O模型时遇到以下几个问题
- 变量前面怎么会没有类型呀?
- 为什么生成的BMP文件是一片全黑?
- 各位好,关于数据库及网络传输
- string to char[]
- 如何设置工作区的ResourceView
- 一个关于DeviceIoControl的函数
- 我已经完成了一个SDI工程,突然通知要把它改成DLL,请问改怎么办?从哪入口进行调用?
- 著名的vchelp.net的主页上的“中国共享软件”链接竟然是淫秽站点!
- ********疑难求解:写调度程序********最近的项目中需要写一个调度程序,碰到不少问题,做过类似工作或知道的朋友请指导下,多谢!******
- 删除CList链表元素出错,请帮忙
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
=>
typedef struct _tagShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
=>
shareData sendMsg;
error C2086: 'sendMsg' : redefinition
指向:
extern "C" {ShareData sendMsg;}
main()
{
int a;
int a; // C2086
}
// The following example is an error in C++, but not in ANSI C:// C2086b.cpp
int a;
int a; // C2086
main()
{
}
这里是定义函数还是什么?
在应用程序(进程)按外部变量引用共享数据。
我把这句换到调用程序中就OK了。
只是extern "C"应该是C++的为C程序提供连接转换符,为什么这里要用到它???--------------------------
另外:
进程中使用该变量应注意间接引用。
m_pStatic=(CEdit*)GetDlgItem(IDC_SHARED);
m_pStatic->GetLine(0,*MySharedData,80);
另外:
进程中使用该变量应注意间接引用。
m_pStatic=(CEdit*)GetDlgItem(IDC_SHARED);
m_pStatic->GetLine(0,*MySharedData,80);
-------------------------
这句是什么意思?
我不能直接使用如下使用吗?为什么??应该怎样写。
int nCode = sendMsg.g_nCode;
SendMessage( m_hWnd, AS_SENDMSG, 0, 0);
但是调用程序好像没收到,没有反映!!不知何故??调用程序中如下设置消息响应:
ON_MESSAGE(AS_SENDMSG,OnSendMsg)
afx_msg void OnSendMsg();
void CASClientDlg::OnSendMsg()
{
int nCode = sendMsg.g_nCode;
MessageBox("OK","远程控制",MB_OK);
}
1、如何在调用程序中使用DLL中的共享数据;
2、在DLL中给调用程序发送了一条消息,
SendMessage( m_hWnd, AS_SENDMSG, 0, 0);
但是调用程序好像没收到,没有反映!!
谢谢!!
我就是想用共享内存,并且我也这样在DLL中设置了一块共享内存。
现在我不知道怎样去使用它。因为我查资料说不能直接引用。
--------------------
进程中使用该变量应注意间接引用。
m_pStatic=(CEdit*)GetDlgItem(IDC_SHARED);
m_pStatic->GetLine(0,*MySharedData,80);
--------------------
除了消息传递,其他的方法我都没用过,
内存映射也看到,只是觉得内存共享似乎更简单。用什么都可以。
我在调用程序中直接引用了共享内存的值,但是好像都是空值。大概是值没有传过来。
调用程序中:
//与DLL的共享数据段
typedef struct ShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
extern "C" {ShareData sendMsg;}LRESULT CASClientDlg::OnSendMsg()
{
int nCode = sendMsg.g_nCode;
......
}
跟踪发现它们的值都是0。
用WM_COPYDATA也很好
COPYDATASTRUCT cds;
char mem[1024];
cds.lpData=mem;
FindWindow();
SendMessage(hwnd,WM_COPYDATA,wParam,&cds);
nonstandard extension used : '_export' is an obsolete keyword, see documentation for __declspec(dllexport)这几个方法都知道,只是我觉得共享内存的方法最直接,不需要其他的一些辅助变量。
我现在的问题是:在共享内存的数据并没有被传递,不知道是否哪里缺少了什么东西??
DLL程序中:
.DEF中
EXPORTS
; Explicit exports can go here
sendMsg CONSTANT
.CPP中
#pragma data_seg("mydata")
typedef struct ShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
ShareData sendMsg;
#pragma data_seg() LRESULT WINAPI KeyboardProc(int nCode,WPARAM wparam,LPARAM lparam)
{
sendMsg.g_nCode = nCode;
sendMsg.g_lparam = lparam;
sendMsg.g_wparam = wparam;
if (nCode < 0)
{
return CallNextHookEx(glhHook,nCode,wparam,lparam);
}
if (nCode != HC_ACTION)
{
return CallNextHookEx(glhHook,nCode,wparam,lparam);
}
if (m_bOperator && !::FindWindow(0, "KeyBoard Locked"))
{
::MessageBox(0,buffer,"KeyBoard Locked",MB_OK);
} if (m_bOperator)
{
PostMessage( m_hWndMain, AS_SENDMSG, 0, 0);
return CallNextHookEx(glhHook, nCode, wparam, lparam );//继续传递消息
}
else
return 1;}//在调用程序中:
typedef struct ShareData
{
int g_nCode;
WPARAM g_wparam;
LPARAM g_lparam;
} ShareData;
extern "C" {ShareData sendMsg;}LRESULT CASClientDlg::OnSendMsg()
{
int nCode = sendMsg.g_nCode;
......
}
跟踪发现它们的值都是0。
LRESULT CASClientDlg::OnSendMsg()
{
int nCode = sendMsg.g_nCode;
if( !FindWindow(0, "SendMSG") )
MessageBox(buffer,"SendMSG",MB_OK);
return 0L;
}
感觉就只是在本程序中定义了sendMsg这么个变量,与DLL的共享内存就没关系。
{
int nCode = sendMsg.g_nCode;
_itoa( sendMsg.g_wparam, buffer, 10);
if( !FindWindow(0, "SendMSG") )
MessageBox(buffer,"SendMSG",MB_OK);
return 0L;
}
显示的值始终是0。
应该怎样使用?最好能把步骤说清楚,DLL中需要什么,调用程序中需要什么?
多谢!
我也先试试!!
应该怎样使用?最好能把步骤说清楚,DLL中需要什么,调用程序中需要什么?
多谢!
我也先试试!!
LRESULT WINAPI KeyboardProc(int nCode,WPARAM wparam,LPARAM lparam)
{
if (m_bOperator)
{
//创建一个名为MySharedMem的长度为4096字节的有名映射文件:
HANDLE hMySharedMapFile = CreateFileMapping(((HANDLE)0xFFFFFFFF), NULL,PAGE_READWRITE,0,0x1000,"mydata"); pszMySharedMapView = (LPSTR)MapViewOfFile(hMySharedMapFile, FILE_MAP_READ|FILE_MAP_WRITE,0,0,0); PostMessage( m_hWndMain, AS_SENDMSG, 0, 0);
return CallNextHookEx(glhHook, nCode, wparam, lparam );//继续传递消息
}
else
return 1;}在调用程序中:
HANDLE hMySharedMapFile = OpenFileMapping(FILE_MAP_WRITE,FALSE,"mydata");
LPSTR pszMySharedMapView = (LPSTR)MapViewOfFile(hMySharedMapFile, FILE_MAP_READ|FILE_MAP_WRITE,0,0,0);
是这样就给它们建立了连接的通路,可以通过mydata这个文件视图传递数据??有什么问题吗?(我不知道怎样存数和取数,所以无法验证,只是编译通过)
那么,我接下来的问题是:
需要向mydata这个文件视图中添加数据并读取数据。
这个应该怎样做??
我没有这些资料。
ShareData *psd = (ShareData*) pszMySharedMapView;
psd->g_nCode = 1;
psd->g_wparam = 2;
psd->g_lparam = 3;将这个地址(也就是ShareData的地址)传给接收数据的一方,在这里就是pszMySharedMapView读取的时候
ShareData *psd = (ShareData*)pszMySharedMapView
int code = psd->g_ncode;
http://community.csdn.net/Expert/topic/3906/3906269.xml?temp=.3167383