Resumen Información sobre Net DDE

Aqui va lo que habia mencionado sobre net dde. Disculpen la demora, pero mas
vale tarde que.....

Yo lo implemente con VB 3.0 y equipos conectados usando Windows 3.11 y el
asunto funciona (no se que pasa al hacerlo con VB4 o 5 y bajo Windows 95).
Si en algo puedo ayudar..., solo escriban.



How to Establish a Network DDE Link Using Visual Basic
Article ID: Q93160

----------------------------------------------------------------------
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for
  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0
----------------------------------------------------------------------

SUMMARY
=======

This article demonstrates how to establish a network Dynamic Data Exchange
(DDE) link between two computers running Microsoft Windows for Workgroups.

MORE INFORMATION
================

Under DDE, a destination (or client) application sends commands through DDE
to the source (or server) application to establish a link. Through DDE, the
source provides data to the destination at the request of the destination
or accepts information at the request of the destination. When you use DDE
with Windows version 3.0 or 3.1 based applications, the source and
destination applications are both located on the same computer.

When you use Network DDE with Windows for Workgroups based applications,
DDE functions exactly the same way as standard DDE except that the source
and destination applications are located on different computers.

Before establishing a network DDE link, you must first establish a network

DDE share for the conversation by calling the API NDdeShareAdd() function
located in the NDDEAPI.DLL file. Here is the Visual Basic declaration:

' Enter the following as one, single line:
Declare Function NDdeShareAdd Lib "NDDEAPI.DLL" (Server As Any, ByVal Level
   As Integer, ShareInfo As NDDESHAREINFO, ByVal nSize As Long) As Integer

Enter the entire statement as a single line. The first parameter is always
a 0 and is passed with ByVal 0& from Visual Basic. The second parameter is
always 2. The next parameter is a filled ShareInfo structure (given below).
The last parameter is the size of the ShareInfo structure.

Here is The structure of the NDDESHAREINFO structure:

   Type NDDESHAREINFO
      szShareName As String * MAX_NDDESHARENAME_PLUSONE

      lpszTargetApp As Long 'LPSTR lpszTargetApp
      lpszTargetTopic As Long 'LPSTR lpszTargetTopic
      lpbPassword1 As Long 'LPBYTE lpbPassword1
      cbPassword1 As Long 'DWORD cbPassword1;

      dwPermissions1 As Long 'DWORD dwPermissions1;
      lpbPassword2 As Long 'LPBYTE lpbPassword2;
      cbPassword2 As Long 'DWORD cbPassword2;
      dwPermissions2 As Long 'DWORD dwPermissions2;
      lpszItem As Long 'LPSTR lpszItem;
      cAddItems As Long 'LONG cAddItems;

      lpNDdeShareItemInfo As Long
   End Type

The following table describes each field of the NDDESHAREINFO type:

Field Name Purpose
---------------------------------------------------------------------

szShareName Name of the share to add.
lpszTargetApp Pointer to null-terminated string containing the
                  service or application name.
lpszTargetTopic Pointer to null-terminated string holding the topic name
lpbPassword1 Pointer to the read-only password -- uppercase, null-
                  terminated string. If null, pass null string, not zero.
cbPassword1 Length of read-only password
dwPermissions1 Full access password

cbPassword2 Length of the full access password
dwPermissions2 Permissions allowed by the full access password

Here are the permissions allowed for dwPermissions:

Name Value Function
---------------------------------------------------------------------

NDDEACCESS_REQUEST &H1 Allows LinkRequest
NDDEACCESS_ADVISE &H2 Allows LinkAdvise
NDDEACCESS_POKE &H4 Allows LinkPoke
NDDEACCESS_EXECUTE &H8 Allows LinkExecute
NDDEACCESS_START_APP &H10 Starts source application on connect

Here are the possible return values from NDdeShareAdd():

Name Value Meaning

-------------------------------------------------------------------

NDDE_NO_ERROR 0 No error.
NDDE_BUF_TOO_SMALL 2 Buffer is too small to hold information.
NDDE_INVALID_APPNAME 13 Application name is not valid.

