Send to Printer

st4u

ST 4U 240: Making External API Calls

June 1, 2012 11:01:28.736

Today's Smalltalk 4 You looks at making external API calls using VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

External Calls.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll take a look at how to make external API calls from VA Smalltalk. IN this example, we'll call the MessageBoxA API in Windows:

C API

The code looks like this:


| pf |
pf := PlatformFunction fromArray: #('C' 'MessageBoxA' nil 'user32.dll' #(#uint32 #pointer #pointer #uint32) #int32).
pf 
   callWith: PlatformGlobals::HwndNull 
   with: 'this is some text' asPSZ 
   with: 'this is a caption' asPSZ 
   with: PlatformConstants::MbYesno

To understand what's going on in the ByteArray of arguments, have a look at class PlatformFunction:

PlatformFunction

Bear in mind that this example is a bit artificial; the class CwPrompter exists in VA< and uses this API already. However, it does give you a simple example of making an API call, and you can follow the same pattern for your own work.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u240-iPhone.m4v ( Size: 3344361 )]

posted by James Robertson

 Share Tweet This