Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
Obtaining names and positions for shortcuts located on the Windows Desktop
GDI+: Implementing image scrolling with inertia
How to change display settings: screen resolution, screen refresh rate
Browsing Windows Known Folders (Special Folders)
How to control Adobe Reader 9.0 (SDI mode) from VFP application
Splash Screen for the VFP application
How to make a VFP form fading out when released (GDI version)
Creating a console window for Visual FoxPro application
Vertical Label control
Displaying dimmed window behind VFP top-level form
How to print a bitmap file
How to put a horizontal text scrolling on the form (a news line, marquee)
Enumerating devices installed on the local machine
Storing content of the Clipboard to a bitmap file
Detecting changes in connections to removable drives (VFP9)
Displaying icons in the system tray (VFP9)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to put a vertical text scrolling on the form (a movie cast)
How to create MD-5 and SHA-1 hash values from a string
Storing screen shot of a form to bitmap file
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Windows Shell Icons displayed and exported to ICO files (Vista)
How to perform Base64 encoding/decoding using Cryptography API Functions

User rating: 10/10 (4 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
#DEFINE CRYPT_STRING_BASE64 0x0001
#DEFINE CRYPT_STRING_NOCRLF 0x40000000
#DEFINE CRYPT_STRING_NOCR 0x80000000

DO declare
SET MEMOWIDTH TO 120

LOCAL cBuffer, cEncoded, cDecoded

TEXT TO cBuffer NOSHOW
Base cryptographic functions provide the most flexible means 
of developing cryptography applications. All communication 
with a cryptographic service provider (CSP) occurs through 
these functions.

A CSP is an independent module that performs all cryptographic 
operations. At least one CSP is required with each application 
that uses cryptographic functions. A single application can 
occasionally use more than one CSP.
ENDTEXT

cEncoded = ToBase64(m.cBuffer)
? cEncoded

cDecoded = FromBase64(cEncoded)
? cDecoded

* end of main

FUNCTION ToBase64(cSrc)
    LOCAL nFlags, nBufsize, cDst
    nFlags=CRYPT_STRING_BASE64

    nBufsize=0
    = CryptBinaryToString(@cSrc, LEN(cSrc),;
        m.nFlags, NULL, @nBufsize)

    cDst = REPLICATE(CHR(0), m.nBufsize)
    IF CryptBinaryToString(@cSrc, LEN(cSrc), m.nFlags,;
        @cDst, @nBufsize) = 0
        RETURN ""
    ENDIF
RETURN cDst

FUNCTION FromBase64(cSrc)
    LOCAL nFlags, nBufsize, cDst
    nFlags=CRYPT_STRING_BASE64

    nBufsize=0
    = CryptStringToBinary(@cSrc, LEN(m.cSrc),;
        nFlags, NULL, @nBufsize, 0,0)

    cDst = REPLICATE(CHR(0), m.nBufsize)
    IF CryptStringToBinary(@cSrc, LEN(m.cSrc),;
        nFlags, @cDst, @nBufsize, 0,0) = 0
        RETURN ""
    ENDIF
RETURN m.cDst

PROCEDURE declare
    DECLARE INTEGER CryptBinaryToString IN Crypt32;
        STRING @pbBinary, LONG cbBinary, LONG dwFlags,;
        STRING @pszString, LONG @pcchString

    DECLARE INTEGER CryptStringToBinary IN crypt32;
        STRING @pszString, LONG cchString, LONG dwFlags,;
        STRING @pbBinary, LONG @pcbBinary,;
        LONG pdwSkip, LONG pdwFlags

User rating: 10/10 (4 votes)
Rate this code sample:
  • ~
1772 bytes  
Created: 2001-08-03 12:00:00  
Modified: 2015-10-28 09:29:17  
Visits in 7 days: 38  
Listed functions:
CryptBinaryToString
CryptStringToBinary
Printer friendly API declarations
My comment:
Starting VFP8, base64 conversion can be performed with STRCONV().

In my tests, API routines presented on this page encoded and decoded strings approximately 2 times faster than STRCONV() did -- on 100K cycles 3.7 seconds vs. 7.7 seconds.

* * *
This is an output from call to CryptBinaryToString with dwFlags set to CRYPT_STRING_HEXASCIIADDR (0x000b). Can make a good starting point for developing a simple binary viewer.


* * *
From Burkhard Stiller`s VFP Blog:
Another way to encode and store picture-data inside your classes -- relates to base64 encoding, and is an interesting sample of code by itself.
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-2017 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.36), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.159.120.168)
7 sec.Function: 'GetMonitorContrast'
15 sec.Function: 'GetInterfaceInfo'
Function group: 'IP Helper'
21 sec.Example: 'Retrieving information specific to the current Time Zone'
29 sec.Function: 'NetWkstaUserEnum'
Function group: 'Network Management'
37 sec.Function: 'SHGetSpecialFolderLocation'
Function group: 'Shell Functions'
45 sec.Function: 'InternetCrackUrl'
Function group: 'Internet Functions (WinInet)'
52 sec.Function: 'mmioWrite'
Function group: 'Windows Multimedia'
1 min.Example: 'Reading and setting explicit Application User Model ID for the current process (Win7)'
1.12 min.Function: 'NetShareAdd'
Function group: 'Network Management'
1.27 min.Function: 'NetServerGetInfo'
Function group: 'Network Management'
Google
Advertise here!