Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Retrieving list of all active RAS connections
Retrieving the name and type of all available RAS-capable devices
Storing the environment strings in cursor
Winsock: retrieving the standard host name and IP address for the local machine
Drawing standard Windows icons
Enumerating print processors and supporting data types installed on the specified server
Obtaining I/O counts for the current process
Obtaining Shell32.dll version
Pocket PC: Folder Viewer
Reading header information from AVI file
Retrieving information about MS-DOS device names using QueryDosDevice (WinNT only)
Tracking mouse movement to detect when to start dragging
Using FtpCommand
Using the DrawText function
Using the MessageBox Win32 function
Creating a directory on the FTP
Disk in drive A:
GDI+: enumerating fonts installed on the system
How to view system icons for the classes installed on the local machine
Reading VFP settings from the Windows Registry
Using GetNearestColor
Wininet last error description
Comparing dimensions of the VFP main window with _SCREEN properties
Enumerating ODBC Data Sources available on the local computer
Adding supplementary data to AVI files

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:
The code below shows how to add a string to AVI file. The string may contain, for example, a copyright information, comments etc. AVI or MMIO functions can be used later on to read the string.

The code sample is simplified, intended to be only a blue-print. So use it on those AVI files you have copies of.
 
cFile = "findcomp.avi"
? AddInfo_AVI(cFile, "AUTH", SYS(0))
* end of main
 
PROCEDURE AddInfo_AVI(cAviFile, cChunkId, cValue)
#DEFINE OF_SHARE_DENY_WRITE 0x00000020
#DEFINE OF_READWRITE 0x00000002
 
    DO declare2
    = AVIFileInit()
 
    LOCAL hFile, nResult, nChunkId
    IF AVIFileOpen(@hFile, cFile,;
        BITOR(OF_SHARE_DENY_WRITE, OF_READWRITE), 0) <> 0
        RETURN .F.
    ENDIF
 
    nChunkId = buf2dword(PADR(cChunkId,4,CHR(0)))
    nResult = AVIFileWriteData(hFile, nChunkId,;
        @cValue, LEN(cValue))
 
    = AVIFileRelease(hFile)
    = AVIFileExit()
RETURN (nResult=0)
 
PROCEDURE AddInfo_RIFF(cAviFile, cChunkId, cValue)
#DEFINE MMIO_READWRITE  2
#DEFINE MMIO_ALLOCBUF   0x00010000
#DEFINE MMIO_FINDRIFF   0x0020
#DEFINE MMSYSERR_NOERROR 0
 
    DO declare1
 
    LOCAL hFile, cMMIOInfo, cRiffInfo,;
        cChunkInfo, lResult
 
    cMMIOInfo = Repli(Chr(0), 64)
    hFile = mmioOpen(cAviFile, @cMMIOInfo,;
        MMIO_READWRITE+MMIO_ALLOCBUF)
 
    IF hFile <= 0
        RETURN .F.
    ENDIF
 
    cRiffInfo = Repli(Chr(0), 20)
    = mmioDescend(hFile, @cRiffInfo, Null, MMIO_FINDRIFF)
    = mmioAscend(hFile, @cRiffInfo, 0)
 
    cChunkInfo = PADR(PADR(cChunkId,4,CHR(0)) +;
        num2dword(LEN(m.cValue)), 20)
 
    IF mmioCreateChunk(hFile, @cChunkInfo, 0)=0;
        And mmioWrite(hFile, cValue, Len(cValue))=0
        = mmioAscend(hFile, @cChunkInfo, 0)
        lResult=.T.
    ENDIF
 
    = mmioFlush(hFile, 0)
    = mmioClose(hFile, 0)
RETURN m.lResult
 
PROCEDURE declare1
    DECLARE INTEGER mmioClose IN winmm INTEGER hmmio, INTEGER wFlags
    DECLARE INTEGER mmioFlush IN winmm INTEGER hmmio, INTEGER fuFlush
 
    DECLARE INTEGER mmioOpen IN winmm;
        STRING szFilename, STRING @lpmmioinfo, INTEGER dwOpenFlags
 
    DECLARE INTEGER mmioAscend IN winmm;
        INTEGER hmmio, STRING @lpck, INTEGER wFlags
 
    DECLARE INTEGER mmioDescend IN winmm;
        INTEGER hmmio, STRING @lpck,;
        STRING @lpckParent, INTEGER wFlags
 
    DECLARE LONG mmioWrite IN winmm;
        INTEGER hmmio, STRING pch, LONG cch
 
    DECLARE INTEGER mmioCreateChunk IN winmm;
        INTEGER hmmio, STRING @lpck, INTEGER wFlags
 
PROCEDURE declare2
    DECLARE AVIFileInit IN avifil32
    DECLARE AVIFileExit IN avifil32
    DECLARE INTEGER AVIFileRelease IN avifil32 INTEGER pfile  
 
    DECLARE INTEGER AVIFileOpen IN avifil32;
        INTEGER @ppfile, STRING szFile,;
        INTEGER mode, INTEGER pclsidHandler
 
    DECLARE INTEGER AVIFileWriteData IN avifil32;
        INTEGER pfile, LONG ckid,;
        STRING @lpData, LONG cbData
 
FUNCTION num2dword(lnValue)
#DEFINE m0  256
#DEFINE m1  65536
#DEFINE m2  16777216
    IF lnValue < 0
        lnValue = 0x100000000 + lnValue
    ENDIF
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
 
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2964 bytes  
Created: 2005-03-01 17:39:33  
Modified: 2009-02-03 15:26:42  
Visits in 7 days: 83  
Listed functions:
AVIFileExit
AVIFileInit
AVIFileOpen
AVIFileRelease
AVIFileWriteData
mmioAscend
mmioClose
mmioCreateChunk
mmioDescend
mmioFlush
mmioOpen
mmioWrite
Printer friendly API declarations
My comment:
AVI formats support adding supplementary data (other than normal header, format, and stream data) to AVI files.

The Microsoft AVI file format is a RIFF file specification, so any supplementary data can be added in the chunk format. A chunk consists from ID (4 bytes), data size (4 bytes) and the data itself (up to 0xffffffff bytes).

Here is an example of chunk with supplementary data:
CPRT*000Copyright (c) 2001-2005. Such-n-such, Inc.

Where CRPT is 4-byte ID. *000 is the binary presentation (DWORD) of number 42, which is the length of the data. And Copyright (c) 2001-2005. Such-n-such, Inc. is the data.

In less sophisticated way, FoxPro low-level file functions most liekly can be used to open AVI file and attach some data to the end of it.

If you prefer playing by rules, use either AVI or MMIO API functions. Two procedures in the code above present both ways. Well, neither AVIFileWriteData nor mmioCreateChunk works smart enough.

The AddInfo_AVI adds new chunk to the AVI file regardless of whether a chunk with this ID already exists. If you decide to read the supplementary information using the AVIFileReadData, it will read only the first chunk found.

The AddInfo_RIFF always adds a chunk immediately after the main part of the file. Although, you may modify the code, making it search through existing chunks. In my opinion, MMIO functions have much greater flexibility. With them you can build a real routine for adding, reading and modifying supplementary data in AVI files.
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 (23.22.100.67)
26.38 min.Example: 'How to hot-track menu item selection in top-level form (requires VFP9)'
26.45 min.Example: 'Setting the mouse capture to the specified window'
2.51 hrs.Function: 'ClosePrinter'
Function group: 'Printing and Print Spooler'
2.52 hrs.Example: 'How to enumerate terminal servers within the specified Windows domain'
 Function: 'WinHttpSendRequest'
Google
Advertise here!