惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - cjnong

EVA:自定义字段实现 Mac OS 下安装mysqlclient报“mysql_config not found”的解决 Tensorflow之训练MNIST(1) [新手]在macOS环境下安装xdebug 31.8重拾技术人生 MAC下安装MAMP后,mysql server无法启动 用myeclipse配置hibernate 重学JSP—设置CATALINA_HOME环境变量 Java 回调函数 转自:http://blog.sina.com.cn/s/blog_48cf38890100go6x.html android学习笔记 创建一个android activity 启动不了android模拟器 在线口语考试系统制作(二) 在线口语考试制作(一) 网页播放器的控制参数的收集 使用不同版本的.net框架使服务器应用程序不可用 ASP.NET生成静态页面的方法 sql2005转SQL2000出现的问题 实现页面无刷新(使用回调函数) - cjnong - 博客园
口语考试制作(三)——使用DllImport调用非托管函数
cjnong · 2008-12-07 · via 博客园 - cjnong

  前一篇文章分析了制作口语考试系统的几种方法,JMF好像口碑不是很好,而且客户端还需要下载JMF的框架,RED5和FMS都没有使用过,而微软好像没有提供类似java的applet那样的网页端小程序,因为胖客户端应用已经被flash占了比较大的又是,silverlight也是刚刚开始推广。所以,我决定选择使用C/S的架构。

  第一个要解决的问题就是就是在托管程序中调用非托馆函数的问题。

  使用DllImport来调用win32 API. DllImport在命名空间System.Runtime.InteropServices中.

  DllImport是用于指明声明的函数。

  DllImport的使用形式为:[DllImport("User32.dll", EntryPoint = "MessageBox", CharSet = CharSet.Auto)]

  其中,User32.dll是要调用的dll名,EntryPoint指明了调用的入口点,即是调用dll中的哪个函数。CharSet指明了调用的字符集。字符集包括ansi和unicode两种。

  DllImport描述的函数必须是用static和extern加以修饰。

  举例说明:

  声明原型:

LipWrap

 调用函数

Code

运行程序后,当点击窗口中的按钮时,就会出现一个hello world的弹出窗口。

附:由于托管代码和非托管代码的数据类型是不兼容的,必须使用托管代码中的数据类型对非托管代码的数据类型进行替换

下表引自MSDN,列出了非托管代码对应的托管代码的数据类型

下表列出了在 Win32 API(在 Wtypes.h 中列出)和 C 样式函数中使用的数据类型。许多非托管库包含将这些数据类型作为参数传递并返回值的函数。第三列列出了在托管代码中使用的相应的 .NET Framework 内置值类型或类。某些情况下,您可以用大小相同的类型替换此表中列出的类型。

Wtypes.h 中的非托管类型 非托管 C 语言类型 托管类名 说明

HANDLE

void*

System.IntPtr

在 32 位 Windows 操作系统上为 32 位,在 64 位 Windows 操作系统上为 64 位。

BYTE

unsigned char

System.Byte

8 位

SHORT

short

System.Int16

16 位

WORD

unsigned short

System.UInt16

16 位

INT

int

System.Int32

32 位

UINT

unsigned int

System.UInt32

32 位

LONG

long

System.Int32

32 位

BOOL

long

System.Int32

32 位

DWORD

unsigned long

System.UInt32

32 位

ULONG

unsigned long

System.UInt32

32 位

CHAR

char

System.Char

用 ANSI 修饰。

LPSTR

char*

System.String 或 System.Text.StringBuilder

用 ANSI 修饰。

LPCSTR

Const char*

System.String 或 System.Text.StringBuilder

用 ANSI 修饰。

LPWSTR

wchar_t*

System.String 或 System.Text.StringBuilder

用 Unicode 修饰。

LPCWSTR

Const wchar_t*

System.String 或 System.Text.StringBuilder

用 Unicode 修饰。

FLOAT

Float

System.Single

32 位

DOUBLE

Double

System.Double

64 位

下表将说明 Win32 API 中几个常用的 DLL。

DLL 内容说明

GDI32.dll

用于设备输出的图形设备接口 (GDI) 函数,例如用于绘图和字体管理的函数。

Kernel32.dll

用于内存管理和资源处理的低级别操作系统函数。

User32.dll

用于消息处理、计时器、菜单和通信的 Windows 管理函数。

  win32API提供的多媒体API叫MCI,在system32目录下的winmm.dll中包含了该函数。