做一个MFC常规dll,使用了serial类,其中有个函数是初始化串口的,为
BOOL CSerialPort::InitPort(CWnd* pPortOwner, // the owner (CWnd) of the port (receives message)   UINT  portnr,UINT  baud,char  parity,UINT  databits,UINT  stopbits,DWORD dwCommEvents,UINT  writebuffersize)
在应用程序中可以这样使用m_Port.InitPort(this,1,19200,'E',8,1,m_dwCommEvents,512);
但是在MFC常规dll中的函数如
__declspec(dllexport) void Init(void)
{
theApp.m_Port.InitPort(this,1,19200,'E',8,1);
theApp.m_Port.StartMonitoring();
}
就不能使用,会说全局函数Init不能使用this指针,那我应该怎样使用呢?谢谢各位!

解决方案 »

  1.   

    __declspec(dllexport) void Init(void)
    {
    theApp.m_Port.InitPort(this,1,19200,'E',8,1);
    theApp.m_Port.StartMonitoring();
    }theApp ???
    It's existing as MFC regular DLL, thus you may need to use the method AfxGetApp()->m_Port.InitPort(...)
      

  2.   

    您好,感谢您回复给我的关于dll中使用serial类的问题,可能因为我基础太差,所以还是不太明白,不知您是否可以去看看我发的另外一个帖子,这个帖子已经将源程序贴出来了,希望您帮我看看有什么问题,不胜感激
    地址为http://community.csdn.net/Expert/topic/5024/5024472.xml?temp=.4544489
      

  3.   

    要写个函数,把主程序的窗口句柄传到dll中。