Win32 GetComputerNameA... 
Author Message
 Win32 GetComputerNameA...

Can anyone of the gurus or the ascets help me?

I writte this code in VB5 and works right

<!--Begin VB code -->

Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA"
(ByVal lpBuffer As String, nSize As Long) As Long  'Get the name of the
current computer

   Dim l As Long
   Dim s As String

   s = Space(256)
   l = GetComputerName(s, Len(s))

<!-- End VB code -->

 s contains the stringz of the computer name and l the lenght of the
name... ok, but when I do
this in asm...

<!-- Begin ASM code -->

.data

 loccomp           db 256 dup(0)

.code

                push offset loccomp
                push 256
                call GetComputerNameA

<!-- End ASM code -->

only the lenght of the string plus one (6 in my case "willy") is stored
in the buffer and the value of eax is zero...

What i'm doing wrong? I need to offer a wax candle to Saint Gates in the
cathedral?
Or better i will forgot about asm programming and go into the study of
the caribean wild snail life's?

 Using TASM32 5.0 on a WinNT4sp3WSt. with an Intel P166MMX

        Willy Ruiz.
          (Spain)



Sat, 07 Jul 2001 03:00:00 GMT  
 Win32 GetComputerNameA...
2 things wrong here: the 'size' parameter is actually a pointer
to the size, not the actual size.  Also, in the win32 API, parameters
have to be pushed in the reverse order(from right to left), so change
that code to:

.data

 loccomp           db 256 dup(0)
 size              dd 256

.code

                push offset size
                push offset loccomp
                call GetComputerNameA

device



Sat, 07 Jul 2001 03:00:00 GMT  
 Win32 GetComputerNameA...
Ok, thank you very much, now the code works fine, what a dumb mistake i
do :-)
This piece of code retrieve the assigned IPs to the machine, utile in the
case you have
a modem and a ethernet card in your computer.

.data

          loccomp    db 256 dup(0)
          size       dd 256

.code

          push       offset size
          push       offset loccomp
          call       GetComputerNameA
          push       offset loccomp
          call       gethostbyname
          mov        esi,[eax+12]

        ;esi points to an array of pointers finished by a NULL, pointing
to the asigned IPs

 Thanks again, i can drop this snails book



Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. elj-win32 0.4 Release: The GNU Eiffel win32 Distribution

2. elj-win32: A FREE/NO-RISK win32 SmallEiffel Distribution

3. Calling Win32 API functions with Gnat 3.09 (Win32 version)

4. Win32 extensions using the .NET SDK and the Win32 Platform SDK

5. Win32 Debug vs Win32 Release when Fortran files are included (+IMSL)

6. Win32 Console app -> Win32 app: help wanted

7. Win32 Nimda.A@mm (dr) and Win32 Nimda.E@mm (dr)

8. Redefined symbol "select" in win32/win32.h

9. DirectX interface for Python/Win32? PyOpenGL/Win32 status?

10. FYI: GTK/Win32 => pygtk/Win32 ???

11. Tk8.0p2 Visual C++ build __WIN32__ vs _WIN32 vs WIN32 macros?

12. Smalltalk V\Win32 problems

 

 
Powered by phpBB® Forum Software