Current location - Education and Training Encyclopedia - Graduation thesis - How to write UCD function for Authorware to change language?
How to write UCD function for Authorware to change language?
It is not enough to improve the flexibility of Authorware multimedia programs only by the functions of Authorware itself and the system functions it provides. Sometimes, users need to use other development tools to generate custom functions to extend the functions of the program. It is precisely because of the flexibility and convenience of UCD that many third-party software vendors have made many UCDs with different functions for Authorware. Using these UCDs will add a lot of color to our program. In addition to using UCD created by others, we must also create our own UCD function, because sometimes the existing UCD can not meet our needs, at this time En can develop UCD that meets our needs. Everything is difficult at the beginning. If we write a UCD function now, we may feel at a loss. In fact, it is quite easy to create a powerful UCD function as long as we understand the principle of UCD function. Of course, the premise is to have a certain level of programming. Let me introduce how to develop a 32-bit UCD function (U32) with Delphi. I will create two UCD functions as examples: a) addition function: add two numbers; B) UCase function: Capitalize a string. The specific steps are as follows: 1. Create an ordinary DLL u to start Delphi3.0, and then select File => "New application" menu command to create a new project u select File => "Remove from project" menu command, select "Forml" from the list in the pop-up window, click "OK" button, and a confirmation window will appear, in which you can click "No" button to save the changes. U choose file => new menu command, then select unit item in the new item window, and click OK to add a new unit in the new project. This new unit will contain all the codes in the UCD function. U Next, we will modify the existing code to create a DLL file instead of an EXE file. Select view = > unit menu command, select Project 1 in the view unit window, and then click ok. U At this time, a panel named Project 1 will be added to the project1. We will notice that the first line of code in the panel is the program Project 1, which is used to create an EXE file. In order for Delphi to create a DLL file, the keyword "program" must be changed to "library". U Because we don't need a form in this project, in the "Use" section, delete the reference to "Form". Because if this reference is retained, the final DLL file will be about 150K larger than the DLL file formed without this reference. Of course, if you need to use a form in a DLL, please keep a reference to "form". After the "Use" section, we need to declare all the custom functions that will be used in Authorware. In this example, we first Add the following code: Exports Add: The function of this code is to output the add function so that other applications can use it. Because the DLL file does not need to be executed, we need to delete the line "Application". Initialize the and application. Run between the beginning and the end. The final modified code should look like this: library project1; Use Unitl in 'UNT 1. PAS '; Increase in exports; | $ R *。 Start and end. Now save the project, where the name of the project is the name of the last created DLL. In this example, we named the project DllDemo.dpr and saved the Unitl unit as UNITL. PAS.2. Create an Add Function Now let's implement adding a custom function. The main steps are as follows: u Click the UNILL tab in the DllDemo.dpr code window to display the code window in the UNILL panel. U Because the Add function is very simple, you don't need to do any special work when passing or returning the value of an integer, word or long, so the method of creating this function is the same as any other Delphi function. First, if you want to create a function for use in Authorware, you must declare it as an output function. Therefore, please Add(n 1, N2: integer): integer in the "interface keyword: UESyutils, WinTypes, Winprocs function; Export; The 32-bit Delphi program needs an extra code segment, and an indicator named "stdcall" should be added to the code segment. However, the 16-bit version of the Delhpi program cannot recognize the "stdcall" indicator. Therefore, in order to make our DLL support both 16-bit and 32-bit versions of Delphi programs, we can use conditional inclusion statements. Please Add the following code after the add function declaration: | ifdefwin32 | stdcall($ endif) In this way, the compiler only adds extra code fragments in the case of 32-bit version. The modification at this time should be as follows: function Add (N 1, N2, integer): integer; Export; | $ ifdef WIN32 | srdcall|endif| u Now it's time to Add muscles to the add function. After the keyword "implementlation", add the following code: function Add (N 1, N2: integer): integer; Initial result: = n1+N2; End; At this point, the Add function is created. 3. The code for creating UCase function UCase function is a little more complicated. Because the strings passed to or returned from Authorware are all C-type strings, if you want to call a function that uses pascal-type strings, you must first convert the C-type strings into pascal-type strings, and the strings returned by Authorware are read-only, so we cannot modify them directly. U Open the Unitl code window, and then after the ReturnString function declaration of the "Interface" code segment, add the following code to declare the Ucase function: Function ucase (string: pchar): pchar; Export; | $ ifdef WIN32 | stdcall| $ endif | u Then, after the implementation code of the ReturnString function in the "implementation" code segment, add the implementation code of the UCase function: functionucase (string: pchar): pchar; | Note: I didn't do any error checking-string length | Varretstr: char| of array [0 ... 64] | Returns the string of APW | instr: outstr: string [64]; | Some temporary strings | Begin instr: = strpas (stringin): | Convert a C string into a pascal string; | outstr: = uppercase (instr ): | As a function, use Delhpi's built-in function | strplcopy( retstr, outstr, 60): | Convert pascal string into C string | Result: = Return string (Retstr): | Return the string to APW | end;; U In order to use this function in Authorware, it must be declared as an exportable function in the project file. Please click the DllDemo tab at the top of the code window to open the project file, and then Add the following code after outputting the statement of the add function: Exports UCase is now complete. 4. Convert the regular DLL into UCD 1) Set some project options L to return to Delphi, select the "Project = > Options" menu command to open the project options window, and then click the compiler tab in the window. L In the Debug Combination field of the compiler panel, clear all check boxes. L Click OK to close the project options window. 2) Creating resource files Up to now, we have only created a regular DLL, and there is no UCD supported by Authorware. So the next work is to add UCD resources to the existing DLL, so that Authorware can directly load the functions in it. To achieve this, you need to create a suffix named. Rc, and then compiled into a. res file. Please use any tool software that can edit the text file, then add the following code in it, and finally save it in the directory where the newly created DLL is located, with the file name MyUCD.rc Please be careful not to make the name of the resource file the same as that of the engineering file (that is, both DllDemo), otherwise Delphi will overwrite the resource file. The code is as follows:1dll _ headerepreqad discard aplebebegin "add \ 0", "UCASE \ 0", "0", endaddll _ headerepreqad discard aplebebegin "\ 0", "I \ 0 ","ii \ 0 ","result: = add (Num 1, Num2) \ r \ n ","r \ n ","Calculate the sum of two integers Num 1 and num 2 \ 0 ",and end ucase dll _ headprel qaddiscard. In Delphi3.0, the executable file used to compile resource files is called Brc32.exe, which is located in the Bin directory of Delphi3.0. Open a DOS window, enter the directory where we save Delphi projects, and then enter the following statement at the DOS prompt: c:\ progta- 1 \ borland \ Delphi-1\ bin \ brc32.exe–r myucd.rc–fdmycd.res Press Enter and the DOS command will be executed immediately. After execution, you can find a file named MyUCD.res in the current directory. Now we need to add the edited resource file to our project. So go back to Delphi, click the DllDemo tab in the code window to open the engineering code window, and find the following line: | $ R *. Res| If the form is not used in the project, you can delete this line, because our UCD function does not use the form, so you can delete it. Of course, there will be no problem in keeping this line. After this line, add the following code: | $ R MyUCD.res| At this point, all the work is finished, compile this project, and then open a new file in Authorware for testing. Everything is as I expected. Of course, for the sake of unification, it is suggested to rename DllDemo.u32 to DllDemo.u32, so that other users will know that this file is a UCD file.

Seek adoption