WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Jeremy Whilde on June 23, 2015, 08:14:14 AM

Title: How to avoid Bad DDE channel request in While loop?
Post by: Jeremy Whilde on June 23, 2015, 08:14:14 AM
I am using  the following code inside a While 1 loop as a way to wait for a particular URL to appear in a browser window, this works well except occasionally on some machines when the browser is closed we get a 3152: DDEReq: Bad channel number.

Thought the BrowserOpen = FindWindow('IEFrame') and If BrowserOpen <> "" would help but still get the occasional Bad channel error,  guess occasionally the browser is closed when this line of code has run so the DDE fails because the channel does not exist?!

Does anyone have any suggestions how can we avoid this?

Thanks JW

   ;---------------------------------------------------------------------------
   ; Check If a browser is running (wait for the browser),  IE at the moment
   ;---------------------------------------------------------------------------
   Browser = ""   ; Initialise variable just in case
   Browser = FindWindow('IEFrame')

   While Browser == ""
      Browser = FindWindow('IEFrame')
      TimeDelay(.5)
   EndWhile


   ;-------------------------------------
   ; Define browser type & check URL
   ;-------------------------------------
   
   BrowserOpen = FindWindow('IEFrame')
   If BrowserOpen <> ""
      BrowserType = ""   ; Initialise variable just in case
      BrowserType = "Iexplore"
      channel=DDEInitiate(BrowserType, "WWW_GetWindowInfo")  ;Initialize DDE
      Info = ""   ; Initialise variable just in case
      info = DDERequest( channel, "0xFFFFFFFF" )  ;<<<----Error here only some times????
      DDETerminate(channel)
        Endif

;Rest of the While loop

Title: Re: How to avoid Bad DDE channel request in While loop?
Post by: td on June 23, 2015, 01:26:35 PM
The  DDEInitiate topic example in the WIL Consolidated Help file shows one method.
Code (winbatch) Select
url = ''
If AppExist('iexplore')
   browser = 'iexplore'
   channel = DDEInitiate(browser, 'WWW_GetWindowInfo') ;Initialize DDE
   If channel != 0 ;If DDE OK Execute DDE Command
      url = DDERequest( channel,-1)
      DDETerminate(channel)
   EndIf
Else
   Pause('','No active IE browser')
   Exit
EndIf
Message('Active URL in ':browser, url)