NDDE_INVALID_ITEMNAME 9 Item name is not valid.
NDDE_INVALID_LEVEL 7 Invalid level; nLevel parameter must be 2.
NDDE_INVALID_PASSWORD 8 Password is not valid.
NDDE_INVALID_SERVER 4 Computer name is not valid; lpszServer
                                 parameter must be NULL.
NDDE_INVALID_SHARE 5 Share name is not valid.
NDDE_INVALID_TOPIC 10 Topic name is not valid.

NDDE_OUT_OF_MEMORY 12 Not enough memory to complete request.
NDDE_SHARE_ALREADY_EXISTS 15 Existing shares cannot be replaced.

There are two steps to establish a network Dynamic Data Exchange (DDE) link
between two computers running Microsoft Windows for Workgroups. First,
create the DDE source application. Second, create the DDE destination
application.

Step One -- Create DDE source application
-----------------------------------------

The following steps show you how to create a Visual Basic DDE source
and destination application that communicates through a network DDE link.

1. From the DDE source computer, start Visual Basic or if Visual Basic is
   already running, from the File menu, choose New Project (ALT, F, N).
   Form1 is created by default.

2. Change the LinkTopic property of Form1 to VBTopic.

3. If you are running Visual Basic version 2.0 or 3.0 for Windows, change

   the LinkMode property of Form1 to 1 - Source. In Visual Basic version
   1.0, this property is already set to 1 - Server; don't change it.

4. Add a text box (Text1) to Form1.

5. Change the Name property (CTlName in version 1.0) of Text1 to VBItem.

6. Add a timer (Timer1) to Form1.

7. From the File menu, choose New Module (ALT, F, M). Module1 is created.

8. Add the following code to the general declarations section of Module1,
   and enter all lines as a single line even though they may be shown on
   multiple lines for readability:

   ' DDE access options
   Global Const NDDEACCESS_REQUEST = &H1
   Global Const NDDEACCESS_ADVISE = &H2
   Global Const NDDEACCESS_POKE = &H4
   Global Const NDDEACCESS_EXECUTE = &H8

   Global Const NDDEACCESS_START_APP = &H10
   Global Const MAX_NDDESHARENAME_PLUSONE = 65
   Type NDDESHAREINFO
      szShareName As String * MAX_NDDESHARENAME_PLUSONE
      lpszTargetApp As Long 'LPSTR lpszTargetApp
      lpszTargetTopic As Long 'LPSTR lpszTargetTopic
      lpbPassword1 As Long 'LPBYTE lpbPassword1
      cbPassword1 As Long 'DWORD cbPassword1;
      dwPermissions1 As Long 'DWORD dwPermissions1;
      lpbPassword2 As Long 'LPBYTE lpbPassword2;
      cbPassword2 As Long 'DWORD cbPassword2;

      dwPermissions2 As Long 'DWORD dwPermissions2;
      lpszItem As Long 'LPSTR lpszItem;
      cAddItems As Long 'LONG cAddItems;
      lpNDdeShareItemInfo As Long
   End Type
   Declare Function NDdeShareAdd Lib "NDDEAPI.DLL" (Server As Any, ByVal
      Level As Integer, ShareInfo As NDDESHAREINFO,
      ByVal Size As Long) As Integer
   Declare Function lstrcpy Lib "KERNEL" (szDest As Any, szSource As Any)
      As Long
   'If using Visual Basic version 1.0, add the following declarations
   'Global Const False = 0
   'Global Const True = Not False


