Platforms to show: All Mac Windows Linux Cross-Platform

Back to SoftDeclareMBS class.

SoftDeclareMBS.CallFunction(param as string,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function.
Example
dim c as SoftDeclareMBS
dim m,p,b as memoryBlock
dim f as folderItem
dim path as string

f=ApplicationsFolderMBS(-32766) // get a folder...
path=f.NativePath

MsgBox path

b=newmemoryBlock(1024)
b.long(0)=0 // make empty C string

p=newmemoryBlock(lenb(path)+3)
p.cstring(0)=path

m=newmemoryBlock(12+10)
m.long(0)=p.AddressMBS(0)
m.long(4)=b.AddressMBS(0)
m.long(8)=1023

c=new SoftDeclareMBS
if c.LoadDLL("KERNEL32") then
if c.loadfunction("GetShortPathNameA") then
c.CallingMode=0
MsgBox "found function"
if c.CallFunction("iii",m) then
msgbox "Short path is: "+b.cstring(0)
else
msgbox "Failed to call function."
end if
else
msgbox "Loading of function "+c.FunctionName+" failed."
end if
else
msgbox "Loading of Kernel32 failed."
end if

The param string is a combination of the characters "i" for integer, "l" for 64bit integer, "f" for single (float) and "d" for double.
Use "i" for booleans, shorts and pointers.

the memoryblock must match exactly the parameters you specified.
Returns true on success.

See also:

SoftDeclareMBS.CallFunction(paramcount as Integer,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function.
Example
dim c as SoftDeclareMBS
dim m,p,b as memoryBlock
dim f as folderItem
dim path as string

f=ApplicationsFolderMBS(-32766) // get a folder...
path=f.NativePath

MsgBox path

b=newmemoryBlock(1024)
b.long(0)=0 // make empty C string

p=newmemoryBlock(lenb(path)+3)
p.cstring(0)=path

m=newmemoryBlock(12+10)
m.long(0)=p.AddressMBS(0)
m.long(4)=b.AddressMBS(0)
m.long(8)=1023

c=new SoftDeclareMBS
if c.LoadDLL("KERNEL32") then
if c.loadfunction("GetShortPathNameA") then
c.CallingMode=0
MsgBox "found function"
if c.CallFunction(3,m) then
msgbox "Short path is: "+b.cstring(0)
else
msgbox "Failed to call function."
end if
else
msgbox "Loading of function "+c.FunctionName+" failed."
end if
else
msgbox "Loading of Kernel32 failed."
end if

If paramtercount is 0, the memoryblock is ignored.
The size of the memoryblock must be minimum 4*paramcount.
Each parameter is set using m.long(n*4) where n=0 is the first parameter.
A parameter may be any integer value or an address of a memoryblock. The address can be read using memoryblock.addressMBS which is part of the plugin. You can even use only one memoryblock for all 3 parameters in the example like this:

m=newmemoryBlock(2100)
m.cstring(1024)=path
m.long(0)=m.address(20)
m.long(4)=m.address(1024)
m.long(8)=1024

First 12 bytes for the parameter table, the next 1000 bytes for the result buffer and finally a thousand bytes for the input string.

Before RB 3.1 this function was named "Call", but RB5 requires that the word "Call" is no longer valid for a function name.

Softdeclare is limited to only 6 parameters for plugin version 3.2. Plugin version 3.3 extends this to 8 parameters.

See also:

SoftDeclareMBS.CallFunctionDouble(param as string,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns a double value.

The param string is a combination of the characters "i" for integer, "l" for 64bit integer, "f" for single (float) and "d" for double.
Use "i" for booleans, shorts and pointers.

the memoryblock must match exactly the parameters you specified.
Returns true on success.

See also:

Some examples using this method:

SoftDeclareMBS.CallFunctionDouble(paramcount as Integer,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 3.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns a double value.

Fills the ResultDouble property.

If paramtercount is 0, the memoryblock is ignored.
The size of the memoryblock must be minimum 4*paramcount.
Each parameter is set using m.long(n*4) where n=0 is the first parameter.
A parameter may be any integer value or an address of a memoryblock. The address can be read using memoryblock.addressMBS which is part of the plugin.
Only 10 parameters can currently be used.

See also:

SoftDeclareMBS.CallFunctionInteger64(param as string,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns an integer value.

The param string is a combination of the characters "i" for integer, "l" for 64bit integer, "f" for single (float) and "d" for double.
Use "i" for booleans, shorts and pointers.

the memoryblock must match exactly the parameters you specified.
Returns true on success.

See also:

SoftDeclareMBS.CallFunctionInteger64(paramcount as Integer,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 3.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns an integer value.

Fills the ResultInt64 property.

If paramtercount is 0, the memoryblock is ignored.
The size of the memoryblock must be minimum 4*paramcount.
Each parameter is set using m.long(n*4) where n=0 is the first parameter.
A parameter may be any integer value or an address of a memoryblock. The address can be read using memoryblock.addressMBS which is part of the plugin.
Only 10 parameters can currently be used.

See also:

SoftDeclareMBS.CallMethod(param as string,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns no value.

The param string is a combination of the characters "i" for integer, "l" for 64bit integer, "f" for single (float) and "d" for double.
Use "i" for booleans, shorts and pointers.

the memoryblock must match exactly the parameters you specified.
Returns true on success.

See also:

SoftDeclareMBS.CallMethod(paramcount as Integer,data as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calls a function which returns no value.

If paramtercount is 0, the memoryblock is ignored.
The size of the memoryblock must be minimum 4*paramcount.
Each parameter is set using m.long(n*4) where n=0 is the first parameter.
A parameter may be any integer value or an address of a memoryblock. The address can be read using memoryblock.addressMBS which is part of the plugin.
Only 10 parameters can currently be used.
Returns true on success.

See also:

SoftDeclareMBS.CopyLibrary(byref target as SoftDeclareMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies the library handle to another softdeclare object.

if target is nil, a new object is created.
The library handle in the target object is set to point to the same library as the original object.

SoftDeclareMBS.FreeLibrary as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 5.4 ❌ No ✅ Yes ❌ No ❌ No All
Releases the library.

Only for Windows currently this function releases the handles and unloads the library. Windows internally has a reference counter for the library so memory is only released when the last reference is freed.
Lasterror is set.

SoftDeclareMBS.LoadConstant(constname as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads a constant from inside the library.
Example
dim c as SoftDeclareMBS
dim s as CFStringMBS
dim m as MemoryBlock
dim handle as Integer

// Test Mac OS X
// Load the constant kABFirstNameProperty from the Addressbook framework

c=new SoftDeclareMBS

if c.LoadFramework("Addressbook.framework") then
msgbox "Loaded "+c.libname+" to "+format(c.libhandle,"-0")+"."
if c.LoadConstant("kABFirstNameProperty") then
msgbox "Loaded constant "+c.ConstantName+" to "+format(c.ConstantPointer,"-0")+"."

m=NewMemoryBlockFromPtrMBS(c.ConstantPointer) // I hope it's not nil!

handle=m.Long(0)
if handle<>0 then
s=new CFStringMBS
s.Handle=handle

msgbox "Got value: "+s.str
end if
else
msgbox "Loading of constant "+c.ConstantName+" failed."
end if
else
msgbox "Loading of Addressbook.framework failed."
end if

Lasterror is set.

Some examples using this method:

SoftDeclareMBS.LoadDLL(libname as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 5.4 ❌ No ✅ Yes ❌ No ❌ No All
Loads a Windows DLL.

Lasterror is set.
libname can be name (e.g. "KERNEL32"), filename (e.g. "KERNEL32.DLL") or path (e.g. "C:\WINDOWS\KERNEL32.DLL").

SoftDeclareMBS.LoadDLLfromMemory(data as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ❌ No ✅ Yes ❌ No ❌ No All
Loads a Windows DLL from a string.

Some libraries don't like to be loaded from a string.
But else you can pass any DLL file content to this function.

The string is locked so it stays in memory.
On success the handle property is not zero and the function returns true.

SoftDeclareMBS.LoadDylib(path as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 5.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Loads a library in Mac OS X dylib format.

Lasterror and Liberror are set.

Some examples using this method:

SoftDeclareMBS.LoadFramework(frameworkfilename as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 5.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Loads a framework in Mac OS X.
Example
// A user's question:
// I am trying to call this to Carbon.framework using the softdeclare function:

// UInt32 SwapQDTextFlags(UInt32 newFlags);

// flags are OR'd

// kQDUseDefaultTextRendering = 0
// kQDUseTrueTypeScalerGlyphs = (1 << 0)
// kQDUseCGTextRendering = (1 << 1)
// kQDUseCGTextMetrics = (1 << 2)
// kQDDontChangeFlags = 0xFFFFFFFF

// The call is to make the system use Quartz rendering for QuickDraw text (like the text in my WASTEField). How should I call this?

// The solution code:

dim s as SoftDeclareMBS
dim m as MemoryBlock

const flags=-1 // = 0xFFFFFFFF

s=new SoftDeclareMBS
m=NewMemoryBlock(10)
m.Long(0)=flags

if s.LoadFramework("Carbon.Framework") then
if s.LoadFunction("SwapQDTextFlags") then
if s.CallFunction(1,m) then
MsgBox str(s.Result) // returns 7 for me (using Silk)
end if
end if
end if

// Without any error checking!

frameworkfilename is e.g. "Carbon.framework"
Lasterror is set.

SoftDeclareMBS.LoadFrameworkFile(frameworkpath as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 3.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Loads on Mac OS X a framework from the given file specification.
Example
dim f as FolderItem
dim s as SoftDeclareMBS

f=SpecialFolder.Desktop.Child("spellcheck.bundle")
s=new SoftDeclareMBS

if s.LoadFrameworkFile(f) then
MsgBox "OK"
end if

Returns true if successfull.
Lasterror is set.

SoftDeclareMBS.LoadFunction(funcname as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads a function from inside the library.
Example
dim s as SoftDeclareMBS
dim m as MemoryBlock

const flags=-1 // = 0xFFFFFFFF

s=new SoftDeclareMBS
m=NewMemoryBlock(10)
m.Long(0)=flags

if s.LoadLibrary("Carbon.Framework") then
if s.LoadFunction("SwapQDTextFlags") then
if s.CallFunction(1,m) then
MsgBox str(s.Result) // returns 7 for me (using Silk)
end if
end if
end if

A user's question:
I am trying to call this to Carbon.framework using the softdeclare function:

UInt32 SwapQDTextFlags(UInt32 newFlags);

flags are OR'd

kQDUseDefaultTextRendering = 0
kQDUseTrueTypeScalerGlyphs = (1 << 0)
kQDUseCGTextRendering = (1 << 1)
kQDUseCGTextMetrics = (1 << 2)
kQDDontChangeFlags = 0xFFFFFFFF

The call is to make the system use Quartz rendering for QuickDraw text (like the text in my WASTEField). How should I call this?

The solution code is above without any error checking!

Lasterror is set.

SoftDeclareMBS.LoadLibrary(libname as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads a library.

On Mac OS X e.g. "Carbon.framework" or "System.framework".
On Mac OS Carbon inside Classic e.g. "CarbonLib".
On Windows e.g. "KERNEL32" or "USER32".

Lasterror is set.

SoftDeclareMBS.ParametersSupported(param as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Declare MBS Util Plugin 7.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Tests whether plugin supports the given parameter string.

The param string is a combination of the characters "i" for integer, "l" for 64bit integer, "f" for single (float) and "d" for double.
Use "i" for booleans, shorts and pointers.

Any new parameter string can be added. Please send an email to support to get a new combination added.

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...