Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get ComputerName (adapted from Visual basic Project)
Message
From
14/07/1999 11:22:30
 
 
To
14/07/1999 09:21:14
Anderson Girardi
Athenas Automação de Escritório
Porto Alegre, Brazil
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00241239
Message ID:
00241269
Views:
13
>hello Dear friends!
>
>I wanna get the computer name, i have a project in Visual Basic that does it, but i´m trying to convert to Visual FoxPro and ai having GPF when i execute it.
>
>The Project in Visual Basic is:
>
>Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal sBuffer As String, lSize As Long) As Long
>
>Private Sub Command1_Click()
> Dim PCName As String
> Dim P As Long
> P = NameOfPC(PCName)
> Text1.Text = PCName
>End Sub
>
>Function NameOfPC(MachineName As String) As Long
> Dim NameSize As Long
> Dim X As Long
> MachineName = Space$(16)
> NameSize = Len(MachineName)
> X = GetComputerName(MachineName, NameSize)
>End Function
>
>
>And My Visual FoxPro program is:
>
>Declare String GetComputerName In Kernel32
>P = NameOfPC()
>
>
>Procedure NameOfPC
> MachineName = " "
> NameSize = Len(MachineName)
> X = GetComputerName()
> Return X
>
>What i´m doing wrong????

Pretty much you aren't decalring the function properly, or handling the return. The API declaration would be as follows:
DECLARE INTEGER GetComputerName IN Win32API ;
	STRING  @cComputerNameBuffer, ;
	INTEGER @nLengthOfName

and then to use it:

LOCAL cMyBuffer, nBufferLen, nResult, cReturnVal
*
*  Create a fixed-length buffer to hold result;  we'll examine the buffer length
*   after the call to see how long the name really is
*
cMyBuffer = SPACE(255)+CHR(0)
nBufferLen=256
nResult = GetComputerName(@cMyBuffer, @nBufferLen)
IF nResult = 1
   cReturnVal=STRTRAN(LEFT(cMyBuffer,nBufferLen),CHR(0),'')
ELSE
   cReturnVal = ''
ENDIF
*  cReturnVal now has the computer name in it
>
>Thanks
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform