DDEInitiate() from a Client May Require a Pause

Last reviewed: April 29, 1996
Article ID: Q100562
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a

SUMMARY

When a dynamic data exchange (DDE) client application starts FoxPro for Windows and runs a program that sets up FoxPro as a DDE server application, the client application may need to pause while FoxPro's server program is loading. Not waiting until FoxPro is properly configured can result in error messages stating that the DDE server is unobtainable.

Having to wait, and the length of the pause while a FoxPro program sets up FoxPro as a server application, may be influenced by the speed of the hardware and software being used. The length of the required pause or wait may vary. For example, some applications and some machines may require little or no pause to initiate a channel, while others may need to wait several seconds.

For example, Microsoft Excel version 4.0 may return the error "Remote data not accessible. Start application MYSERVER.EXE?" This error may be generated even if Microsoft Excel had just launched FoxPro and run a .PRG file to publish MYSERVER as a DDE server application (example below). Consequently, when FoxPro is being used as a DDE client application, it may also have to pause before issuing a DDEInitiate() command to an application it just started. Any program that multitasks in the Microsoft Windows environment may exhibit these symptoms.

MORE INFORMATION

The following Microsoft Excel macro requires a pause. ("A1" indicates cell A1 on a Microsoft Excel macro sheet.).

   A1:   =EXEC("foxprow.exe c:\foxprow\tutorial\ddeserve.prg",3)
   A2:   =APP.ACTIVATE()
   A3:   m.initial.chan=INITIATE("myserver","DO")
   A4:   =EXECUTE(m.initial.chan,"SET DEFAULT TO c:\foxprow\tutorial")
   A5:   =EXECUTE(m.initial.chan,"USE customer")
   A6:   =TERMINATE(m.initial.chan)
   A7:   =RETURN()

This Microsoft Excel macro launches FoxPro and runs the DDESERVE.PRG program (found below), which sets up FoxPro as a server application to accept commands from a DDE client application (Microsoft Excel in this case).

However, on machines that have a fast CPU and hard disk, this macro results in a "Remote data not accessible. Start application MYSERVER.EXE?" error message in Microsoft Excel. This error occurs because Microsoft Excel, as a multitasking program for Windows, executes its DDEInitiate() command before FoxPro has time to configure itself as a DDE server application. In other words, Microsoft Excel and FoxPro are running their respective programs at the same time, resulting in Microsoft Excel trying to establish a DDE channel to a server application that is not yet running.

To correct this problem, add a pause or wait statement in the DDE client application, letting FoxPro (or any server application) finish configuring itself.

In Microsoft Excel, a WAIT() statement will pause a macro long enough for FoxPro to finish executing its server program. The revised Microsoft Excel macro would then be:

   A1:   =EXEC("foxprow.exe c:\foxprow\tutorial\ddeserve.prg",3)
   A2:   =APP.ACTIVATE()
   A3:   =WAIT(NOW()+"00:00:03")
   A4:   m.initial.chan=INITIATE("myserver","DO")
   A5:   =EXECUTE(m.initial.chan,"SET DEFAULT TO c:\foxprow\tutorial")
   A6:   =EXECUTE(m.initial.chan,"USE customer")
   A7:   =TERMINATE(m.initial.chan)
   A8:   =RETURN()

The above WAIT() statement in cell A3 tells Microsoft Excel to pause the macro 3 seconds, giving FoxPro a chance to finish loading its server program before Microsoft Excel tries to open a channel to it.

The DDESERVE.PRG Program

   *** Save as DDESERVE.PRG in the \FOXPROW\TUTORIAL directory ***

   *** Set FoxPro up as a DDE server ***
   = DDESetService('myserver', 'DEFINE')
   = DDESetService('myserver', 'EXECUTE', .T.)
   = DDESetTopic('myserver', 'DO', 'DOTOPIC')

   PROCEDURE dotopic
   PARAMETERS channel, action, item, data, format, advise
   mresult = .F.

   *** It's necessary to return .T. from an     ***
   *** INITIATE action or no connection is made ***

   IF action = 'INITIATE'
        mresult = .T.
   ENDIF

   IF action = 'EXECUTE'
        &data
        mresult = .T.
   ENDIF

   IF action = 'TERMINATE'
        WAIT WINDOW 'Goodbye ... ' NOWAIT
        mresult = .T.
   ENDIF
   RETURN mresult

REFERENCES

Microsoft Excel "Function Reference"

FoxPro for Windows "Language Reference"


Additional reference words: FoxWin 2.50 2.50a SetServer SetTopic
KBCategory: kbinterop kbprg
KBSubcategory: FxinteropDde


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.