Solved

Part 2 of DDE/Netscape/Binary Arrays

Posted on 1997-11-02
3
295 Views
Last Modified: 2008-03-10
For Alamo:

Via DDE, Netscape can return a list of its open windows (WWW_ListWindows). The value returned is a long word array. If I pass a long to WWW_GetWindowInfo, I'll get back the URL and the title,
             which I want.

             My question is how within the confines of VB DDE handling do I parse
             what WWW_List Window returns?

             Here's netscapes Doc: see
             http://developer.netscape.com/library/documentation/communicator/DDE/ddeapi.htm
0
Comment
Question by:cellphone
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 100 total points
ID: 1439512
It turns out that in fact you can call the DDE API from VB, at least for a simple request.

Here's the code:

' DDE API declares
Private Declare Function DdeInitialize Lib "user32" Alias "DdeInitializeA" (pidInst As Long, ByVal pfnCallback As Long, ByVal afCmd As Long, ByVal ulRes As Long) As Integer
Private Declare Function DdeCreateStringHandle Lib "user32" Alias "DdeCreateStringHandleA" (ByVal idInst As Long, ByVal psz As String, ByVal iCodePage As Long) As Long
Private Declare Function DdeFreeStringHandle Lib "user32" (ByVal idInst As Long, ByVal hsz As Long) As Long
Private Declare Function DdeDisconnect Lib "user32" (ByVal hConv As Long) As Long
Private Declare Function DdeUninitialize Lib "user32" (ByVal idInst As Long) As Long
Private Declare Function DdeGetLastError Lib "user32" (ByVal idInst As Long) As Long

' The following declares I needed to change to make the types work out (we are passing 0 for all of these)
'Private Declare Function DdeConnect Lib "user32" (ByVal idInst As Long, ByVal hszService As Long, ByVal hszTopic As Long, pCC As CONVCONTEXT) As Long
 Private Declare Function DdeConnect Lib "user32" (ByVal idInst As Long, ByVal hszService As Long, ByVal hszTopic As Long, ByVal pCC As Long) As Long
'Private Declare Function DdeClientTransaction Lib "user32" (pData As Byte, ByVal cbData As Long, ByVal hConv As Long, ByVal hszItem As Long, ByVal wFmt As Long, ByVal wType As Long, ByVal dwTimeout As Long, pdwResult As Long) As Long
 Private Declare Function DdeClientTransaction Lib "user32" (ByVal pData As Long, ByVal cbData As Long, ByVal hConv As Long, ByVal hszItem As Long, ByVal wFmt As Long, ByVal wType As Long, ByVal dwTimeout As Long, ByVal pdwResult As Long) As Long
'Private Declare Function DdeGetData Lib "user32" Alias "DdeGetDataA" (ByVal hData As Long, pDst As Byte, ByVal cbMax As Long, ByVal cbOff As Long) As Long
 Private Declare Function DdeGetData Lib "user32" (ByVal hData As Long, ByVal pDst As String, ByVal cbMax As Long, ByVal cbOff As Long) As Long

' DDE API Constants used here
Const APPCMD_CLIENTONLY = &H10&
Const CP_WINANSI = 1004
Const XCLASS_DATA = &H2000
Const XTYP_REQUEST = (&HB0 Or XCLASS_DATA)
Const CF_TEXT = 1

Private Sub Command1_Click()

'I had to change the loop to parse the returned data, turns out it  fails when it hits the final array entry of 0

    t$ = RequestDDEBinaryData("netscape", "WWW_ListWindows", "doesn't matter")
    Do While Len(t$) > 0
        win& = GetNextDW&(t$)
        If win& = 0 Then Exit Do
        MsgBox "Window " & win& & ": " & GetWindowInfo(win&)
    Loop
End Sub

' Function GetNextDW& and GetWindowInfo is unchanged from last message (http://www.experts-exchange.com/topics/bin/ShowQ?qid=8630022627)

Public Sub CheckForDDEError(idInst&, context$)
Dim errnum As Long
    errnum = DdeGetLastError(idInst)
    If errnum <> 0 Then
        MsgBox "Error: " & errnum & " (" & Hex$(errnum) & ") after " & context$
    End If
End Sub

Public Function RequestDDEBinaryData(service$, topic$, item$) As String

Dim idInst As Long         ' DDE Instance handle
Dim hcnv As Long           ' Conversation handle
Dim hszData  As Long        ' StringHandles
Dim hszItem  As Long
Dim hszService As Long
Dim hszTopic As Long
Dim retVal As Integer

    'Though it's undocumented, DdeInitialize seems to be fine with a null callback function. If needed, write a callback using VB5
    idInst = 0
    retVal = DdeInitialize(idInst, 0, APPCMD_CLIENTONLY, 0)
    If retVal <> 0 Then
        MsgBox "Unable to initialize DDE, error =" & retVal & " " & Hex$(retVal)
        Exit Function
    End If
   
    ' Create some string objects we can use for service, topic, item
    hszService = DdeCreateStringHandle(idInst, service$, CP_WINANSI)
    CheckForDDEError idInst, "DdeCreateStringHandle(service)" ' a little overboard on the error checking but this is for test
    hszTopic = DdeCreateStringHandle(idInst, topic$, CP_WINANSI)
    CheckForDDEError idInst, "DdeCreateStringHandle(topic)"
    hszItem = DdeCreateStringHandle(idInst, item$, CP_WINANSI)
    CheckForDDEError idInst, "DdeCreateStringHandle(item)"
   
    ' Connect to the service / topic
    hcnv = DdeConnect(idInst, hszService, hszTopic, 0)
    CheckForDDEError idInst, "DdeConnect"
   
    ' Request the item from the server - we get handle to resulting data object back
    hszData = DdeClientTransaction(0, 0, hcnv, hszItem, CF_TEXT, XTYP_REQUEST, 1000, 0)
    CheckForDDEError idInst, "DdeClientTransaction"
   
    ' get the returned data
    buffer$ = Space$(256)
    retVal = DdeGetData(hszData, buffer$, Len(buffer$), 0)
    RequestDDEBinaryData = Left$(buffer$, retVal)
    CheckForDDEError idInst, "DdeGetData"
   
    ' Done, free everything we created and we are done
    retVal = DdeFreeStringHandle(idInst, hszService)
    CheckForDDEError idInst, "DdeFreeStringHandle(hszService)"
    retVal = DdeFreeStringHandle(idInst, hszTopic)
    CheckForDDEError idInst, "DdeFreeStringHandle(hszTopic)"
    retVal = DdeFreeStringHandle(idInst, hszItem)
    CheckForDDEError idInst, "DdeFreeStringHandle(hszItem)"
    retVal = DdeDisconnect(hcnv)
    CheckForDDEError idInst, "DdeDisconnect"
    retVal = DdeUninitialize(idInst)
End Function

0
 
LVL 6

Expert Comment

by:alamo
ID: 1439513
Cellphone, I assume no news is good news, and the above code worked? If not, let me know - if so, please grade this question (so it doesn't get autograded to C due to inactivity). Thanks!
0
 

Author Comment

by:cellphone
ID: 1439514
have'nt had time to try it ... but won't hold you up.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question