9. Add the following code to the Form_Load event of Form1:

   Sub Form_Load ()
      Dim r As Integer
      Dim szShareName As String ' Net DDE share name
      Dim szTargetName As String ' Net DDE target name
      Dim szTopicName As String ' Net DDE source topic name
      Dim szItemName As String
      Dim szReadOnlyPassword As String ' Read-only pw Net DDE share
      Dim szFullAccessPassword As String ' Full access password
      Dim ShareInfo As NDDESHAREINFO

      Dim ShareInfoSize As Long
      Dim Result As Integer
      szShareName = "VBDDESource$" + Chr$(0)
      szTargetName = "VBTARGET" + Chr$(0)

      szTopicName = "VBTopic" + Chr$(0)
      szItemName = Chr$(0) 'All items are allowed
      szReadOnlyPassword = Chr$(0) 'No password
      szFullAccessPassword = Chr$(0)
      'Provide the share, target, topic, and item names along with
      'passwords that identify the network DDE share
      ShareInfo.szShareName = szShareName
      ShareInfo.lpszTargetApp = lstrcpy(ByVal szTargetName,
         ByVal szTargetName)
      ShareInfo.lpszTargetTopic = lstrcpy(ByVal szTopicName,

         ByVal szTopicName)
      ShareInfo.lpszItem = lstrcpy(ByVal szItemName, ByVal szItemName)

      ShareInfo.cbPassword1 = 0
      ShareInfo.lpbPassword1 = lstrcpy(ByVal szReadOnlyPassword,
         ByVal szReadOnlyPassword)
      ShareInfo.dwPermissions1 = NDDEACCESS_REQUEST Or NDDEACCESS_ADVISE Or
         NDDEACCESS_POKE Or NDDEACCESS_EXECUTE Or NDDEACCESS_START_APP
      ShareInfo.cbPassword2 = 0
      ShareInfo.lpbPassword2 = lstrcpy(ByVal szFullAccessPassword,
         ByVal szFullAccessPassword)

      ShareInfo.dwPermissions2 = NDDEACCESS_REQUEST Or NDDEACCESS_ADVISE Or
         NDDEACCESS_POKE Or NDDEACCESS_EXECUTE Or NDDEACCESS_START_APP
      ShareInfo.lpNDdeShareItemInfo = 15
      Result = NDdeShareAdd(ByVal 0&, 2, ShareInfo, Len(ShareInfo))
      ' Start the timer that will continually update the text box and
      ' the DDE link item with random data.
      timer1.Interval = 1000
      timer1.Enabled = True

   End Sub

10. Add the following code to the Timer1_Timer event procedure:

    Sub Timer1_Timer ()
       ' Display random value 0 - 99 in the text box (DDE source data).

       Randomize Timer
       VBItem.Text = Format$(Rnd * 100, "0")
    End Sub

11. From the File menu, choose Make EXE File...

12. Name the file VBTARGET.EXE and choose OK to create the .EXE file.

13. From the File Manager or Program Manager, run VBTARGET.EXE to display
    a random value in the text box every second.

Step Two -- Create the DDE destination application
--------------------------------------------------

14. From the DDE destination computer, start Visual Basic or if Visual
    Basic is already running, from the File menu, choose New Project (ALT,
    F, N). Form1 is created by default.

15. Add a text box (Text1) to Form1.

16. Add the following code to the Form_Load event of Form1:

    Sub Form_Load ()
       Dim r As Long
       Dim szComputer As String ' Network server name.

       Dim szTopic As String
       ' Identify the network server where the DDE source application
       ' is running. The following statement assumes the source computer
       ' name is COMPUTER1. Change it to your source computer name.
       szComputer = "\\COMPUTER1"
       ' Identify the DDE share established by the source application
       szTopic = "VBDDESource$"
       Text1.LinkMode = 0
       ' The link topic identifies the computer name and link topic
       ' as established by the DDE source application
       Text1.LinkTopic = szComputer + "\" + "NDDE$" + "|" + szTopic
       Text1.LinkItem = "VBItem" ' Name of text box in DDE source app


       Text1.LinkMode = 1 ' Automatic link.
    End Sub

    'For this program to work, set the szComputer variable (above) to the
    'computer name that holds the DDE source application. Find the name
    'in the Network section of Windows for Workgroups Control Panel.

17. From the Run menu, choose Start to run the program.

You should see the same random values generated on the source computer
displayed in the text box of the destination computer. If you receive
the error message "DDE method invoked with no channel open" on the
Text1.LinkMode = 1 statement in Step 16, make sure the szComputer
variable is set correctly.

Additional reference words: 1.00 2.00 3.00 NETDDE
KBCategory: kbnetwork kbprg kbcode kbinterop
KBSubcategory: APrgNet IAPDDE

Copyright 1993 Microsoft Corporation. All rights reserved.


*************************
** Saludos desde Chile **
** **
** Esteban Arias **
** earias@cmet.net **
*************************




Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com