您的位置:程序门 -> vc/mfc -> 进程/线程/dll



exe与dll的参数传递?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


exe与dll的参数传递?[已结贴,结贴人:clxye]
发表于:2007-06-04 09:04:56 楼主
我用dll导出一个类:

carrayserial.h

#ifdef   dll_file
class   _declspec(dllexport)   carrayserial     //导出类carrayserial
#else
class   _declspec(dllimport)   carrayserial     //导入类carrayserial
#endif
{
public:
bool   initializedevice(   cwnd*   pportowner,   uint   portnr   =   1,   uint   baud   =   9600,   char   parity   =   'n ',   uint   databits   =   8,   uint   stopsbits   =   2   );
}


cserialarray.cpp
bool   carrayserial::initializedevice(   cwnd*   pportowner, //   the   owner   (cwnd)   of   the   port   (receives   message)
  uint   portnr, //   portnumber   (1..4)
  uint   baud, //   baudrate
  char   parity, //   parity  
  uint   databits, //   databits  
  uint   stopsbits //   stopbits  
  )
{
hwnd   htest   =   *pportowner;
cstring   strtemp;
strtemp.format(   "%d ",   htest   );
afxmessagebox(   strtemp   );

return   true;
}

exe文件中引用:

void   cserialmfcdemodlg::onconnect()  
{
//   todo:   add   your   control   notification   handler   code   here
hwnd   htest   =   *this;
cstring   strtemp2;
strtemp2.format(   "%d ",   htest   );
afxmessagebox(   strtemp2   );

m_serialdevice.initializedevice(   this,   m_unport,   m_unbaudrate,   *(   m_sparity.c_str()   ),   m_undatabit   );
}

结果dll中弹出的窗口指针和exe弹出的窗口指针值不一样,不知是什么原因,改如何解决,谢谢!!
发表于:2007-06-04 09:50:281楼 得分:0
hwnd   htest   =   *pportowner;


???
发表于:2007-06-04 10:20:252楼 得分:0
虽然用的不按套路,我主要是想看看这两个指针是否相等,真正用的时候是不会这样用的。
当然,感谢你的关注,谢谢!!
发表于:2007-06-04 16:57:243楼 得分:20
搞定了,原来指针是一样的,但是指针所指向的m_hwnd是不一样的。至于具体原因我不清楚。
解决方法:在传递cwnd*时,再加一个参数把m_hwnd也直接穿过来,而不是在dll中调用cwnd-> m_hwnd。

收分   ^_^


快速检索

最新资讯
热门点击