Solved

Part 2 of DDE/Netscape/Binary Arrays

Posted on 1997-11-02
3
291 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now