我如何 运行 TD 6.3 程序(SalLoadApp?)中的 .exe

How would I run a .exe from within TD 6.3 program (SalLoadApp?)

大家好,

我正在尝试从现有的 TD6.3 应用程序中 运行 一个 .exe 程序(一个用另一种语言编写的小助手应用程序)。

根据文档,我认为这适用于 SalLoadApp(或者理想情况下适用于 SalLoadAppAndWait,因为我确实需要等待它完成并希望它对用户不可见 - 该应用程序是一个控制台没有可见输出或用户交互的应用程序),但尝试像这样调用它根本没有任何作用。 我已经尝试将应用程序名称作为参数(它与 TD 应用程序位于同一文件夹中):

Call SalLoadApp('HelperApp.exe', '')

以及完整路径:

Call SalLoadApp('C:\Users\user\ProjectFolder\HelperApp.exe', '')

我是不是误解了它的工作原理或遗漏了什么?它只适用于 TD 应用程序吗?是否有另一种通过代码执行现有非 TD .exe 文件的方法?

是的,您可以为此目的使用 SalLoadApp。该函数可用于调用 任何 exe 文件(没有像只有 td exe 那样的限制)。例如,如果你想调用 windows 计算器,只需写

SalLoadApp( "calc.exe", "" )

此外,如果您要指定文件路径,请使用双斜杠(而不是单斜杠),如下所示,

Call SalLoadApp('C:\Users\user\ProjectFolder\HelperApp.exe', '')

SalLoadApp 的格式为:SalLoadApp( strAppName, strParameters )

strAppName - exe 文件的名称。

strParameters - 参数数组(strParameters 中的space 标记一个参数的结尾)。

此外,如果您想在不指定文件位置的情况下调用 salloadapp,则可以将两个 exe 文件保存在同一文件夹中-(HelperApp.exe 和调用应用程序)

使用 ShellExecuteW()。这样你就有了更多的控制权

1) 将其作为外部函数包含在 SHELL32.dll 中:

Library name: SHELL32.DLL
ThreadSafe: No
Function: ShellExecuteW
    Description: The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file. See ShellExecuteEx also.

    Export Ordinal: 0
    Returns
        Number: DWORD
    Parameters
        Window Handle: HWND
        String: LPWSTR
        String: LPWSTR
        String: LPWSTR
        String: LPWSTR
        Number: INT

2) 运行 您的 exe 具有以下语法(或查找 'ShellExecute' 以获取更多信息)

Call ShellExecuteW( hWndNULL, "open", "C:\Program Files (x86)\Gupta\TeamDeveloper6.2.1\Your.exe", STRING_Null, STRING_Null, SW_SHOWNORMAL )

3) 可选地编写一个包装函数,这样你就可以检查任何你想要的 return 代码,例如:

Select Case nRet
Case SE_ERR_FNF
    If spApplication
        Set sError = 'Either the Application, or the specified file was not found. ' || sCTRL || sCTRL ||
                'Check the Application ' || spApplication || ' and any Compatibility Packs have been installed on this machine .' || sCTRL  || sCTRL  ||
                'Check the file ' || spFile || ' exists. '
    Else
        Set sError = 'The specified file was not found. ' || sCTRL || sCTRL ||
                'Check the file ' || spFile || ' exists. '
    Break
Case SE_ERR_PNF
    Set sError = 'The specified Path was not found'
    Break
Case SE_ERR_ACCESSDENIED
    Set sError = 'The operating system denied access to the specified file.'
    Break
Case SE_ERR_ASSOCINCOMPLETE
    Set sError = 'The filename association is incomplete , invalid, or has not been defined within Windows'
    Break
Case SE_ERR_DDEBUSY
    Set sError = 'The DDE transaction could not be completed because other DDE transactions are being processed.'
    Break
Case SE_ERR_DDEFAIL
    Set sError = 'The DDE transaction failed.'
    Break
Case SE_ERR_DDETIMEOUT
    Set sError = 'The DDE transaction could not be completed because the request timed out'
    Break
Case SE_ERR_NOASSOC
    Set sError = 'There is no application associated with the given filename extension'
    Break
Case SE_ERR_OOM
    Set sError = 'There was not enough memory to launch the application'
    Break
Case SE_ERR_SHARE
    Set sError = 'Another user has this document open.'
    Break
Case 0
    Set sError = 'The operating system is out of memory or resources'
    Break
Default
    Break


If nRet <=32
If spApplication
    Call SalMessageBox( sError || sCTRL || sCTRL ||
             'File Name =  ' || spFile || sCTRL || sCTRL ||
            'Application Name = ' ||  spApplication , 'Application or File Open Error' , MB_IconStop  |  MB_Ok )
Else
    Call SalMessageBox( sError || sCTRL || sCTRL ||
             'File Name =  ' || spFile , 'File Open Error' , MB_IconStop  |  MB_Ok )
If nRet = SE_ERR_NOASSOC or nRet = SE_ERR_ASSOCINCOMPLETE
    ! Now open the OpenAs dialog from Windows to select an application from a list or browse.
    Call ShellExecuteW( hWndNULL, "open", "rundll32.exe", "shell32.dll,OpenAs_RunDLL " || spFile, STRING_Null, npShowState )
Set bOk = FALSE