[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Your code works on my Windows XP.
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Indeed ... I tried this at home and my routine works, except one small thing. My comp. at home call 'Brother Home' and the routine just returns 'Brother', even if I rename my comp. to 'Brother-Home'.
Anyway, I tried the same routine on my laptop now at home and the fields stay blank.
Any reason for this to happen ?
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
I just use the following - seems to work OK.
accept LNK-COMPUTER-NAME from EVIRONMENT "COMPUTERNAME".
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
I just use the following - seems to work OK.
accept LNK-COMPUTER-NAME from EVIRONMENT "COMPUTERNAME".
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Originally posted by Hans
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
A number of problems here:
1. You do nowhere set the size of lpBuffer. This should be set with th lpnSize variable. The function takes this variable on input to determine if it has space to hold the name of the computer. To be exact, set lpnSize to 250. Upon return, this variable will hold the actual length of the computer name copied to the buffer.
2. To my knowledge, the second parameter in this case is a DWORD, DWORD is 4 bytes, thus, the size of the second parameter is too big. Reduce it to 4.
That this works on some computers and not on others is because your variables are not initialized, thus, whatever is currently present in the memory of the variable at execution time is used.
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Txs Ghisle and others ...
The accept comp-name from environment "COMPUTERNAME" works ok.
And Ghisle, I changed my project with the comments you suggested and now it works ok.
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Just as a footnote to the accept computername solution - I believe that you must be careful with older versions of Windows - sometimes the environment name is different and sometimes not there at all on 98 and earlier.
[Migrated content. Thread originally posted on 30 December 2005]
Looking into the API-exemples, I don't get my routine to work
01 lpBuffer PIC X(250).
01 lpnSize PIC X(8) COMP-N.
SET ENVIRONMENT "DLL_CONVENTION" TO "1".
CALL "Kernel32.DLL".
CALL "GetComputerNameA" USING
BY REFERENCE lpBuffer
BY REFERENCE lpnSize
END-CALL.
The variables stay empty. Where are the bugs ?
Just as a footnote to the accept computername solution - I believe that you must be careful with older versions of Windows - sometimes the environment name is different and sometimes not there at all on 98 and earlier.