Highlighted
Absent Member.
Absent Member.
2513 views

[archive] command Line under thin client

[Migrated content. Thread originally posted on 10 August 2006]

Hi,

Currently I have a DLL which calls the getcommandline function and returns the whole command line. I use this to scan the command line to find out where the configuration file and error output files are located. I use this information to send via Email when the application fails.

However, I am now trying this using thinclient, and while I can create a similar command line from the windows shortcut, the windows getcommandline is only returning the value upto the end of the server-name, nothing else after that.

The Acucobol Doco makes reference to and external array called Acmd_line, whta is this and how do you access it and does it contain the FULL command line as opposed to what ACCEPT FROM COMMAND-LINE gives you?

Is there another way of obtaining the path/name of the error/config files from the runtime/thinclient or do we have to try and interrogate the command line?

Another option is to try and set a number of configuration file entries to emulate where these files are and what there names are.

Any suggestions would be great

thanks
0 Likes
12 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Currently I have a DLL which calls the getcommandline function and returns the whole command line.
However, I am now trying this using thinclient, and while I can create a similar command line from the windows shortcut, the windows getcommandline is only returning the value upto the end of the server-name, nothing else after that.


You don't say anything about how this works. But having in mind that GetCommandLine() is returning a pointer, I find it likely that the problem is either that you copy to little from the pointer or you copy to a PIC X that is too small. Have you checked this, that you are not in fact actually getting just what fits, not what is actually available?

The Acucobol Doco makes reference to and external array called Acmd_line


You don't have access to this one in COBOL, you may make it accessible, but then you have to relink the runtime. Sorry.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

I just use the getcomandline() routine from windows built in a C++ DLL as a pointer. the receiving PIC X is 1024 Bytes long. I know this works because I have used it many times with the standard runtime. Its only when I use it with thinclient that it gets chopped.

eg.

Standard runtime shortcut set to "M:\acucbl610\acugt\bin\wrun32.exe -d -x -l -e ..\%username%.err -c ..\v86.cfg i:\clients\version8.6\objprogs\plauxm.aob"

returns "M:\acucbl610\acugt\bin\wrun32.exe -d -x -l -e ..\%username%.err -c ..\v86.cfg i:\clients\version8.6\objprogs\plauxm.aob"

Thin client shortcut set to "M:\acucbl610\acugt\bin\acuthin.exe hal9000 -l -x -e client.err -c client.cfg"

returns "M:\acucbl610\acugt\bin\acuthin.exe hal9000"

Where is the rest of the command line?

Is Acuthin truncating the line?

Rebuilding the runtime is not an option.

Is there another way of obtaining the path/name of the error file and config file?

as far as I can see, I would have to set a configuration item to the path/name of the error and config files and in the begining of the initial program actually test to see if those files are there, I would then either exit the application with a message that it cannot find these files (so as to force the correct placement of these files) or continue with the application.

Any other suggestions?

Regards
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Here is the DLL source I use to get the command line, I don't think there is anything wrong with it.


#include
#include
#include
#include

#define INFO_BUFFER_SIZE 32767
#define CL9000_API __declspec(dllexport)

CL9000_API int GetCobolCommandLine(char *cobol_cmd_line);
CL9000_API int GetCobolSysUser(char *cobol_sysuser);

LPTSTR  pszCmdLine;

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
//            MessageBox(NULL, "DLL Process Attach", "DLL Message 1", MB_OK);
            break;
        case DLL_THREAD_ATTACH:
//            MessageBox(NULL, "DLL Thread Attach", "DLL Message 2", MB_OK);
            break;
        case DLL_THREAD_DETACH:
//            MessageBox(NULL, "DLL Thread Detach", "DLL Message 3", MB_OK);
            break;
        case DLL_PROCESS_DETACH:
//            MessageBox(NULL, "DLL Process Detach", "DLL Message 4", MB_OK);
            break;
    }
    return TRUE;
}


CL9000_API int GetCobolCommandLine(char *cobol_cmd_line)
{
    pszCmdLine = GetCommandLine();
    strcpy(cobol_cmd_line, pszCmdLine);
    return true;
}

CL9000_API int GetCobolSysUser(char *cobol_sysuser)
{
    DWORD bufCharCount;

    bufCharCount = INFO_BUFFER_SIZE;
    GetUserName(pszCmdLine, &bufCharCount);
    strcpy(cobol_sysuser, pszCmdLine);
    return true;
}


