Windows Mobile和Wince(Windows Embedded CE)下封装Native DLL进一步探讨

简介:

之前写过一篇关于Windows Mobile和Wince(Windows Embedded CE)下封装Native DLL的文章,原文如下:

Windows Mobile和Wince(Windows Embedded CE)下如何封装Native DLL提供给.NET Compact Framework进行调用

 

原文主要针对如何封装的Native DLL提供给.NET Compact Framework的程序来调用。但是如果按照原文的方法进行封装,使用Native C++调用该封装DLL会有一些麻烦,需要动态加载该DLL,关于动态加载,我之前也写过一篇文章,原文如下:

如何在Windows Mobile下使用Native C++动态加载DLL

 

动态加载有其好处,但是如果封装的DLL和调用方都是内部的程序,使用初始化时候加载(也叫做静态加载),在开发时会更加方便和简单。下面讲述如何封装DLL为调用方提供静态加载服务。

1.建立输出定义头文件

// 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 should 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);

调用方需要#include该头文件。

 

2.实现头文件提供的接口

// 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.配置预编译宏(Preprocessor Definitions)

 export-dll-2

封装DLL的项目会输出接口 __declspec(dllexport) ,而调用方会输入接口 __declspec(dllimport) ,见头文件定义。

4.配置输出lib文件

export-dll-1

调用方需要链接该lib文件。

 

完成了。


    本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2009/11/18/Windows-Mobile-Native-DLL.html,如需转载请自行联系原作者



相关文章
|
3月前
|
存储 Java C语言
Windows 下 JNI 调用动态链接库 dll
Windows 下 JNI 调用动态链接库 dll
56 0
|
6月前
|
监控 编译器 API
[笔记]Windows核心编程《二十二》注入DLL和拦截API(一)
[笔记]Windows核心编程《二十二》注入DLL和拦截API
143 0
|
6月前
|
人工智能 缓存 Shell
[笔记]Windows核心编程《二十》DLL的高级操作技术(二)
[笔记]Windows核心编程《二十》DLL的高级操作技术(二)
144 0
|
9月前
|
安全 虚拟化 Windows
Windows x64内核下注入DLL姿势之一
讲述了Windows x64内核下注入DLL的思路与流程
|
3月前
|
存储 Java C++
Windows 下 JNA 调用动态链接库 dll
Windows 下 JNA 调用动态链接库 dll
41 0
|
6月前
|
编译器 C++ Windows
[笔记]Windows核心编程《十九》DLL基础(二)
[笔记]Windows核心编程《十九》DLL基础(二)
102 0
|
4月前
|
网络协议 安全 API
9.9 Windows驱动开发:内核远程线程实现DLL注入
在笔者上一篇文章`《内核RIP劫持实现DLL注入》`介绍了通过劫持RIP指针控制程序执行流实现插入DLL的目的,本章将继续探索全新的注入方式,通过`NtCreateThreadEx`这个内核函数实现注入DLL的目的,需要注意的是该函数在微软系统中未被导出使用时需要首先得到该函数的入口地址,`NtCreateThreadEx`函数最终会调用`ZwCreateThread`,本章在寻找函数的方式上有所不同,前一章通过内存定位的方法得到所需地址,本章则是通过解析导出表实现。
67 0
9.9 Windows驱动开发:内核远程线程实现DLL注入
|
5月前
|
开发者 Windows
什么是 Windows 操作系统 DLL 文件的 Side-by-Side Assemblies 技术
什么是 Windows 操作系统 DLL 文件的 Side-by-Side Assemblies 技术
47 0
|
5月前
|
API UED Windows
什么是 Windows 操作系统的 DLL 文件
什么是 Windows 操作系统的 DLL 文件
83 0
|
5月前
|
Unix Linux C#
使用 ABAP + OLE 消费 Windows DLL 文件里的代码和服务
使用 ABAP + OLE 消费 Windows DLL 文件里的代码和服务
27 0