Compact 2013 Ebook

16.6 Create a DLL
Created by djones on 6/18/2013 11:07:22 AM

1. Refocus upon the second instance of Visual Studio 2012 if not already the focus.

2. In File Explorer select the solution

3. File—>Add—>New Project

4. Navigate to Visual C++/Windows Embedded Compact/SDK1

5. Choose Win32 DLL and call it sdkTimeDLL

6. Generate the project

7. Set the project to be built in Debug mode (default).

The project is an empty DLL project:

//  sdkTimeDLL.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "targetver.h"
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

Listing 16.4: The DLL source file sdkTimeDLL.cpp as generated by the SDK DLL template

8. Add the GetTime( ) function to the this source code:

sdkTimeDLL_API  void GetTime(TCHAR * time)
{
	//Get the system time
	SYSTEMTIME st;
	GetLocalTime(&st);
	_stprintf
		(time,
		_T("Time  %02d:%02d:%02d Date [DD/MM/YYY] %02d/%02d/%04d\n"),
		st.wHour,st.wMinute,st.wSecond, st.wDay, 
		st.wMonth, st.wYear
		);
}

Listing 16.5: The DLL GetTime( ) function

A header file for the DLL is required that includes a function prototype for the GetTime( ) function. This header file is included in applications that use the DLL.

9. Add a new header file to the DLL project: FileàAdd new Item
Call it sdkTimeDLL.h

10. Insert the following code in that header file.

#ifdef sdkTimeDLL_EXPORTS
#define sdkTimeDLL_API __declspec(dllexport)
#include 
#else
#define sdkTimeDLL_API __declspec(dllimport)
#endif
sdkTimeDLL_API  void GetTime(TCHAR * time);

Listing 16.6: The sdkTimeDLL.h header file

11. Modify stdafx.h as follows (towards the bottom):

include "sdkTimeDLL.h"   Insert this
//#include     Comment this out
#include < commctrl.h >    
// Windows Header Files:
//#include < windows.h >    Comment this out

Listing 16.7: The sdkTimeDLL.h header file

The DLL project needs sdkTimeDLL_EXPORTS needs to be defined for the C++ compilation so that the correct branch is taken in sdkTimeDLL.h.

12. Open the DLL project’s property pages: Right-click on the project in Solution Explorer and select Properties.

13. Select: Configuration Properties/C/C++/Preprocessor, then click on
Preprocessor Definitions (on right) then the down arrow on right in that box.
Then select as in Figure 1.3:

clip_image002

Figure 1.3: SDK Native Code Templates

14. Add the sdkTimeDLL_EXPORTS compiler directive as in Figure 1.4:

clip_image004

Figure 1.4: The sdkTimeDLL_EXPORTS compiler directive

Build the project and resolve any issues.

15. Open the Solution in File Explorer. Note that there is a folder \Debug.
This where the output of all projects in the solution are placed.

16. Open the folder and note that the .dll and ,lib files for the DLL project are there.

The .lib file needs to be linked with any application project that uses the DLL. The .dll needs to be made available to the application when it runs. One simple way is to include it as content for the application projection. The DLL project needs to be set as a dependency of the application project so that it gets compiled first. Finally the DLL header file created as above must be referenced by the application project.


NEXT: 16.7 Create an application to test the DLL

print

Click here to provide feedback and input

  Comments

profile photo

- In step 10. The #include above #else shouldn't be there
- In step 11. The first line should start with #

There are two typos on 16.6

By David Jones on 12/17/2013 4:56:32 AM

Turkish porno izle video site in rokettubeporno izle