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. COM
  4. Async WinInet Locks Program for Period of Time - need implementation advise!

Async WinInet Locks Program for Period of Time - need implementation advise!

Scheduled Pinned Locked Moved COM
helpquestionc++testingbeta-testing
10 Posts 3 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.
  • T Offline
    T Offline
    Tim Rymer
    wrote on last edited by
    #1

    Hey I've been working on an ATL Object that uses Asynchronous WinInet API's, which end up getting used up to about 20 at a time, but i'm only really testing at 2 right now, which has the same problem: The program that uses more than one of these objects at a time locks up when waiting for data from the callback function. It uses little or no processor power, but sits there and stays locked until it gets the data, then finally moves on. (the OS is fine and switching windows and hitting the Start buttons all work fine, so it's just the program) *NOTE: I noticed how MSDN did it (ARTICLE:Calling Win32 Internet Functions Asynchronously), and it seemed like a great idea to create the worker thread inside of the callback function, but for some reason I couldnt get my ATL object to work (i think it may have to do with not having experience first time around and not being smart and firing events from that callback thread) either way, it's not the way i'm doing it and i'm not changing it. unless you're "for sure" that it can work easily. HERE'S HOW I DID IT: 1. I fire events from the worker thread by using IGlobalInterfaceTable and cookies. (the App is in VB - no changing that either) 2. More importantly, in my worker thread, I call WaitForSingleObject() and I wait for the event that i had created and a bool member variable that is changed (because it seems like sometimes it will pick up the other ATL objects' SetEvent() calls so i just make sure that it is that object's Event that was set. Now in MSDN's version, you dont have to do call WaitForSingleObject() because it starts the thread when it has the Url's HINTERNET handle. Right now that's not a big deal at all, cuz when it's waiting to connect, i can move the program's window around and it hasnt locked up. OK HERE'S THE BAD PART: When I Call InternetReadFileEx() I check for ERROR_IO_PENDING of course, and when i get that, I call WaitForSingleObject() and wait for the INTERNET_STATUS_REQUEST_COMPLETE status. IT LOCKS UP THE PROGRAM NOW. This is all in the worker thread! What is the deal? No CPU Usage And Yet, NO CONTROL! And if that ever gets figured out, i have yet to find out how to properly kill the internet APIs and after that, do another address with the same object. And in the callback function, what is dwInternetStatus = 320, 321???? I havent found a thing on what that might actually be! it's not in MSDN, and i dont have a clue what it is, but it's actually a good value. but i sure dont know though. I

    J 1 Reply Last reply
    0
    • T Tim Rymer

      Hey I've been working on an ATL Object that uses Asynchronous WinInet API's, which end up getting used up to about 20 at a time, but i'm only really testing at 2 right now, which has the same problem: The program that uses more than one of these objects at a time locks up when waiting for data from the callback function. It uses little or no processor power, but sits there and stays locked until it gets the data, then finally moves on. (the OS is fine and switching windows and hitting the Start buttons all work fine, so it's just the program) *NOTE: I noticed how MSDN did it (ARTICLE:Calling Win32 Internet Functions Asynchronously), and it seemed like a great idea to create the worker thread inside of the callback function, but for some reason I couldnt get my ATL object to work (i think it may have to do with not having experience first time around and not being smart and firing events from that callback thread) either way, it's not the way i'm doing it and i'm not changing it. unless you're "for sure" that it can work easily. HERE'S HOW I DID IT: 1. I fire events from the worker thread by using IGlobalInterfaceTable and cookies. (the App is in VB - no changing that either) 2. More importantly, in my worker thread, I call WaitForSingleObject() and I wait for the event that i had created and a bool member variable that is changed (because it seems like sometimes it will pick up the other ATL objects' SetEvent() calls so i just make sure that it is that object's Event that was set. Now in MSDN's version, you dont have to do call WaitForSingleObject() because it starts the thread when it has the Url's HINTERNET handle. Right now that's not a big deal at all, cuz when it's waiting to connect, i can move the program's window around and it hasnt locked up. OK HERE'S THE BAD PART: When I Call InternetReadFileEx() I check for ERROR_IO_PENDING of course, and when i get that, I call WaitForSingleObject() and wait for the INTERNET_STATUS_REQUEST_COMPLETE status. IT LOCKS UP THE PROGRAM NOW. This is all in the worker thread! What is the deal? No CPU Usage And Yet, NO CONTROL! And if that ever gets figured out, i have yet to find out how to properly kill the internet APIs and after that, do another address with the same object. And in the callback function, what is dwInternetStatus = 320, 321???? I havent found a thing on what that might actually be! it's not in MSDN, and i dont have a clue what it is, but it's actually a good value. but i sure dont know though. I

      J Offline
      J Offline
      Joao Vaz
      wrote on last edited by
      #2

      Hum, you could try this link http://www.codeproject.com/useritems/asyncwininet.asp#xx84731xx Also you could check chapter 9 source code of the Essential Wininet book, a good book that i used to program wininet and com winnet applications, and the chapter 10 that deals with http wininet com components, this book was a life savier for me in the past :-D , Ah , and because your app is in VB and since Vb doesn't support multithreading, in this case i think they recommend 2 ways to solve this problem, and one, the best one(the one that i used )is to create a message pump in the main thread that catches the message of the worker thread and then dispatches the event in the callback :confused: that is on the main thread to the vb app, check for "events and atl and vb" in msdn for a more correct explanation. Hope this helps :confused: , Joao Vaz

      T 1 Reply Last reply
      0
      • J Joao Vaz

        Hum, you could try this link http://www.codeproject.com/useritems/asyncwininet.asp#xx84731xx Also you could check chapter 9 source code of the Essential Wininet book, a good book that i used to program wininet and com winnet applications, and the chapter 10 that deals with http wininet com components, this book was a life savier for me in the past :-D , Ah , and because your app is in VB and since Vb doesn't support multithreading, in this case i think they recommend 2 ways to solve this problem, and one, the best one(the one that i used )is to create a message pump in the main thread that catches the message of the worker thread and then dispatches the event in the callback :confused: that is on the main thread to the vb app, check for "events and atl and vb" in msdn for a more correct explanation. Hope this helps :confused: , Joao Vaz

        T Offline
        T Offline
        Tim Rymer
        wrote on last edited by
        #3

        Here's the thing with the message pump, I dont really know how to do that coming from an ATL object... do you see where i'm coming from? I've heard that a bunch but i've always stayed away from it because i didnt know how to make one (that's what i used IGlobalInterfaceTable which worked with Firing Events, but obviously is not working with WaitForSingleObject() now if you have an example.... then that might be a different story... for me i wouldnt know where to start. ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

        J 1 Reply Last reply
        0
        • T Tim Rymer

          Here's the thing with the message pump, I dont really know how to do that coming from an ATL object... do you see where i'm coming from? I've heard that a bunch but i've always stayed away from it because i didnt know how to make one (that's what i used IGlobalInterfaceTable which worked with Firing Events, but obviously is not working with WaitForSingleObject() now if you have an example.... then that might be a different story... for me i wouldnt know where to start. ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

          J Offline
          J Offline
          Joao Vaz
          wrote on last edited by
          #4

          Okay Tim , i founded it, check this http://www.mvps.org/vcfaq/com/1.htm, the kbs and references to code are at the bottom at the page. Hope this helps, Joao Vaz

          T 1 Reply Last reply
          0
          • J Joao Vaz

            Okay Tim , i founded it, check this http://www.mvps.org/vcfaq/com/1.htm, the kbs and references to code are at the bottom at the page. Hope this helps, Joao Vaz

            T Offline
            T Offline
            Tim Rymer
            wrote on last edited by
            #5

            Ok, I guess i'm just going to have a class that is derived from CWnd, do I HAVE to use CWnd? I've seen all those articles before, of course they dont make much sense when you havent actually done whatever they are saying to do, but I guess i'm just expecting to see an example of a normal CreateWindow function and then the message loop function that would fire the event after each PostMessage() not just a ctor to CWnd... but i'll try my best, thanks for the help, I just wish I had done this once before cause it always makes sense the 2nd time around... ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

            J 1 Reply Last reply
            0
            • T Tim Rymer

              Ok, I guess i'm just going to have a class that is derived from CWnd, do I HAVE to use CWnd? I've seen all those articles before, of course they dont make much sense when you havent actually done whatever they are saying to do, but I guess i'm just expecting to see an example of a normal CreateWindow function and then the message loop function that would fire the event after each PostMessage() not just a ctor to CWnd... but i'll try my best, thanks for the help, I just wish I had done this once before cause it always makes sense the 2nd time around... ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

              J Offline
              J Offline
              Joao Vaz
              wrote on last edited by
              #6

              Tim, i thought that your object is in ATL :confused: , if so you must add the public CWindowImpl to your inheritance chain, CWnd is for MFC controls, not ATL ! Do a step by step procedure of the kb: Q196026 http://support.microsoft.com/default.aspx?scid=kb;PT;q196026 Happy coding, and also don't forget to check Essential Wininet sourcecode for proper asynch behavoir. Regarsds, Joao Vaz

              T 2 Replies Last reply
              0
              • J Joao Vaz

                Tim, i thought that your object is in ATL :confused: , if so you must add the public CWindowImpl to your inheritance chain, CWnd is for MFC controls, not ATL ! Do a step by step procedure of the kb: Q196026 http://support.microsoft.com/default.aspx?scid=kb;PT;q196026 Happy coding, and also don't forget to check Essential Wininet sourcecode for proper asynch behavoir. Regarsds, Joao Vaz

                T Offline
                T Offline
                Tim Rymer
                wrote on last edited by
                #7

                I didnt know that... its tough trying to pick out the important parts, especially when you havent done it before. I'll put CWindowImpl in my obj and try to use it. Thanks! ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

                1 Reply Last reply
                0
                • J Joao Vaz

                  Tim, i thought that your object is in ATL :confused: , if so you must add the public CWindowImpl to your inheritance chain, CWnd is for MFC controls, not ATL ! Do a step by step procedure of the kb: Q196026 http://support.microsoft.com/default.aspx?scid=kb;PT;q196026 Happy coding, and also don't forget to check Essential Wininet sourcecode for proper asynch behavoir. Regarsds, Joao Vaz

                  T Offline
                  T Offline
                  Tim Rymer
                  wrote on last edited by
                  #8

                  1. When I throw CWinImpl, into the header, It gives me an error about already having CComControl in my thing as well. What should I do? Should I just make a variable of CWinImpl in my ATL Class? and if that works, how do I make it windowless? do i just not set a STYLE when I create the window? or do i just make a DialogBox and call ShowWindow(WS_HIDE) or something? I dont want anything showing up of course, nothing in the background, etc. Any Tips? ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

                  L J 2 Replies Last reply
                  0
                  • T Tim Rymer

                    1. When I throw CWinImpl, into the header, It gives me an error about already having CComControl in my thing as well. What should I do? Should I just make a variable of CWinImpl in my ATL Class? and if that works, how do I make it windowless? do i just not set a STYLE when I create the window? or do i just make a DialogBox and call ShowWindow(WS_HIDE) or something? I dont want anything showing up of course, nothing in the background, etc. Any Tips? ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    From the article :-) Steps to Reproduce Behavior The following example first creates an ATL project, then a Visual Basic 6.0 project. It then uses these to demonstrate the proper way to have a secondary thread request that the primary thread fire an event. Steps to Create an ATL Project with Visual C++ Create a new ATL COM AppWizard Project named MyAtlDll and keep the default settings. In the class view, right-click the project name and select New ATL Object. Select Simple Object in the displayed dialog box and click Next. Type in "MyAtl" as the C++ short name. Click the Attribute tab and select Support Connection Points. Click OK and a new ATL object is added. In the class view, right-click the IMyAtl and choose Add Method. Type "InitTask" in the Method Name text box and "[in] long number" in the parameters text box. Click OK. In the class view, right-click _IMyAtlEvents and select Add Method. Select "void" from return type drop-down list box. Type "TaskFinished" in the Method Name text box and "[in] long result" in the parameters text box. Click OK. In the class view, right-click CMyAtl and choose Add member variable. Type "long" in the variable type text box and "m_number" in the variable name text box. Build the project to generate the type library needed for step 10. In the class view, expand and double-click CMyAtl -> IMyAtl -> InitTask. Edit the InitTask function to make it appear as follows: STDMETHODIMP CMyAtl::InitTask(long number) { HANDLE hThrd; DWORD tid; m_number = number; if((hThrd = CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)justDoIt, (void *)this, 0, &tid)) == NULL) { //error handling here } CloseHandle(hThrd); return S_OK; } Add the following code to the MyAtl.cpp file: DWORD WINAPI justDoIt(LPVOID lpParameter) { CMyAtl *myAtl = (CMyAtl*)lpParameter; long result; for (int i = 1; i <= myAtl->m_number; ++i) result = i * 2; myAtl->Fire_TaskFinished(result); return 0; } Add the following code right above the line "#endif //__MYATL_H_" in MyAtl.h file: DWORD WINAPI justDoIt(LPVOID lpParameter); In the class view, right-click CMyAtl and select Implement Connection Point. Select _IMyAt-Events in the displayed dialog box. C

                    1 Reply Last reply
                    0
                    • T Tim Rymer

                      1. When I throw CWinImpl, into the header, It gives me an error about already having CComControl in my thing as well. What should I do? Should I just make a variable of CWinImpl in my ATL Class? and if that works, how do I make it windowless? do i just not set a STYLE when I create the window? or do i just make a DialogBox and call ShowWindow(WS_HIDE) or something? I dont want anything showing up of course, nothing in the background, etc. Any Tips? ~Timothy T. Rymer www.digipen.edu tim.xpertz.com

                      J Offline
                      J Offline
                      Joao Vaz
                      wrote on last edited by
                      #10

                      The CComControl class derives by default from CWindowImpl, so the error... About the windowless aspect, i think that by default CComControl window is windowless, so no reason to worry, i think :confused: If isn't windowless, then put this in the private parte of your class:

                      unsigned m_bWndLess:1;

                      , this variable is a member of a union declared in CComControlBase, a base class of CComControl, so it's necessary to declare it in the current class, but i think you wouldn't need this ... Cheers; Joao Vaz

                      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