Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ATL collection and event firing

ATL collection and event firing

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Farry
    wrote on last edited by
    #1

    I've got an ATL component that is used to get a Directory listing async for VB clients. I have 3 interfaces in my Component. IListing IDirectory IFileObject I listing exposes a method of ExecuteImmediate, and Execute(it creates a thread to do the work). It then uses the FindFirstFile/FindFirstFile etc to actually do the work. In this area of the component, I create a CComObject and store that in the member variable for my component. Then the hard work is done, and each CComObject as added to the CDirectory object. All this works perfectly. No leaks, etc. I then call a property (Contents) to return the IDirectory which is my enumeration of the objects. Also fine. If I add to the bottom of the ExecuteImmediate/Execute and Event to Fire_Complete(). The system crashes. I've gone through with the debugger, and I can't find anything. I would really appreciate it if someone could identify any problems with this code(or if I should include some more). DWORD WINAPI SearchFilesFunction2( LPVOID lpParam ) { SearchFunction(lpParam); ExitThread(0); return 0; // thread completed } void SearchFunction( LPVOID lpParam ) { USES_CONVERSION; CListing2* pListing; CComBSTR path; LPTSTR lpsz; BSTR directoryPath; BSTR directoryMask; bool Finished; WIN32_FIND_DATA FileFindData; HANDLE hSearch; pListing = (CListing2*)lpParam; pListing->m_inProgress = TRUE; lpsz = new TCHAR[512]; pListing->get_Directory(&directoryPath); pListing->get_Mask(&directoryMask); path = directoryPath; path += directoryMask; hSearch = FindFirstFile(OLE2CT(path), &FileFindData); Finished = FALSE; if (hSearch == INVALID_HANDLE_VALUE) { Finished= TRUE; } pListing->pDirectory = new CComObject; while (!Finished) { CComBSTR fullpath; BSTR bstr_Filename; CFileObject * pFileObject; pFileObject = new CComObject; _tcscpy( lpsz, FileFindData.cFileName ); bstr_Filename = SysAllocString(lpsz); fullpath = directoryPath; fullpath += bstr_Filename; pFileObject->put_Name(bstr_Filename); pFileObject->put_Path(directoryPath); if (FileFindData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY)) { pFileObject->put_Type(1); fullpath += "\\"; } else { pFileObject->put_Type(0); } pFileObject->put_Fullpath(fullpath); SysFreeString(bstr_Filename); pListing->pDirectory->Add(pFileObject); if (!FindNextFile(hSearch,

    J 1 Reply Last reply
    0
    • P Paul Farry

      I've got an ATL component that is used to get a Directory listing async for VB clients. I have 3 interfaces in my Component. IListing IDirectory IFileObject I listing exposes a method of ExecuteImmediate, and Execute(it creates a thread to do the work). It then uses the FindFirstFile/FindFirstFile etc to actually do the work. In this area of the component, I create a CComObject and store that in the member variable for my component. Then the hard work is done, and each CComObject as added to the CDirectory object. All this works perfectly. No leaks, etc. I then call a property (Contents) to return the IDirectory which is my enumeration of the objects. Also fine. If I add to the bottom of the ExecuteImmediate/Execute and Event to Fire_Complete(). The system crashes. I've gone through with the debugger, and I can't find anything. I would really appreciate it if someone could identify any problems with this code(or if I should include some more). DWORD WINAPI SearchFilesFunction2( LPVOID lpParam ) { SearchFunction(lpParam); ExitThread(0); return 0; // thread completed } void SearchFunction( LPVOID lpParam ) { USES_CONVERSION; CListing2* pListing; CComBSTR path; LPTSTR lpsz; BSTR directoryPath; BSTR directoryMask; bool Finished; WIN32_FIND_DATA FileFindData; HANDLE hSearch; pListing = (CListing2*)lpParam; pListing->m_inProgress = TRUE; lpsz = new TCHAR[512]; pListing->get_Directory(&directoryPath); pListing->get_Mask(&directoryMask); path = directoryPath; path += directoryMask; hSearch = FindFirstFile(OLE2CT(path), &FileFindData); Finished = FALSE; if (hSearch == INVALID_HANDLE_VALUE) { Finished= TRUE; } pListing->pDirectory = new CComObject; while (!Finished) { CComBSTR fullpath; BSTR bstr_Filename; CFileObject * pFileObject; pFileObject = new CComObject; _tcscpy( lpsz, FileFindData.cFileName ); bstr_Filename = SysAllocString(lpsz); fullpath = directoryPath; fullpath += bstr_Filename; pFileObject->put_Name(bstr_Filename); pFileObject->put_Path(directoryPath); if (FileFindData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY)) { pFileObject->put_Type(1); fullpath += "\\"; } else { pFileObject->put_Type(0); } pFileObject->put_Fullpath(fullpath); SysFreeString(bstr_Filename); pListing->pDirectory->Add(pFileObject); if (!FindNextFile(hSearch,

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      Assuming you are not using free threaded apartments, you are in a canoe on a creek of manure, without paddles. You need to synchronize the apartments by marshalling the pListing interface pointer. Take a look at Len Holgates excellent article which touches this subject: COM Mailslots - Designing asynchonous COM components for VB[^]. -- They're out get me, I can't escape cos' they won't let me They won't forget me, they'll get me in their grip and sweat me They'll wait me out, and then move in under my skin They'll make me doubt, they're out to make me let them in

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups