Encapsulation of native DLL in Windows Mobile and Windows WinCE (Windows Embedded CE)

Source: Internet
Author: User
ArticleDirectory
    • 1. Create an output definition header file
    • 2. implement interfaces provided by header files
    • 3. Configure precompiled macros (Preprocessor definitions)
    • 4. Configure the output lib File

I have written an article about native DLL encapsulation in Windows Mobile and Windows Embedded ce. The original Article is as follows:

How to encapsulate native DLL provided to. NET Compact framework in Windows Mobile and WinCE (Windows Embedded CE) for calling

 

The original article focuses on how to encapsulate native DLL provided to. NET Compact frameworkProgram. However, If You encapsulate the DLL according to the original method, calling the DLL using native C ++ may cause some trouble. You need to dynamically load the DLL, I have written an article earlier. The original Article is as follows:

How to use native C ++ to dynamically load DLL in Windows Mobile

 

Dynamic Loading has its advantages. However, if both the encapsulated DLL and the caller are internal programs and are loaded during initialization (also called static loading), it will be more convenient and simple during development. The following describes how to encapsulate DLL to provide the static loading service for the caller.

1. Create an output definition header file
// The following ifdef block is the standard way of creating macros which make exporting
// From a DLL simpler. All files within this DLL are compiled with the my32feetwidcomm_exports
// Symbol defined on the command line. This symbol shocould not be defined on any project
// That uses this DLL. This way any other project whose source files include this file see
// My32feetwidcomm_api functions as being imported from a DLL, whereas this DLL sees symbols
// Defined with this macro as being exported.
# Ifdef My32feetwidcomm_exports
# Define My32feetwidcomm_api _ Declspec ( Dllexport )
# Else
# Define my32feetwidcomm_api _ declspec (dllimport)
# Endif

// This class is exported from the 32feetwidcommwm. dll
Class My32feetwidcommwm_api cmy32feetwidcommwm {
Public :
Cmy32feetwidcommwm ( Void );
// Todo: add your methods here.
};

Extern My32feetwidcommwm_api Int Nmy32feetwidcommwm;

My32feetwidcommwm_api Int Fnmy32feetwidcommwm ( Void );

The caller needs to # include this header file.

 

2. implement interfaces provided by header files
 // 32feetwidcommwm. cpp: defines the entry point for the DLL application.
//

# Include "Stdafx. H"
# Include "32feetwidcommwm. H"
# Include <Windows. h>
# Include <Commctrl. h>

Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Switch (Ul_reason_for_call)
{
Case Dll_process_attach:
Case Dll_thread_attach:
Case Dll_thread_detach:
Case Dll_process_detach:
Break ;
}
Return True;
}

// This is an example of an exported variable
My32feetwidcommwm_api Int Nmy32feetwidcommwm = 0;

// This is an example of an exported function.
My32feetwidcommwm_api Int Fnmy32feetwidcommwm ( Void )
{
Return 42;
}

// This is the constructor of a class that has been exported.
// See 32feetwidcommwm. h for the class definition
Cmy32feetwidcommwm: cmy32feetwidcommwm ()
{
Return ;
}

 

3. Configure precompiled macros (Preprocessor definitions)

The project that encapsulates the DLL will output the interface_ Declspec(DllexportThe caller will enter the interface _ declspec (dllimport). For details, see the header file definition.

4. Configure the output lib File

The caller needs to link the Lib file.

 

Finished.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.