Using Win32 functions in Visual FoxPro Image Gallery
Shell Lightweight Utility APIs -- string functions
..msdn
ChrCmpI
StrCpy
StrDup
wnsprintf
Code examples:
StrDup returns a pointer to the duplicate of a source VFP string
Using Common Controls: the Header Control
StrDup returns a pointer to the duplicate of a source VFP string

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
 
LOCAL lcSource, lcTarget, hMemory
lcSource = "Jack and Jill went up a hill"
hMemory = StrDup(lcSource)
 
IF hMemory <> 0
    ? "Pointer to a new string:", hMemory
 
    * copying from a pointer to a VFP string
    lcTarget = SPACE(250)
    = StrCpy (@lcTarget, hMemory)
    ? "Transferred string:", LEFT(lcTarget, AT(Chr(0), lcTarget)-1)
 
    * MSDN: The calling application must free this memory 
    * by calling the LocalFree function on the pointer 
    * returned by the call to StrDup. 
    = LocalFree (hMemory)
ELSE
* error
ENDIF
 
PROCEDURE  decl
    DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
    DECLARE INTEGER StrDup IN shlwapi STRING lpsz
    DECLARE INTEGER StrCpyW IN shlwapi AS StrCpy;
        STRING @psz1, INTEGER psz2
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
738 bytes  
Created: 2001-10-30 19:10:52  
Modified: 2001-11-02 18:55:49  
Visits in 7 days: 51  
Listed functions:
LocalFree
StrCpy
StrDup
Printer friendly API declarations
My comment:
For sure in many situations you can pass pointers to strings to external procedures just using STRING @.

But not when you need to fill a structure, which contains 4-byte pointers to strings. StrDup solves this problem easily, though you have an additional burden to free the allocated memory block.
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 (107.20.129.212)
3 sec.Example: 'How to create transparent areas inside a form -- punching holes in the form'
46.82 min.Example: 'How to generate GUID values'
4.59 hrs.Function: 'GdipDrawImageRectRectI'
Function group: 'GDI+ Graphics'
 Function: 'LsaFreeMemory'
Function group: 'Security'
4.93 hrs.Example: 'How to make a VFP form fading out when released (GDI+ version)'
 Function: 'CloseWindow'
6.04 hrs.Example: 'Winsock: retrieving the standard host name and IP address for the local machine'
 Example: 'The window and its ancestors'
7.66 hrs.Example: 'Testing serial ports'
11.63 hrs.Example: 'Using an Event Object. Part B: running an application responding to events'
Google
Advertise here!