Develop AUTHORWARE's u32 using DELPHI
Function functions are the most prominent feature of AUTHORWARE. The system functions provided by AUTHORWARE can complete some complex control tasks. For some special tasks, AUTHORWARE allows users to define functions themselves, making programming more flexible. For Windows systems, custom functions are stored as dynamic link library (DLL) files, so the file that stores custom functions is separated from the current interactive application file. This article introduces how to use DELPHI to develop AUTHORWARE's custom function - 32bitU32. This article takes DELPHI development U32 that can call messagebox display in AUTHORWARE as an example. Although AUTHORWAREATTAIN 5.0 has provided the function of using knowledgeobjects to display messagebox, this feature does not exist in versions before 4.0. This allows you to develop your own U32 in other languages and call it in AUTHORWARE.
Developing U32 can be divided into five steps:
Create project files
Create a function
Create a resource file
Compile resource files
Create u32
1. Create project files
Select dll in file/new to generate a dll file, add a unit containing U32 function code in file/addtoPRoject…. Myunit.pas (this unit is explained in detail in the second step of creating the function) After use, all of the user can be declared in authorware function called in. For example:
exportsMsgBox;
The final code is as follows:
libraryauthorware;
uses
SysUtils, Classes,
myunitin'myunit.pas';
exportsMsgBox;
Begin
end.
2. Create a function
When you create a function that is available in authorware, you must declare it as exported function and add the code after the keyword interface as follows:
interface
uses,Dialogs,SysUtils,windows;
functionMsgBox(msg:string;mbType:
Word;title:string):WORD;export;
Delphi32 needs to add {$ifdefWIN32}stdcall;
($endif} is followed by the function declaration as follows:
functionMsgBox(msg:string;mbType:
Word;title:string):WORD;export;
{$ifdefWIN32}stdcall;{$endif}
Now we add code to the function and follow the implementation:
const
OKOnly=0;
OKCancel=1;
AbortRetryIgnore=2;
YesNoCancel=3;
YesNo=4;
RetryCancel=5;
Critical=16;
Question=32;
Excalamation=48;
Information=64;
DefaultButton1=0;
DefaultButton2=256;
DefaultButton3=512;
applicationModal=0;
SystemModal=4096;
functionStrToPch(Str:string):PChar;
vara:PChar;
Begin
a:=StrAlloc(Length(Str)+1);
StrPCopy(a,Str);
StrToPch:=a;
end;
functionMsgBox(msg:string;mbType:
Word; title:string):WORD;
VAR
LpText,lpCaption:Pchar;
h:HWND;
Begin
lpText:=StrToPch(title);
lpCaption:=StrToPch(msg);
h:=GetActiveWindow();
MsgBox:=MessageBox(h,lpText,lpCaption,mbType);
end;
3. Create resource files
The last thing we have to do is create the resource file so that authorware can call the function directly. You must first create the .rc file and then compile it into the .res file. Use Notepad to create a resource file for .rc. Add the following definitions: I will explain these definitions later:
1DLL_HEADERPRELOADDISCARDABLE
BEGIN
"MsgBox/0",
"/0"
END
msgboxDLL_HEADERPRELOADDISCARDABLE
BEGIN
"/0",
"W/0",
"SWS/0",
"Result:=MsgBox(msg,mbType,title)/r/n",
"/r/n",
"showmessagebox/0",
END
If a dll file is written in the authorware call conversion format, the directory of all custom functions stored in it is also included in the file, and the information required by authorware when calling these functions is also included, and its directory is called Directory source, and each function in the directory source has corresponding definitions, and these definitions are called definition sources. The specific format is as follows:
1. Directory source
The format of the directory source is as follows:
|DLL_HEADERPRELOADDISCARDABLE
BEGIN
"functionname[=exportname]/0",
"functionname[=exportname]/0",
….
"functionname[=exportname]/0",
“/0”
END
①|is the directory source identifier;
②DLL_HEADER is the starting mark used to create descriptive text;
③BEGIN indicates the beginning of the source file of the directory.
END indicates the end of the directory source.
2. Custom function definition format
For each function in the directory source, there must be a corresponding definition format, the specific format is as follows:
functionnameDLL_HEADERPRELOADDISCARDABLE
BEGIN
"dllfilename/0"
“returnvalue/0”
“argumentlist/0”
"description>",
"description",
…
"description/0"
END
① Functionname refers to the function name defined in the directory source;
②DLLfilename represents the dll file name of the storage function;
③ Returnvalue represents the return value type of the function;
④Argumentlist represents the parameter type list in this function;
⑤Description represents the descriptive text of the function.
A descriptive body can be composed of many lines, but the last line must be ended with the "/0".
3. Parameter type description format
Parameter types are represented by a capital letter, and each letter represents a parameter format, as shown in the following table:
Description format typeDescribe format type
CSignedcharPFarpointer
BUnsignedcharFFloat
ISignedshortintegerDDouble
WUnsignedshortintegerSHandle
LSignedlongintegerVVoid
UUnsignedlonginteger
4. Compile resource files
Save the resource file of .rc as a3w.rc (note that the file name cannot be saved and the dll file name cannot be saved, otherwise the resource file of delphi will overwrite it). The compiled file of delphi is brc32.exe, and run in dos mode:
c:/delphi32/bin/brc32-ra3w.rc–foa3w32.res
Now add the resource file to the project, return to delphi in view/projcetsource to open the project file
exportsMsgBox; you can see:
{$R*.RES}
Delete the line and join: {$ifdefWIN32}
{$Ra3w32.res}
{$else}
{$Ra3w16.res}
{$endif}
Compile project files.
5. Create u32
We have created 32bit authorware.dll and renamed it to authorware.u32. Now U32 has been successfully created. Call authorware.u32 in authorware to add code in the operation design button:
MsgBox("Warning Box", 1+32+0+4096, "Do you exit this system?")