Using Win32 functions in Visual FoxPro Image Gallery
Unicode and Character Set
..msdn
MultiByteToWideChar
WideCharToMultiByte
Code examples:
Converting Unicode data from the Clipboard to a character string using a given code page
Creating a unique filename based on existing filename
Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)
Creating a unique filename based on existing filename

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
 
#DEFINE CP_ACP         0
#DEFINE CP_OEMCP       1
#DEFINE MB_PRECOMPOSED 1
#DEFINE MAX_PATH       260
DO decl
 
LOCAL cPath, cFile, cUnique, cTpl
 
* retrieving FoxPro executable name
cPath = Repli(Chr(0),MAX_PATH)
= GetModuleFileName(0, @cPath, Len(cPath))
cPath = SUBSTR(cPath, 1, AT(Chr(0),cPath)-1)
cFile = SUBSTR(cPath, RAT("\",cPath)+1)
? "Base name:", cPath
 
cUnique = Repli(Chr(0),MAX_PATH*2)
= PathYetAnotherMakeUniqueName(@cUnique, a2u(cPath), Null, a2u(cFile))
cUnique = u2a(cUnique)
? "Unique filename:", cUnique
?
 
cUnique = Repli(Chr(0),MAX_PATH*2)
cTpl = "MyFile.Dat"
cPath = GetLongTempPath()
? "Base name:", cPath + cTpl
 
= PathMakeUniqueName(@cUnique, MAX_PATH, a2u(cTpl), a2u(cTpl), a2u(cPath))
cUnique = u2a(cUnique)
? "Unique filename:", cUnique
* end of main
 
FUNCTION GetLongTempPath
    LOCAL cPath, cLongPath, nBufsize
    cPath = Repli(Chr(0),MAX_PATH)
    cLongPath = Repli(Chr(0),MAX_PATH*2)
    nBufsize = GetTempPath(Len(cPath), @cPath)
    cPath = LEFT(cPath, nBufsize)
    = GetLongPathName(cPath, @cLongPath, Len(cLongPath))
RETURN SUBSTR(cLongPath, 1,AT(Chr(0),cLongPath)-1)
 
FUNCTION u2a(cText)
* converting a Unicode string to an ANSI string
    LOCAL lcBuffer, lnBufsize
    cText = SUBSTR(cText, 1, AT(Chr(0)+Chr(0),cText))
 
    * first calling to define required buffer size
    lcBuffer = ""
    lnBufsize = WideCharToMultiByte(CP_ACP, 0,;
        cText, Len(cText), @lcBuffer, 0, Chr(0), 0)
 
    lcBuffer = Repli(Chr(0), lnBufsize)
    = WideCharToMultiByte(CP_ACP, 0,;
        cText, Len(cText), @lcBuffer, lnBufsize, Chr(0), 0)
RETURN SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
 
FUNCTION a2u(cText)
* converting an ANSI string to a Unicode string
    LOCAL lcBuffer, lnBufsize
 
    * first calling to define required buffer size
    lcBuffer = ""
    lnBufsize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,;
        cText, Len(cText), @lcBuffer, 0)
 
    lcBuffer = Repli(Chr(0), lnBufsize*2)  && in wide chars
    = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,;
        cText, Len(cText), @lcBuffer, lnBufsize)
RETURN lcBuffer
 
PROCEDURE decl
    DECLARE INTEGER PathMakeUniqueName IN shell32;
        STRING @pszUniqueName, INTEGER cchMax, STRING pszTemplate,;
        STRING pszLongPlate, STRING pszDir
 
    DECLARE INTEGER PathYetAnotherMakeUniqueName IN shell32;
        STRING @pszUniqueName, STRING pszPath,;
        STRING pszShort, STRING pszFileSpec
 
    DECLARE INTEGER GetTempPath IN kernel32;
        INTEGER nBufferLength, STRING @lpBuffer
 
    DECLARE INTEGER GetLongPathName IN kernel32;
        STRING lpszShortPath, STRING @lpszLongPath,;
        INTEGER cchBuffer
 
    DECLARE INTEGER GetModuleFileName IN kernel32; 
        INTEGER hModule, STRING @lpFilename, INTEGER nSize
 
    DECLARE INTEGER WideCharToMultiByte IN kernel32;
        INTEGER CodePg, INTEGER dwFlags,;
        STRING lpWideCharStr, INTEGER cchWideChar,;
        STRING @lpMultiByteStr, INTEGER cbMultiByte,;
        STRING lpDefaultChar, INTEGER lpUsedDefaultChar
 
    DECLARE INTEGER MultiByteToWideChar IN kernel32;
        INTEGER CodePage, LONG dwFlags, STRING lpMultiByteStr,;
        INTEGER cbMultiByte, STRING @lpWCharStr, INTEGER cchWChar
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3092 bytes  
Created: 2001-07-12 12:00:00  
Modified: 2005-12-12 11:26:21  
Visits in 7 days: 59  
Listed functions:
GetLongPathName
GetModuleFileName
GetTempPath
MultiByteToWideChar
PathMakeUniqueName
PathYetAnotherMakeUniqueName
WideCharToMultiByte
Printer friendly API declarations
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 (184.72.184.104)
3 sec.Example: 'Placing On-screen Alert on top of all windows'
2.15 hrs.Article: 'Passing parameters to Win32 functions '
 Function: 'GetThreadPriority'
4.17 hrs.Example: 'A client for testing non-blocking Winsock server'
 Example: 'Displaying Windows shell folders in TreeView control with Visual FoxPro FLL'
12.17 hrs.Example: 'Setting and retrieving the double-click time for the mouse'
22.59 hrs.Function: 'GetIpAddrTable'
1 day(s)Example: 'How to upload a local file to FTP server using FtpPutFile'
 Example: 'Browsing Windows Known Folders (Special Folders)'
Google
Advertise here!