CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

关于enumwindowpro 和 stl 高手帮我看看 为什么出现访问非法地址错误???

楼主whereisthedog()2004-11-01 13:49:28 在 VC/MFC / 基础类 提问

//   MainDlg.h   :   interface   of   the   CMainDlg   class  
  //  
  /////////////////////////////////////////////////////////////////////////////  
   
  #pragma   once  
  #include   "list"  
  #include   "string"  
  using   namespace   std;  
  typedef   struct    
  {  
  HWND   hWnd;  
  string   cWinBuf;  
  string   cname;  
   
  }WINLIST;  
  typedef     list<WINLIST>   wndlist;  
  static   wndlist   gWinList,childlist;  
  static   BOOL     CALLBACK   EnumWindowsProc(   HWND   hWnd,   LPARAM   lParam   )  
  {  
  WINLIST   temp;  
  temp.hWnd=hWnd;  
   
  ::GetWindowText(hWnd,   (LPSTR)temp.cWinBuf.data(),   256);  
  ::GetClassName(hWnd,   (LPSTR)temp.cname.data()   ,256);  
  string::size_type   pos=0;  
  pos=temp.cname.find("ThunderRT6FormDC",temp.cname.length());  
  if(pos!=-1)  
  {  
  gWinList.push_back(temp);  
  }  
  return   TRUE;  
  }  
  static     BOOL   CALLBACK   EnumChildProc(HWND   hwnd,LPARAM   lParam)  
  {  
  WINLIST   temp;  
  temp.hWnd=hwnd;  
  ::GetWindowText(hwnd,   (LPSTR)temp.cWinBuf.data(),   256);  
  ::GetClassName(hwnd,   (LPSTR)temp.cname.data()   ,256);  
  if(temp.cWinBuf.find("打印结果")!=NULL)  
  {  
  childlist.push_back(temp);  
  }  
   
  return   TRUE;  
  }  
  class   CMainDlg   :   public   CDialogImpl<CMainDlg>,   public   CUpdateUI<CMainDlg>,  
  public   CMessageFilter,   public   CIdleHandler  
  {  
   
   
  public:  
   
   
   
   
     
  void   getwnd()  
  {  
  ::ATLTRACE("getwnd   begin");  
  ::EnumWindows((WNDENUMPROC   )EnumWindowsProc,0);  
  ::ATLTRACE("getwnd   end;");  
  /*list<WINLIST>::iterator   it=gWinList.begin();  
  this->MessageBox("getwnd     begin");  
  for(;it!=gWinList.end();it++)  
  {  
  if(!it->cname.compare("ThunderRT6FormDC"))  
  gWinList.erase(it);  
  }  
  this->MessageBox("getwnd     ok");*/  
  }  
          HWND   getchildwnd()  
  {  
  list<WINLIST>::iterator   it=gWinList.begin();  
  for(;it!=gWinList.end();it++)  
  {  
  ::EnumChildWindows(it->hWnd,(WNDENUMPROC)EnumChildProc,0);  
  }  
  ; for(it=childlist.begin();it!=childlist.end();it++)  
  {  
  if(it->cWinBuf.compare("打印结果"))  
  return   it->hWnd;  
  }  
  return   NULL;  
  }  
  enum   {   IDD   =   IDD_MAINDLG   };  
   
  virtual   BOOL   PreTranslateMessage(MSG*   pMsg)  
  {    
  return   IsDialogMessage(pMsg);  
  }  
   
  virtual   BOOL   OnIdle()  
  {  
  return   FALSE;  
  }  
   
  BEGIN_UPDATE_UI_MAP(CMainDlg)  
  END_UPDATE_UI_MAP()  
   
  BEGIN_MSG_MAP(CMainDlg)  
  MESSAGE_HANDLER(WM_INITDIALOG,   OnInitDialog)  
  COMMAND_ID_HANDLER(ID_APP_ABOUT,   OnAppAbout)  
  COMMAND_ID_HANDLER(IDOK,   OnOK)  
  COMMAND_ID_HANDLER(IDCANCEL,   OnCancel)  
  COMMAND_HANDLER(IDC_BUTTON1,   BN_CLICKED,   OnBnClickedButton1)  
  END_MSG_MAP()  
   
  //   Handler   prototypes   (uncomment   arguments   if   needed):  
  // LRESULT   MessageHandler(UINT   /*uMsg*/,   WPARAM   /*wParam*/,   LPARAM   /*lParam*/,   BOOL&   /*bHandled*/)  
  // LRESULT   CommandHandler(WORD   /*wNotifyCode*/,   WORD   /*wID*/,   HWND   /*hWndCtl*/,   BOOL&   /*bHandled*/)  
  // LRESULT   NotifyHandler(int   /*idCtrl*/,   LPNMHDR   /*pnmh*/,   BOOL&   /*bHandled*/)  
   
  LRESULT   OnInitDialog(UINT   /*uMsg*/,   WPARAM   /*wParam*/,   LPARAM   /*lParam*/,   BOOL&   /*bHandled*/)  
  {  
  //   center   the   dialog   on   the   screen  
  CenterWindow();  
   
  //   set   icons  
  HICON   hIcon   =   (HICON)::LoadImage(_Module.GetResourceInstance(),   MAKEINTRESOURCE(IDR_MAINFRAME),    
  IMAGE_ICON,   ::GetSystemMetrics(SM_CXICON),   ::GetSystemMetrics(SM_CYICON),   LR_DEFAULTCOLOR);  
  SetIcon(hIcon,   TRUE);  
  HICON   hIconSmall   =   (HICON)::LoadImage(_Module.GetResourceInstance(),   MAKEINTRESOURCE(IDR_MAINFRAME),    
  IMAGE_ICON,   ::GetSystemMetrics(SM_CXSMICON),   ::GetSystemMetrics(SM_CYSMICON),   LR_DEFAULTCOLOR);  
  SetIcon(hIconSmall,   FALSE);  
   
  //   register   object   for   message   filtering   and   idle   updates  
  CMessageLoop*   pLoop   =   _Module.GetMessageLoop();  
  ATLASSERT(pLoop   !=   NULL);  
  pLoop->AddMessageFilter(this);  
  pLoop->AddIdleHandler(this);  
   
  UIAddChildWindowContainer(m_hWnd);  
   
  return   TRUE;  
  }  
   
  LRESULT   OnAppAbout(WORD   /*wNotifyCode*/,   WORD   /*wID*/,   HWND   /*hWndCtl*/,   BOOL&   /*bHandled*/)  
  {  
  CAboutDlg   dlg;  
  dlg.DoModal();  
  return   0;  
  }  
   
  LRESULT   OnOK(WORD   /*wNotifyCode*/,   WORD   wID,   HWND   /*hWndCtl*/,   BOOL&   /*bHandled*/)  
  {  
  //   TODO:   Add   validation   code    
  CloseDialog(wID);  
  return   0;  
  }  
   
  LRESULT   OnCancel(WORD   /*wNotifyCode*/,   WORD   wID,   HWND   /*hWndCtl*/,   BOOL&   /*bHandled*/)  
  {  
  CloseDialog(wID);  
  return   0;  
  }  
   
  void   CloseDialog(int   nVal)  
  {  
  DestroyWindow();  
  ::PostQuitMessage(nVal);  
  }  
  LRESULT   OnBnClickedButton1(WORD   /*wNotifyCode*/,   WORD   /*wID*/,   HWND   /*hWndCtl*/,   BOOL&   /*bHandled*/)  
  {  
  HWND   wnd;  
  string   a;  
  getwnd();  
  wnd=this->getchildwnd();  
  ::sprintf((LPSTR)a.data(),"%d",wnd);  
  this->MessageBox((LPCTSTR)a.data());  
   
  return   0;  
  }  
  private:  
   
   
  };  
  问题点数:100、回复次数:7Top

1 楼roger_ding(海天一色)回复于 2004-11-01 13:53:57 得分 0

非法错误的时候利用stack   list,先查下在哪里出错Top

2 楼wwwsq(wwwsq)回复于 2004-11-01 14:00:10 得分 0

访问的时候对象还在吗?Top

3 楼whereisthedog()回复于 2004-11-01 14:03:31 得分 0

> getwindowaaa.exe!operator   delete(void   *   pUserData=0x6f747541)     行52   +   0x3 C++  
    getwindowaaa.exe!std::allocator<char>::deallocate(char   *   _Ptr=0x6f747541,   unsigned   int   __formal=111)     行132   +   0x9 C++  
    getwindowaaa.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char>   >::_Tidy(bool   _Built=true,   unsigned   int   _Newsize=0)     行1519 C++  
    getwindowaaa.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char>   >::~basic_string<char,std::char_traits<char>,std::allocator<char>   >()     行458 C++  
    getwindowaaa.exe!WINLIST::~WINLIST()     +   0x4a C++  
    getwindowaaa.exe!EnumWindowsProc(HWND__   *   hWnd=0x000104bc,   long   lParam=0)     行31   +   0x19 C++  
    user32.dll!77cd55b5()    
    user32.dll!77cd5614()    
    getwindowaaa.exe!CMainDlg::getwnd()     行60   +   0xf C++  
    getwindowaaa.exe!CMainDlg::OnBnClickedButton1(unsigned   short   __formal=0,   unsigned   short   __formal=0,   unsigned   short   __formal=0,   unsigned   short   __formal=0)     行167 C++  
    getwindowaaa.exe!CMainDlg::ProcessWindowMessage(HWND__   *   hWnd=0x00050344,   unsigned   int   uMsg=273,   unsigned   int   wParam=1000,   long   lParam=328530,   long   &   lResult=-858993460,   unsigned   long   dwMsgMapID=0)     行105   +   0x51 C++  
    getwindowaaa.exe!ATL::CDialogImplBaseT<ATL::CWindow>::DialogProc(HWND__   *   hWnd=0x0012fd00,   unsigned   int   uMsg=273,   unsigned   int   wParam=1000,   long   lParam=328530)     行3295   +   0x25 C++  
    user32.dll!77cd15df()    
    user32.dll!77cdbf98()    
    user32.dll!77cdbf4e()    
    user32.dll!77d05142()    
    user32.dll!77cdbe0e()    
    user32.dll!77cd2cea()    
    ntdll.dll!77f33868()    
    user32.dll!77cdbd91()    
    user32.dll!77cd2c62()    
    user32.dll!77cd5fc1()    
    user32.dll!77cd3374()    
    comctl32.dll!70af5436()    
    comctl32.dll!70af550f()    
    comctl32.dll!70af7784()    
    CnsMin.dll!3721a7cf()    
    CnsMin.dll!3721ab38()    
    user32.dll!77cd4868()    
    user32.dll!77cd15df()    
    user32.dll!77cd1a15()    
    user32.dll!77cd19cb()    
    user32.dll!77d05142()    
    user32.dll!77cd16d8()    
    user32.dll!77cd6b2c()    
    user32.dll!77cd40eb()    
    user32.dll!77d05142()    
    user32.dll!77cd1744()    
    user32.dll!77cd4088()    
    user32.dll!77cd6ee4()    
    getwindowaaa.exe!ATL::CWindow::IsDialogMessageA(tagMSG   *   lpMsg=0x0012fd68)     行1611   +   0x12 C++  
    getwindowaaa.exe!CMainDlg::PreTranslateMessage(tagMSG   *   pMsg=0x0012fd68)     行90 C++  
    getwindowaaa.exe!WTL::CMessageLoop::PreTranslateMessage(tagMSG   *   pMsg=0x0012fd68)     行330   +   0x16 C++  
    getwindowaaa.exe!WTL::CMessageLoop::Run()     行291   +   0x13 C++  
    getwindowaaa.exe!Run(char   *   __formal=0x00151f08,   int   nCmdShow=1)     行32   +   0x8 C++  
    getwindowaaa.exe!WinMain(HINSTANCE__   *   hInstance=0x00400000,   HINSTANCE__   *   __formal=0x00000000,   char   *   lpstrCmdLine=0x00151f08,   int   nCmdShow=1)     行54   +   0xd C++  
    getwindowaaa.exe!WinMainCRTStartup()     行251   +   0x30 C  
    kernel32.dll!77e1f38c()    
  Top

