Model 1: Windows CE crude port




Download 1,09 Mb.
bet36/62
Sana21.03.2017
Hajmi1,09 Mb.
#917
1   ...   32   33   34   35   36   37   38   39   ...   62
4.1 Model 1: Windows CE crude port

This is the first model of Embedded Shruti. It started with the source code of Win32 version and first of all the structure of the native source code is identified. The points are identified where the API functions that are used in native code are not supported in Windows CE API. At all these points the modifications will be done accordingly so that the native code remains consistent. The input output characteristic of the native code should not be changed.

Embedded Shruti is designed in a modular way. There are three modules in Model 1. These are the following:


  1. Frontend

  2. Hindianalyser

  3. Hindiengine

Frontend was designed using Java in the native Win32 code but in Embedded Shruti it’s designed using MFC customized for Windows CE in eMbedded Visual C++.

The Frontend has a dialog box having the following contents:


1. Input Text Box: It takes the text input from the user which is to be changed to speech. The input should be in Hindi/Bengali at present. If multilingual keyboard is not there spell the Bengali/Hindi words using English alphabets and then fed the English alphabets into the text box.
2. Analyse Button: Analyse button on clicking read the input text from the text box and then write the text into a temporary file on the device called “TextIscii.txt”. This file will be read later on by the dynamic link library. Now after saving the input text on a file it loads the dynamic link library for Natural Language Processing called as hindianalyser.dll. Code snippet for loading dll is provided. The dll should export the functions which other executable can call. The method of exporting the functions from a dll will be given shortly. Before that the procedure to load a dll and call an exported function from executable code is given.

//Define a function pointer to call the DLL function

typedef int(*MBFuncPtr)(DWORD cBytes);

This is a pointer to a function whose return type is integer and which takes as input a DWORD. DWORD is a datatype defined in MFC. This refers to positive integers.

//Instance variable required to load a library

HINSTANCE hInst1;

//Loading a dynamic link library

hInst1 = ::LoadLibrary(L"hindianalyser.dll");

if(hInst1 == NULL)

MessageBox(L"Unable to load the analyser library");

else

MessageBox(L"Analyser Library successfully loaded");



If the library is not loaded successfully then hInst1 will be null. Once the library is loaded into the main memory the exported function from the library is accessed using the function pointer. The functions exported from the dynamic link libraries can be accessed only by the function pointer.

//Getting the address of the analyser function into the function pointer

MBFuncPtr pFunction=(MBFuncPtr)GetProcAddress(hInst1,L"Analyse");

Analyse is the name of the function exported from the dynamic link library. The functions that were exported by the dynamic link library are mentioned on .def(definition) file of the dynamic link library source code. A typical .def file will look like:

//analyser.def

LIBRARY Analyser

EXPORTS

Analyse


The name of the library is specified on the first line of the def file which is called Analyser library in this case. After that there are a list of functions that are exported from the dll which are mentioned under the EXPORTS header. There may be a number of function exported by a dll. There should be a function in dll that starts with the name as mentioned under EXPORTS tag. The pointer to that function will be copied into the function pointer from the calling program (the executable in this case) and the function is called with appropriate inputs.

pFunction called above will be NULL if there is no such function exported by the dll.

if(pFunction = = NULL)

MessageBox(L"Unable to load the Analyse function");

else

{

MessageBox(L"Analyse function exported from the dll called");



tokenLength=(*pFunction)(cBytes);

}

Once the function pointer is obtained in pFunction, the function can be called with DWORD as parameter and as the return type is integer it will return an integer value after processing the input text file “TextAscii.txt”.



After the use of library is over it’s always advisable to Free the library. As the dynamic link libraries are loaded on RAM, for devices running Windows CE which have very limited RAM space it’s advisable to unload the dll as soon as the work is done.

//Unloading a dynamic link library

::FreeLibrary(hInst1);
The methods discussed above a necessary to do operations related to dynamic link libraries. The next important difference between the native Win32 source code and the Windows CE version are the file operations. As already mentioned above on clicking the Analyse button the text input is saved on a file in disk. Windows CE doesn’t support file operations like fopen, fread, fclose, fseek and so on. Therefore while porting it is very important to find the equivalent of each of these file operations using Windows CE API.
In Windows CE API all devices are accessed by handles. The developer can access a file on disk, or a USB port or a sound device using handles. No other layer is defined like fopen and fseek. The following code snippets will show how to create a file, read a file and write a file using Windows CE API.

//To create a file

HANDLE exampleHandle = 0;

//Create a file in read mode

exampleHandle = CreateFile

(L"TextIscii.txt",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

//Create a file in write mode

exampleHandle= CreateFile(L"TextIscii.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

A complete reference to the CreateFile function is provided below:

This function creates, opens, or truncates a file, communications resource, disk device, or console. It returns a handle that can be used to access the object. It can also open and return a handle to a directory.




Download 1,09 Mb.
1   ...   32   33   34   35   36   37   38   39   ...   62




Download 1,09 Mb.