Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Retrieving configuration information for the specified server (Win98/Me)
Retrieving IP statistics for the computer
Enumerating connections made to a shared resource for the local computer (WinNT only)
Open and close a Simple MAPI Session
Retrieveing information about the active window (even if it is not owned by the calling process)
PocketPC: creating directories and files
Current directory of the application
How to display a Task Dialog (Vista)
How to retrieve the number of objects stored in the Recycle Bin
Obtaining provider name for a specific type of network
Retrieving list of all active RAS connections
Creating a file, then moving it to another destination
Retrieving various system metrics
Using GetCompressedFileSize (WinNT only)
Winsock: how to retrieve a service information corresponding to a port
Enumerating MIDI output devices
Setting the Window Region for a form
Who is the first in viewing the Clipboard
Printf-style formatted text output in VFP
Who owns the Windows Clipboard
Winsock: retrieving information about available transport protocols
How to display the port-configuration dialog box for a port on the specified server
Using custom Simple MapiSendMail class
How to retrieve list of system DSNs (Data Source Name) with parameters
Retrieving configuration information for the specified server (Win98/Me)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
DO decl


#DEFINE CNLEN         15
#DEFINE NERR_Success   0

*| struct _server_info_1 {
*|   char             sv1_name[CNLEN + 1];  0:16
*|   unsigned char    sv1_version_major;   16:2
*|   unsigned char    sv1_version_minor;   18:2
*|   unsigned long    sv1_type;            20:4
*|   char FAR *       sv1_comment;         24:4
*| }; total bytes = 28

*| struct _server_info_50 {
*|   char             sv50_name[CNLEN + 1];  0:16
*|   unsigned char    sv50_version_major;   16:2
*|   unsigned char    sv50_version_minor;   18:2
*|   unsigned long    sv50_type;            20:4
*|   char FAR *       sv50_comment;         24:4
*|   unsigned short   sv50_security;        28:2
*|   unsigned short   sv50_auditing;        30:2
*|   char FAR *       sv50_container;       32:4
*|   char FAR *       sv50_ab_server;       36:4
*|   char FAR *       sv50_ab_dll;          40:4
*| }; total bytes = 44; should be 46?

LOCAL lcBuffer, lnBufsize, lnInfLevel, lcServerName, lnServerType, lnPtr
lnBufsize = 64  && large enough to fit
lcBuffer = Repli(Chr(0), lnBufsize)
lnInfLevel = 50  && 1 and 50 - valid inf levels for Win9*/Me

* quering local computer, otherwise it should be like \\MYSERVER
lcServerName = .Null.

lnResult = NetServerGetInfo (lcServerName, 50, @lcBuffer,;
    lnBufsize, @lnBufsize)

IF lnResult <> NERR_Success
    * 234 = More data is available
    * 2123 = ?
    ? "Error code:", lnResult

? "Server name:", STRTRAN(SUBSTR(lcBuffer, 1,16), Chr(0),"")
? "Major version number:", buf2word(SUBSTR(lcBuffer, 17,2))
? "Minor version number:", buf2word(SUBSTR(lcBuffer, 19,2))

lnServerType = buf2dword(SUBSTR(lcBuffer, 21,4))
? "Networking software type:", lnServerType, GetServerType(lnServerType)

lnPtr = buf2dword(SUBSTR(lcBuffer, 25,4))
? "Server description:", Iif(lnPtr <> 0, mem2str(lnPtr), "")

? "Security type:", buf2word(SUBSTR(lcBuffer, 29,2))
? "Auditing type:", buf2word(SUBSTR(lcBuffer, 31,2))

lnPtr = buf2dword(SUBSTR(lcBuffer, 33,4))
? "Security server:", Iif(lnPtr <> 0, mem2str(lnPtr), "")

lnPtr = buf2dword(SUBSTR(lcBuffer, 37,4))
? "Address domain:", Iif(lnPtr <> 0, mem2str(lnPtr), "")

lnPtr = buf2dword(SUBSTR(lcBuffer, 41,4))
? "Address book service:", Iif(lnPtr <> 0, mem2str(lnPtr), "")

FUNCTION  mem2str(lnMemBlock)
    LOCAL lnPtr, lcResult, lcBuffer, lnPos
    lnPtr = lnMemBlock
    lcResult = ""

    DO WHILE .T.
        lcBuffer = EMPTY_BUFFER
        = Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE)
        lnPos = AT(Chr(0), lcBuffer)

        IF lnPos > 0
            lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1)
            RETURN  lcResult
            lcResult = lcResult + lcBuffer
            lnPtr = lnPtr + BUFFER_SIZE

FUNCTION  GetServerType (lnType)
RETURN  Iif (BitAnd(lnType, SV_TYPE_WORKSTATION)<>0,   "Wkstation;","") +;
        Iif (BitAnd(lnType, SV_TYPE_SERVER)<>0,        "Server;","") +;
        Iif (BitAnd(lnType, SV_TYPE_SQLSERVER)<>0,     "SQL Server;","") +;
        Iif (BitAnd(lnType, SV_TYPE_DOMAIN_CTRL)<>0,   "PDC;","") +;
        Iif (BitAnd(lnType, SV_TYPE_PRINTQ_SERVER)<>0, "Print;","") +;
        Iif (BitAnd(lnType, SV_TYPE_SERVER_UNIX)<>0,   "Unix;","") +;
        Iif (BitAnd(lnType, SV_TYPE_SERVER_NT)<>0,     "WinNT;","") +;
        Iif (BitAnd(lnType, SV_TYPE_DOMAIN_MASTER)<>0, "Master;","") +;
        Iif (BitAnd(lnType, SV_TYPE_WINDOWS)<>0,       "Windows;","")

FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) +;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216

FUNCTION  buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) +;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256

    DECLARE INTEGER NetServerGetInfo IN svrapi;
        STRING pszServer, INTEGER sLevel,;
        STRING @pbBuffer, SHORT cbBuffer, SHORT @pcbTotalAvail

    DECLARE RtlMoveMemory IN kernel32 As Heap2Str;

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
4299 bytes  
Created: 2002-02-11 20:13:11  
Modified: 2005-12-27 10:52:08  
Visits in 7 days: 74  
Listed functions:
Printer friendly API declarations
My comment:
A declaration for the NetServerGetInfo is different in WinNT and Win98/Me. For the latter the caller must allocate and deallocate the receiving buffer. Also information levels available are different in both cases. And the least one is different DLLs.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.

Copyright 2001-2018 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (
5 sec.Function: 'DrawText'
Function group: 'Font and Text'
8 sec.Function: 'CeGetVersionEx'
Function group: 'Remote Application Programming (RAPI)'
11 sec.Function: 'SCardListInterfaces'
Function group: 'Authentication'
14 sec.Function: 'GdipGetPropertyItemSize'
Function group: 'GDI+ Image'
17 sec.Function: 'waveInOpen'
Function group: 'Windows Multimedia'
20 sec.Function: 'NetScheduleJobDel'
Function group: 'Network Management'
24 sec.Function: 'CharToOem'
Function group: 'String'
26 sec.Links
28 sec.
32 sec.Function: 'SQLAllocEnv'
Function group: 'ODBC API'
Advertise here!