4 楼whereisthedog()回复于 2004-11-01 14:06:51 得分 0

对象还在阿    
  Top

5 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2004-11-01 15:18:14 得分 100

为WINLIST写上operator=和copy   constructor即可解决问题。Top

6 楼huaguli(学VC不要命)回复于 2004-11-01 16:58:48 得分 0

为WINLIST写上operator=和copy   constructorTop

7 楼whereisthedog()回复于 2004-11-01 20:59:58 得分 0

主要是   string成员的问题  
  WINLIST   &operator=(const   WINLIST&   a)  
  {  
        WINLIST   *   temp=new   WINLIST(a)  
      //   这里应该怎么写啊  
   
  }  
  WINLIST(const&   WINLIST   a)  
  {    
        hWnd=a.hWnd;  
        cWinBuff=a.WinBuff;  
        cname=a.cname;  
  }  
  写了也是不行啊  
  正确的写法谁能告诉以下阿  
  我现在知道了问题主要是string类的指针成员的问题  
  可是不知怎么解决Top

相关问题

  • 多线程访问类中出现的非法访问
  • 地址非法访问错误一般是什么原因?
  • sqlplus经常出现非法访问,大虾救命!
  • 多线程访问Ole对象出现非法
  • windows如何知道我访问的是非法地址呢?
  • 怎么防止非法内存的访问?
  • 使用 WaitForMultipleObjects 时发生非法地址访问
  • 关闭程序时程序非法访问
  • char str[]="I love abc";printf("%s\n",str[1]);提示非法访问
  • 关于STL中Map访问的问题?

关键词

  • c++
  • basic
  • winlist
  • getwindowaaa
  • gwinlist
  • getwnd
  • cwinbuf
  • hwnd
  • cmaindlg
  • cname

得分解答快速导航

  • 帖主:whereisthedog
  • DentistryDoctor

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo