CallFn Examples

Example 1:

To load a DLL called MyDLL.dll and call a function called "Test") which takes no parameters and returns no value) in it:

var MyDLL = LoadDLL( SYSTEM_PUBLICATION_DIR + "MyDLL.dll" );
if (MyDLL)
{
 // Call a function called Test with no return value (hence the "none" after the separating comma) and no parameters (simply not present)
 MyDLL.CallFn("Test", "none");
}

Example 2:

Calling various example functions which take parameters and return values, using a DLL which is located in the publication directory and is therefore uses the SYSTEM_PUBLICATION_DIR as a path attached the name of the DLL:

var MyDLL = LoadDLL( SYSTEM_PUBLICATION_DIR + "MyDLL.dll" );
if (MyDLL)
{
 // Call a function within the DLL
 var UserID = MyDLL.CallFn("GetID", "ulong", "string", USER_NAME);
 if (UserID != 0)
 {
  MyDLL.CallFn("SomeFunction", "none", "ulong", UserID );
 }
}

Example 3:

It is also possible to call some Windows system functions, providing they take parameters that can be passed via OpusScript. For example, the MessageBox API function can be called as follows:

var User = LoadDLL( SYSTEM_WINSYS_DIR + "User32.dll");
if (User)
{
 User.CallFn( "MessageBoxA", "slong", "hwnd", 0, "long", 0, "string", "This is a message box!", "string", "This is the title", "long", 48 );
}

The message box function is particularly useful for asking for feedback from users in a familiar way – for example asking if they really want to exit the publication.

Further details on using the Window’s MessageBox with Opus can be found in the Using Windows Message Boxes topic. Full documentation for the Windows API can be found on Microsoft’s MSDN website.

image\Script_Button.jpgExamples

Close