Using Win32 functions in Visual FoxPro Image Gallery
File Management
..msdn
CopyFile
CopyFileTransacted
CreateDirectory
CreateFile
CreateFileTransacted
CreateHardLink
CreateSymbolicLink
DeleteFile
DeleteFileTransacted
FindClose
FindCloseChangeNotification
FindFirstChangeNotification
FindFirstFile
FindNextChangeNotification
FindNextFile
FlushFileBuffers
GetBinaryType
GetCurrentDirectory
GetDriveType
GetFileAttributes
GetFileAttributesEx
GetFileInformationByHandle
GetFileType
GetFullPathName
GetLongPathName
GetShortPathName
GetTempFileName
GetTempPath
LockFile
MoveFile
MoveFileTransacted
OpenFile
QueryDosDevice
ReadDirectoryChangesW
ReadFile
RemoveDirectory
RemoveDirectoryTransacted
ReplaceFile
SearchPath
SetCurrentDirectory
SetEndOfFile
SetFileAttributes
SetFilePointer
SetFilePointerEx
SetSearchPathMode
UnlockFile
WriteFile
_lclose
_lopen
Code examples:
Creating a file, then moving it to another destination
How to convert a bitmap file to monochrome format (1 bpp)
How to set Creation Date/Time for a folder (WinNT)
HOWTO: Use the Win32 API to Access File Dates and Times
Monitoring changes occurring within a directory
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Peer-to-peer LAN messenger built with Mailslot API functions
Storing content of the Clipboard to a bitmap file
Storing screen shot of a form to bitmap file
Subclassing CommandButton control to create BackColor property
Testing serial ports
Using InternetSetFilePointer when resuming interrupted download from the Internet
Using mailslots to send messages on the network
Using named pipes for interprocess communication
Using the CreateFile
Using the DeleteFile
Vertical Label control
Testing serial ports

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
Before you begin:
Another example: Enumerating the ports that are available for printing on a specified server
 
DO decl
 
LOCAL nIndex, cPort
FOR nIndex=1 TO 8
    cPort = "COM" + TRANSFORM(nIndex)
    ? "Testing port " + m.cPort + ":", TestPort(m.cPort)
ENDFOR
* end of main
 
FUNCTION TestPort(cPort)
#DEFINE FILE_SHARE_READ   1
#DEFINE FILE_SHARE_WRITE  2
#DEFINE OPEN_EXISTING     3
#DEFINE GENERIC_READ      0x80000000
#DEFINE GENERIC_WRITE     0x40000000
#DEFINE FILE_FLAG_OVERLAPPED 0x40000000
#DEFINE INVALID_HANDLE_VALUE -1
#DEFINE FILE_ATTRIBUTE_NORMAL 128
 
    LOCAL hPort, lnErr
 
*    hPort = CreateFile(cPort, GENERIC_READ, 0,0,;
        OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0)
 
    hPort = CreateFile(cPort,;
        BITOR(GENERIC_READ,GENERIC_WRITE),;
        0,0, OPEN_EXISTING,;
        BITOR(FILE_FLAG_OVERLAPPED,FILE_ATTRIBUTE_NORMAL), 0)
 
    IF hPort = INVALID_HANDLE_VALUE
        lnErr = GetLastError()
        RETURN "Error " + TRANSFORM(lnErr) +;
            ". " + GetErrorMessage(lnErr)
    ELSE
        = CloseHandle(hPort)
        RETURN "Ok"
    ENDIF
 
PROCEDURE decl
    DECLARE INTEGER CreateFile IN kernel32;
        STRING lpFileName, INTEGER dwAccess, INTEGER dwShareMode,;
        INTEGER lpSecurityAttr, INTEGER dwCreationDisp,;
        INTEGER dwFlagsAndAttr, INTEGER hTemplateFile
 
    DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
    DECLARE INTEGER GetLastError IN kernel32
 
    DECLARE INTEGER FormatMessage IN kernel32;
        INTEGER dwFlags, INTEGER lpSource, INTEGER dwMessageId,;
        INTEGER dwLanguageId, INTEGER @lpBuffer,;
        INTEGER nSize, INTEGER Arguments
 
    DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
        STRING @Destination, INTEGER Source, INTEGER nLength
 
FUNCTION GetErrorMessage(lnErr)
#DEFINE FORMAT_MESSAGE_ALLOCATE_BUFFER 256
#DEFINE FORMAT_MESSAGE_FROM_SYSTEM     4096
#DEFINE FORMAT_MESSAGE_IGNORE_INSERTS  512
 
    LOCAL dwFlags, lpBuffer, lnLength, lpResult
    dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER +;
        FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_IGNORE_INSERTS
 
    lpBuffer = 0
    lnLength = FormatMessage(dwFlags, 0, lnErr, 0, @lpBuffer, 0,0)
    IF lnLength <> 0
        lpResult = REPLI(Chr(0), 500)
        = CopyMemory (@lpResult, lpBuffer, lnLength)
        RETURN STRTRAN(LEFT(lpResult, lnLength), Chr(13)+Chr(10), "")
    ELSE
        RETURN "[]"
    ENDIF
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2151 bytes  
Created: 2002-05-06 20:14:58  
Modified: 2004-08-17 21:56:29  
Visits in 7 days: 157  
Listed functions:
CloseHandle
CopyMemory
CreateFile
FormatMessage
GetLastError
Printer friendly API declarations
My comment:
In Windows all input/output ports are presented as files, so work with ports is performed through file functions like CreateFile, CloseHandle, ReadFile, ReadFileEx, WriteFile and WriteFileEx.

Code sample Get the owner of an NTFS file works with serial ports as well as with regular files.

Check this MSDN article "Serial Communications in Win32".

Check VB example Using CreateFile to Determine Available COM Ports on VBNet.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 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.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.226.5.29)
7.77 hrs.Example: 'URL: splitting into its component parts'
 Function: 'GetFileSizeEx'
11.63 hrs.Gallery
11.64 hrs.Example: 'How to prevent users from accessing the Windows Desktop and from switching to other applications'
12.43 hrs.Function: 'FormatMessage'
Function group: 'Error Handling'
 
Function group: 'Kernel Transaction Manager'
 Example: 'How to convert a bitmap file to monochrome format (1 bpp)'
16.19 hrs.Function: 'InternetOpenUrl'
18.27 hrs.Example: 'Winsock: sending email messages (SMTP, port 25)'
 Solution: 'ContextMenu ActiveX Control'
Google
Advertise here!