Compact 2013 Ebook

14.9 Using a Static LIB
Created by djones on 6/18/2013 8:13:06 AM

Using a Static Link Library (.LIB)

In this activity, the time processing for the Console application will be moved to a static library. It could just as easily be applied to the WinForn app. Creating the static lib is similar to the DLL but simpler.

1. Add a new subproject again but this time choose the WCE Static Link Library. Call the DLL TimeLib. There are no options for this project except the Precompiled Header.

Explore for files created, there is no header, no source and no parameter files. We have to add the code files, but the parameter files are not required as this does not run on the platform as a separate entity.

2. Add a new header file TimeLib.h and source file TimeLib.cpp to the project

3. Add the following code to the blank header file:

void  GetTime(TCHAR * time);

Listing 14.19 The header file contents for the static lib.

4. Add the following code to the blank code source file:

#include "stdafx.h"
#include "TimeLib.h"
void GetTime(TCHAR * time)
{
	//Get the system time
	SYSTEMTIME st;
	GetLocalTime(&st);
	//Write it to the string
	wsprintf(time,
		_T("Time  %02d:%02d:%02d Date [DD/MM/YYY] %02d/%02d/%04d"),
		st.wHour,st.wMinute,st.wSecond, st.wDay, 
		st.wMonth, st.wYear
		);
}

Listing 14.20 The static lib code source file contents.

5. Open the lib sources file (double-click on the project in Solution Explorer) and change the line:
MFC=1 to MFC=0
We don’t want to link the MFC library.

6. Build this project

7. Open the console project with Time implemented, and open the code source file. Add the reference to TimeLib.h as shown below stdafx.h reference or include it in stdafx.h.
Modify the main function as indicated:

#include "stdafx.h"
#include "..\TimeLib\TimeLib.h"
{
tprintf(_T("The time is: "));
//Get local time
TCHAR dateTime[100];  //The buffer for the DateTime string
GetTime(&dateTime);
putws(dateTime);
TCHAR ch;
_tprintf(_T("Press enter to continue:\n"));
_getws(&ch);
return 0;
}

Listing 14.21 The code source file contents for console application that references the static lib.

8. Finally add the following .lib linkage information to TARGETLIBS in the main project(Hello) sources file as per commented with the DLL linkage:

..\TimeLib\obj\$(_TGTCPU)\$(WINCEDEBUG)\TimeLib.lib

Listing 14.22 The console application linkage information in its sources file.

Note in this case the lib link to the application contains the actual machine instructions to perform the computation and so the DLL is not loaded at runtime. This lib binary is added to the application at linkage time when the application is built.

9. Build the application and test run it. The output should be the current local time as previous.

Note: A final note about build order and modules. Because the Winform application depends upon the DLL and the final console application depends upon the static lib, those modules should be built before their apps. This can be configured by right-clicking on Subprojects and selecting Subprojects Build order. The modules can then be moved up the build order as required. This impacts when the OS is built or Build All Subprojects is chosen.

clip_image002

Figure 14.20: The Subproject Builder Order Dialog


NEXT: The sources file

print

Click here to provide feedback and input

  Comments

There is no comment.

Turkish porno izle video site in rokettubeporno izle