Problem changing proxy with custom IE toolbar
-
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"<
-
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"<
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/[^]
-
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/[^]
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.
-
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.
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/[^]
-
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/[^]
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.