Skip to main content
guest
Join
|
Help
|
Sign In
Liberty BASIC Programmer's Encyc
Home
guest
|
Join
|
Help
|
Sign In
Wiki Home
Recent Changes
Pages and Files
Members
Home
General Tutorials
Advanced Tutorials
GUI Programming
Graphics and Games
Strings and Text
Numbers and Math
Using Files
Windows API
Communications
Programmer's Tools
Articles by Date
FAQs
Rosetta Code
General Articles
Newsletters Contents
Table of Contents
Demos
Submit Articles
TOS and License
ABCs of APIs 10
Edit
3
…
2
Tags
advanced
api
edit
Save
Cancel
Notify
RSS
Backlinks
Source
Print
Export (PDF)
<strong>The ABCs of APIs Lesson 10</strong><br /> Using Winstring with Pointers to Text<br /> <img id="wikitext@@toc@@normal" class="WikiMedia WikiMediaToc" title="Table of Contents" src="/site/embedthumbnail/toc/normal?w=225&h=100"/><br /> In <a class="wiki_link" href="/ABCs%20of%20APIs%205">Lesson 5 </a> we discussed the use of a string variable as a buffer sent to an API function. The function filled the buffer with text, which we were able to retrieve and use. Some API functions create the string in memory and return a pointer to the memory location. We retrieve the text from that location with <strong>Winstring()</strong><br /> <br /> <h2>Winstring()</h2> Winstring() retrieves a string of text returned from an API function. It can be in the form of a pointer to a memory location or a handle to a data object.<br /> <br /> In the following snippet, ptrText is a pointer to a memory location that contains a string of text. <br /> <br /> <pre class="lb">t$ = winstring(ptrText)<br/>print "Text is ";t$</pre> <br /> In the following snippet, hText is a handle to a data object in memory that contains a string of text. <br /> <br /> <pre class="lb">t$ = winstring(hText)<br/>print "Text is ";t$</pre> <br /> The following snippet demonstrates that winstring() can be used with struct members of type <strong>ptr</strong>. The type "PTR" is a pointer.<br /> <br /> <pre class="lb">struct Test, var$ as ptr<br/>Test.var$.struct="Hello, World!"<br/>print winstring(Test.var$.struct)</pre> <br /> <h2>Demo</h2> The following small program opens the clipboard and checks for text data. If there is text data on the clipboard, it uses winstring() to retrieve the data from the handle to the text object that is returned by the function.<br /> <br /> <pre class="lb">'A handle to the window to be associated with the open clipboard.<br/>'If this parameter is NULL, the open clipboard is associated with the current task.<br/>hTask = _NULL<br/><br/>calldll #user32, "OpenClipboard",_<br/> hTask as ulong,_ 'handle to window or null for current task<br/> result as long 'nonzero=success<br/><br/>calldll #user32, "GetClipboardData",_<br/> _CF_TEXT as long,_ 'clipboard format for text data<br/> hText as long 'handle to data object<br/><br/>if hText<>0 then<br/> print "Text on clipboard is:"<br/> 'retrieve text at this address:<br/> t$ = winstring(hText)<br/> print t$<br/>else<br/> print "No text data on clipboard."<br/>end if<br/><br/>calldll #user32, "CloseClipboard", result as void</pre> <br /> <br /> <br /> Written by Alyce Watson. For more on APIs, see:<br /> <a class="wiki_link_ext" href="http://www.lulu.com/content/611431" rel="nofollow">APIs for Liberty BASIC</a>
Javascript Required
You need to enable Javascript in your browser to edit pages.
help on how to format text
Turn off "Getting Started"
Home
...
Loading...