next up previous contents
Next: Calling dll functions and Up: Using SWFKit Pro to Previous: Using SWFKit Pro to   Contents

Declaring the dll functions

The first thing you would have to do before you can call a dll function in SWFKit Pro is to declare the function. The new "dllimport" keyword and the new structure type make things easier: the "dllimport" keyword makes function declarations in FFish Script very distinct just like in c/c++, and the structure type gives the FFish Script the power of supporting complex data types. More details about dll function declaration can be found at 2.58. Some dll function declaration examples are as follows:

A function without structure type parameters The GetSystemDirectory function is exported by "kernel32.dll" and is used to retrieve the path of the system directory. The declaration of this function in SWFKit Pro should be

dllimport "kernel32.dll" stdcall unsigned int
    GetSystemDirectoryA(char *lpBuffer, unsigned int uSize) as getSysDir;
where "kernel32.dll" indicates the library name (name of the dll file that exports the function). Since "kernel32.dll" is a system file that SWFKit Pro can find it, at here we need not use a full path name like "c:
windows
system32
kernel32.dll". However, for a dll created by yourself, e.g. in the "Resources" of SWFKit Pro, you would have to specify the full path name of the dll file:
var myDll = getAdditionalFile("mydll.dll");
dllimport myDll stdcall void MyFunc();
"stdcall" indicates the calling convention. SWFKit Pro 3 now supports two kinds of calling convention: stdcall and cdecl. Typically, Windows API functions use stdcall calling convention, whereas c/c++ functions use cdecl calling convention. After "stdcall" is the return value, function name, and the parameter list in a pair of brackets You can also omit the parameter names of the functions, e.g.
dllimport "kernel32.dll" stdcall unsigned int
    GetSystemDirectoryA(char *, unsigned int) as getSysDir;
The data types that can be used in function declaration is listed in 2.58. And "void" can only be used for the return type, which means no return. A parameter cannot be of "void" type. After the "as" keyword is the alias of the function. If you specify an alias for a function, you must use its alias to call it in FFish Script; otherwise the name of the function will be used.

A function with structure type parameters or returns a structure In this case, you would have to declare the structure type first. E.g. the FindFirstFile function:

struct
{
    unsigned int dwLowDateTime;
    unsigned int dwHighDateTime;
} FILETIME;

struct
{
    unsigned int dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    unsigned int nFileSizeHigh;
    unsigned int nFileSizeLow;
    unsigned int dwReserved0;
    unsigned int dwReserved1;
    char cFileName[260];
    char cAlternateFileName[14];
} WIN32_FIND_DATA;

dllimport "kernel32.dll" stdcall pointer
    FindFirstFileA(char *, WIN32_FIND_DATA*) as findFirstFile;


next up previous contents
Next: Calling dll functions and Up: Using SWFKit Pro to Previous: Using SWFKit Pro to   Contents
Copyright ©2000-2007 Shanghai TopCMM Software Technologies. All Rights Reserved.