Declare
From REALbasicWiki
Declare statements in REALbasic permit you to call functions defined in external libraries like DLL's on Windows, .so shared libraries on Linux and dylib's on OS X.
There are two varieties of declares. There are "hard" declares and "soft" declares. The difference between the two is how a compiled REALbasic program starts up. With a hard declare the referenced library must be present and accessible when the program starts. With a soft declare it must be available when the function is called. The actual reference to the function is not checked as soon as the program starts.
[edit] Syntax
[soft] declare (sub|function) lib "libraryName" [alias "aliasName"] (parameters) [as returnType]
A declare must be either s SUB or a FUNCTION. A SUB does not return any results. A function does, and so must have a return type.
If the library function you're declaring into has the same name as an RB method you can use the aliasName to rename the library function and call it in an unambiguous way.
On OS X you can use a path like @executable_path/../../../SampleDylib.dylib as the location of the library if it's located inside a program bundle.
[edit] See Also
- To interface Mac OS X's Objective C-based frameworks, see the Cocoa chapter of the I Declare book by Charles Yeomans
