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. Problem changing proxy with custom IE toolbar

Problem changing proxy with custom IE toolbar

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminwindows-admintools
5 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.
  • M Offline
    M Offline
    Matthew Devine
    wrote on last edited by
    #1

    When I execute the following code in my program, it works fine when I toggle the buttons that I generated. However, if I go into IE and manually set the proxy via Tools -> Internet Options -> Connections -> Lan Settings -> Check/Uncheck "Use a Proxy setting...", it works the first time and runs the correct method, so if I check the box and turn the proxy server on and click Ok it will run the ProxyOn() method. However if I don't compeletly close out Internet Options and and go back into Lan Settings and uncheck the box and click OK, it will run the ProxyOn() method again. Now the really confusing part is the fact that if I do it a third time or more, it won't double run the methods but it will be one off from what it should be running. I know its alot to digest but does anybody have any ideas. So here I have the thread that I create to watch for a change in the proxy setting. hThread = CreateThread (NULL, 0, (unsigned long (__stdcall *)(void *))this->ThreadFunc, (void *)(this), 0, &this->hThreadId); DWORD WINAPI CMFToolbar::ThreadFunc(LPVOID lParam) { CMFToolbar *toolbar = (CMFToolbar*)lParam; while(1){toolbar ->WINAPI_tWinMain();}; } int CMFToolbar::WINAPI_tWinMain() { LONG l = 0L; HKEY hKey = {0}; //Open Registry Key to watch l = RegOpenKeyEx ( HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), 0, KEY_NOTIFY, &hKey ); if(l == ERROR_SUCCESS) { // The following call will wait until a change is made to the registry key. l = RegNotifyChangeKeyValue ( hKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE ); RegCloseKey(hKey); //Determines whether or not Proxy is enabled and executes proper method DWORD flag = 0; if ( InternetGetConnectedState ( &flag, 0 ) ) { if ( flag & INTERNET_CONNECTION_PROXY ) { fout<<"Proxy Off Method"<

    J 1 Reply Last reply
    0
    • M Matthew Devine

      When I execute the following code in my program, it works fine when I toggle the buttons that I generated. However, if I go into IE and manually set the proxy via Tools -> Internet Options -> Connections -> Lan Settings -> Check/Uncheck "Use a Proxy setting...", it works the first time and runs the correct method, so if I check the box and turn the proxy server on and click Ok it will run the ProxyOn() method. However if I don't compeletly close out Internet Options and and go back into Lan Settings and uncheck the box and click OK, it will run the ProxyOn() method again. Now the really confusing part is the fact that if I do it a third time or more, it won't double run the methods but it will be one off from what it should be running. I know its alot to digest but does anybody have any ideas. So here I have the thread that I create to watch for a change in the proxy setting. hThread = CreateThread (NULL, 0, (unsigned long (__stdcall *)(void *))this->ThreadFunc, (void *)(this), 0, &this->hThreadId); DWORD WINAPI CMFToolbar::ThreadFunc(LPVOID lParam) { CMFToolbar *toolbar = (CMFToolbar*)lParam; while(1){toolbar ->WINAPI_tWinMain();}; } int CMFToolbar::WINAPI_tWinMain() { LONG l = 0L; HKEY hKey = {0}; //Open Registry Key to watch l = RegOpenKeyEx ( HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), 0, KEY_NOTIFY, &hKey ); if(l == ERROR_SUCCESS) { // The following call will wait until a change is made to the registry key. l = RegNotifyChangeKeyValue ( hKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE ); RegCloseKey(hKey); //Determines whether or not Proxy is enabled and executes proper method DWORD flag = 0; if ( InternetGetConnectedState ( &flag, 0 ) ) { if ( flag & INTERNET_CONNECTION_PROXY ) { fout<<"Proxy Off Method"<

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      Have you tried reading the "ProxyEnabled" (I guess that's the one) value in the key you are monitoring instead of using InternetGetConnectedState? -- jlr http://jlamas.blogspot.com/[^]

      M 1 Reply Last reply
      0
      • J Jose Lamas Rios

        Have you tried reading the "ProxyEnabled" (I guess that's the one) value in the key you are monitoring instead of using InternetGetConnectedState? -- jlr http://jlamas.blogspot.com/[^]

        M Offline
        M Offline
        Matthew Devine
        wrote on last edited by
        #3

        Jose Lamas Rios wrote: Have you tried reading the "ProxyEnabled" (I guess that's the one) value in the key you are monitoring instead of using InternetGetConnectedState? I was also wondering why the code I posted before was acting that way. I'm just assuming I'm not seeing the problem because I put it together.

        J 1 Reply Last reply
        0
        • M Matthew Devine

          Jose Lamas Rios wrote: Have you tried reading the "ProxyEnabled" (I guess that's the one) value in the key you are monitoring instead of using InternetGetConnectedState? I was also wondering why the code I posted before was acting that way. I'm just assuming I'm not seeing the problem because I put it together.

          J Offline
          J Offline
          Jose Lamas Rios
          wrote on last edited by
          #4

          Matthew Devine wrote: I was also wondering why the code I posted before was acting that way Yeah, me too :) Matthew Devine wrote: I'm just assuming I'm not seeing the problem because I put it together. Well, I couldn't find anything obviously wrong in your code either, but that doesn't mean a lot, since I have no experience with that kind of things. The only thing I noted is that there is a possibility that if a change is made between your call to InternetGetConnectedState and the call to RegNotifyChangeKeyValue in the next iteration, you would lose a notification. However, that's a very tiny fraction of time, and it doesn't seem possible to be caught in that situation doing changes through IE's dialogs. Furthermore, it wouldn't explain what you describe (InternetGetConnectedState returning out-of-date results)... I think the actual problem may be related to InternetGetConnectedState not taking its results directly from the registry. If the state is also stored in some other place, maybe your query is being done after the registry was modified but before this other state is actually updated. That's why I suggested reading the registry; reading the values from the same place about which you get notifications seem to make more sense. Does it work? -- jlr http://jlamas.blogspot.com/[^]

          M 1 Reply Last reply
          0
          • J Jose Lamas Rios

            Matthew Devine wrote: I was also wondering why the code I posted before was acting that way Yeah, me too :) Matthew Devine wrote: I'm just assuming I'm not seeing the problem because I put it together. Well, I couldn't find anything obviously wrong in your code either, but that doesn't mean a lot, since I have no experience with that kind of things. The only thing I noted is that there is a possibility that if a change is made between your call to InternetGetConnectedState and the call to RegNotifyChangeKeyValue in the next iteration, you would lose a notification. However, that's a very tiny fraction of time, and it doesn't seem possible to be caught in that situation doing changes through IE's dialogs. Furthermore, it wouldn't explain what you describe (InternetGetConnectedState returning out-of-date results)... I think the actual problem may be related to InternetGetConnectedState not taking its results directly from the registry. If the state is also stored in some other place, maybe your query is being done after the registry was modified but before this other state is actually updated. That's why I suggested reading the registry; reading the values from the same place about which you get notifications seem to make more sense. Does it work? -- jlr http://jlamas.blogspot.com/[^]

            M Offline
            M Offline
            Matthew Devine
            wrote on last edited by
            #5

            Well I'm having some trouble checking the registry key setting for "ProxyEnable", I can't seem to get it to work. I'm also not to sure about getting a DWORD value from the registry, but I'll let you know if I figure it out.

            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