Regards
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Your C code looks valid, I cannot see any particular reason it should behave like you experience. Any chance I can get to see a sample COBOL program using the DLL function as well?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Here is a sample snippet of code that I use to call the DLL


....
    05  WS-COMMAND-LINE                 PIC X(512).
....
    CALL "CL9000.DLL"
        ON EXCEPTION
            CONTINUE.
    PERFORM GET-COMMAND-LINE.
....
GET-COMMAND-LINE.
     MOVE SPACES TO WS-COMMAND-LINE
     CALL "GetCobolCommandLine" USING WS-COMMAND-LINE
         ON EXCEPTION
             EXIT PARAGRAPH
     END-CALL
....
    CANCEL "CL9000.DLL".
....


I use the default setting for DLL convention, sorry the command line is only defined as a pic x(512) not 1024.

Regards
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

I notice that CL9000_API only declares the function for export. I am not sure what compiler you use, but depending on the compiler default this will be exported with some calling convention.
The standard on Windows is the PASCAL calling convention, which is not the standard in ACUCOBOL-GT.
If the dll defaults to PASCAL, you should use the @WINAPI suffix (or SET DLL-CONVENTION TO 1) when you load your DLL, like:
CALL "MyDLL@WINAPI"
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

I'll give that a go and see what thinclient returns

Thanks
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Hi,

I am using MS C++ version 6.0. I do not use the DLL_CONVENTION in Acucobol. And the calling convention in the project is set to "__cdecl*"

using @WINAPI caused an on exception when loading the "getCommandLine" function.
using DLL_CONVENTION set to 1 causes a MAV

The only way I can get it to work is setting DLL_CONVENTION to 0 and not use @WINAPI. This returns me the full command line when using the standard runtime and only upto the server name when using thinclient.

the version of Acucobol I am using is 6.1.0


Regards
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Further to this I have now coded this directly into the cobol program as follows:


77  AllocPtr         USAGE POINTER.
77  WS-COMMAND-LINE  PIC X(1024).


    SET ENVIRONMENT "DLL-CONVENTION" TO "1".
    CALL "kernel32.DLL"
        ON EXCEPTION
            CONTINUE
        NOT ON EXCEPTION
            CALL "msvcrt.DLL"
                ON EXCEPTION
                    CONTINUE
                NOT ON EXCEPTION
                    PERFORM GET-COMMAND-LINE
            END-CALL
    END-CALL.


    SET ENVIRONMENT "DLL-CONVENTION" TO "1".
    CALL "GetCommandLineA" GIVING AllocPtr
         ON EXCEPTION
             EXIT PARAGRAPH.
    SET ENVIRONMENT "DLL-CONVENTION" TO "0".
    CALL "strcpy" USING BY REFERENCE WS-COMMAND-LINE
                        BY VALUE AllocPtr
         ON EXCEPTION
             EXIT PARAGRAPH.

    CANCEL "msvcrt.DLL".
    CANCEL "kernel32.DLL".


And it returns me exactly the same result as mentioned previously.
How can I be sure that I am getting the whole command line? Is there a way to determine the length of the command line returned? Is a NULL getting in the way when using Acuthin etc.....?

Regards
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Apart of the pointer, your example was fine. You should not use USAGE POINTER unless you compile with -Dw32 -Dl4 (on Win32).

However, I fixed your pointer stuff, made it a full sample and ran it with 7.2.0 and it works like a champ.

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  GetCMD.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
       WORKING-STORAGE SECTION.
       77  MemPtr           PIC X(4) COMP-N.
       77  WS-COMMAND-LINE  PIC X(1024).

       PROCEDURE DIVISION.
       MAIN-LOGIC.

           CALL    "kernel32.DLL@WINAPI".
           CALL    "msvcrt.DLL@STDC".
           CALL    "GetCommandLineA" GIVING MemPtr.
           CALL    "strcpy"         USING
                   BY REFERENCE     WS-COMMAND-LINE
                   BY VALUE         MemPtr.
           CANCEL  "msvcrt.DLL".
           CANCEL  "kernel32.DLL".
           DISPLAY MESSAGE          BOX
                   WS-COMMAND-LINE
                   TITLE            "What's on the command line"
           GOBACK.


One thing that I came to think about, do you really provide your parameters on the command line, or do you have them in the acurcl.ini configuration?

If the latter, that explains. That is not on the command line and will thus not be given you from an API command.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] command Line under thin client

Thanks.

But that leads to the initial question of how do I obtain the physical path/name of the error file/config file from the runtime/thinclient?

I want to use the information to attach to an Email for support purposes of our applicaiton.

Regards
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.