Calling API Functions 
Author Message
 Calling API Functions

What is the proper way to call the "GetComputerName" api function from
Access 7.0?



Fri, 08 Oct 1999 03:00:00 GMT  
 Calling API Functions

Chuck,

Declare the API as....
 Declare Function GetComputerName Lib "Kernel32" Alias _
      "GetComputerNameA" (ByVal strBuffer As String, lngSize As Long) As
Long

Then a function, like the one below, would return the computer name...

Function ReturnName() As String
 Dim strName As String
 Dim lngRtn As Long

' strName will have the computer name after the API call
   strName = String$(255, 0)
   lngRtn = GetComputerName(strName, 255)
   ReturnName = strName
End Function

  Good Luck,
     Phil Singer



Quote:
> What is the proper way to call the "GetComputerName" api function from
> Access 7.0?



Sat, 09 Oct 1999 03:00:00 GMT  
 Calling API Functions


Quote:
> Function ReturnName() As String
>  Dim strName As String
>  Dim lngRtn As Long

> ' strName will have the computer name after the API call
>    strName = String$(255, 0)
>    lngRtn = GetComputerName(strName, 255)
>    ReturnName = strName
> End Function

Almost, but this will leave trailing junk in strName.  You need to use:

  ReturnName = Left$(strName, lngRtn)

in order to trim off the extra crud. -- Ken



Sat, 09 Oct 1999 03:00:00 GMT  
 Calling API Functions

Also remember that it returns a lpsz which is a zero-terminated string.
And that if you declare the string as.

        String(255,32)

Then you can use the trim$ function also.
--
_________
CEO DigiTec Web Consultants
Justin Rogers
Personal Programmer and Web Consultant  Home Page:      Soon to come



Quote:

> > Function ReturnName() As String
> >  Dim strName As String
> >  Dim lngRtn As Long

> > ' strName will have the computer name after the API call
> >    strName = String$(255, 0)
> >    lngRtn = GetComputerName(strName, 255)
> >    ReturnName = strName
> > End Function

> Almost, but this will leave trailing junk in strName.  You need to use:

>   ReturnName = Left$(strName, lngRtn)

> in order to trim off the extra crud. -- Ken



Thu, 14 Oct 1999 03:00:00 GMT  
 Calling API Functions


Quote:
> And that if you declare the string as.

>    String(255,32)

> Then you can use the trim$ function also.

That'll leave the trailing null on there.  There's no point to this --
the API function returns the length of the string it returned as its
return value -- using that to truncate the string is the right solution,
as far as I can tell. -- Ken


Sat, 16 Oct 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Calling API functions in DLLs from VB3

2. Calling API function GetTextMetrics

3. Call API Function from within script

4. Problem calling API function

5. Calling API function from within VB6 !!!

6. problems of calling API function.

7. Calling API functions from within Visual Basic 6

8. Dynamically calling API function using VB

9. Calling API functions from VC++ program

10. Can you call API functions on a remote computer?

11. VB4 & NT4, can't call API functions in Kernel !

12. Calling Windows API functions with string parameters from Access

 

 
Powered by phpBB® Forum Software