Friday, August 14, 2009

Actual Program of Recursive File Reading for Windows CE

In my previous posts, i have tried to explain about Recursive File reading in Windows operating systems. But some chages are required to run the program in Windows CE. The program as follows:

void Function()
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
static RetValue=1;
unsigned char DirPath[300];
unsigned char DirPath_Temp[300];
unsigned int Count=0;
unsigned int Temp=0,Temp_2=0;
unsigned char Temp1[300];
unsigned char *Paths[300];
unsigned int Completed=0;

lstrcpy(DirPath,L"\\windows\\*.*");

Completed = 0;
hSearch = FindFirstFile(DirPath, &FileData);

while(1)
{
if(FileData.dwFileAttributes == 16 && RetValue != 0)
{
RetValue=1;
printf("directory is %S\n", FileData.cFileName);
Paths[Count] = (char*)malloc(300);
if(!Paths[Count])
{
printf("Malloc failed\n");
return -1;
}
Temp = lstrlen(DirPath);
Temp = Temp*2;
if(DirPath[Temp-2] == '*')
{
Temp = Temp - 6;
}
Temp_2 = 0;
while(Temp)
{
Temp1[Temp_2] = DirPath[Temp_2];
Temp_2++;
Temp--;
}
Temp1[Temp_2]='\0';
Temp1[Temp_2+1]='\0';
lstrcat(Temp1,FileData.cFileName);
lstrcat(Temp1,"\\");
lstrcpy(Paths[Count], Temp1);
Count++;
}
else if(FileData.dwFileAttributes == 32 && RetValue != 0)
{
RetValue=1;
Temp = lstrlen(DirPath);
Temp = Temp*2;
if(DirPath[Temp-2] == '*')
{
Temp = Temp - 6;
}
Temp_2 = 0;
while(Temp)
{
Temp1[Temp_2] = DirPath[Temp_2];
Temp_2++;
Temp--;
}
Temp1[Temp_2]='\0';
Temp1[Temp_2+1]='\0';
lstrcat(Temp1,FileData.cFileName);
printf("File read is %S\n",Temp1);
}
if(!FindNextFile(hSearch, &FileData))
{
if(GetLastError() == ERROR_NO_MORE_FILES)
{
if(Completed == Count)
{
printf("Exiting....\n");
break;
}
lstrcpy(DirPath, Paths[Completed]);
lstrcat(DirPath,"*\0.\0*\0\0\0");
Completed++;
hSearch = FindFirstFile(DirPath, &FileData);
if(!hSearch)
RetValue =0;
continue;
}
else
{
printf("Could not find next file.\n");
break;
}
}
}
FindClose(hSearch);
}

In Win32, in every directories, two hidden files will be there ('.' and '. .'). Hence two FindNextFile statements are removed here.

Thursday, August 13, 2009

How To Create DLL Files in Windows CE or Win32?

When we were trying to develop a pltform and hardware indpendent Media player for In-Vehicle Infotainment systems, our goal was to make every layer Independent!

Normally for every application in embedded domain, we classiy our work as 3 layers. (OSI layers will come after)
1. Application layer
2. OS and Device Driver layer
3. BSP and Hardware layer

Our work belongs to pure application layer where we are using Operating System services to implement our application. Further, our work will be classified as 3 layers.
1. Human Machine Interface (HMI or GUI)
2. Connectivity and Multimedia (CAM)
3. OS layer

We are not concentrating much on hardware and hence Hardware layer is excluded here.

As a first step, we have decided to separate HMI and CAM. To achieve this, creation of DLL file for the CAM layer was necessary.

With the help of some documents and googling, i was succeeded in creation of DLL in VC++ IDE as a static library. In case of static, we will include ".lib" file in the project settings(dependencies). Then the compiler automatically takes the respective DLL from the standard paths.

But it was not useful for us. Then we came to know about '.def' files (definition file). Definition file Contains Function names which are to be exported to outside of the module.

Finally we have achieved in Visual Studio 2005 IDE.

Steps to be followed:

1. Create a DLL project
2. Write your implementations without main function.
3. Add a new source file of type '.def'. It will be there is IDE.
3. Add function names which have to be accessed from other modules

The '.def' file will be like

LIBRARY "CAM_DLL_FOR_CE"
EXPORTS
FunctionName1
FunctionName2

If you build the project, you will be getting dll file in Debug/Release directory of ur workspace.

Note:
If you didnt add the '.def' file, you will not able to import the functions of DLL files.

We can discuss how to access the DLL files and its functions, in my next post.