本文介绍了Lib文件C#的托管包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候所有,
我最近开始使用C#.我有一个需要使用非托管代码的项目.我可以访问API的.lib和H文件.我意识到这已经在前面讨论过了.例如((如何在C中创建DLL库,然后将其与C#一起使用 [ ^ ]),但我的头文件似乎与在那个例子.
我正在尝试在CE设备上打开蜂鸣器.我想使用C#创建一个表单.我知道我必须创建一个包装器,但是在概念上有些挣扎.头文件的内容如下所示:
#ifndef __BUZZERIF_H__
#define __BUZZERIF_H__
#if __cplusplus
extern"C" {
#endif
BOOL BuzzerState(DWORD dwState);
DWORD BuzzerRegRead(DWORD RegNum);
#if __cplusplus
}
#endif
#endif//__ BUZZERIF_H__
-------------------------------------------------- ---------------------
以下C代码将蜂鸣器打开"
DWORD dwVal;
dwVal = 0x0001;
如果(!BuzzerState(dwVal))
{
printf(" BuzzerState()FAILED \ r \ n" );
}
其他
{
printf(" 蜂鸣器状态设置为=%u \ r \ n" ,dwVal);
}
如果有人可以向我提供有关如何创建包装器的指针,以便我可以在C#中设置/调用该函数(甚至是最简单的示例代码),那将是不胜感激的.方案
Greetings all,
I''ve recently started with C#. I have a project which requires the use of unmanaged code. I have access to a .lib and H file to an API. I realize that this has been covered previously. eg (How to create a DLL library in C and then use it with C#[^] ) but my header file seems a little different to the one used in that example.
I am trying to turn on a buzzer on a CE device. I would like to create a form using C#. I understand I have to create a wrapper but struggling a little with the concepts. The contents of the header file looks like this:
#ifndef __BUZZERIF_H__
#define __BUZZERIF_H__
#if __cplusplus
extern "C" {
#endif
BOOL BuzzerState(DWORD dwState) ;
DWORD BuzzerRegRead(DWORD RegNum) ;
#if __cplusplus
}
#endif
#endif //__BUZZERIF_H__
-----------------------------------------------------------------------
The following C code turns the buzzer "on"
DWORD dwVal ;
dwVal = 0x0001 ;
if ( !BuzzerState(dwVal) )
{
printf("BuzzerState() FAILED\r\n") ;
}
else
{
printf("Buzzer state set to = %u \r\n", dwVal) ;
}
If anyone could provide me with pointers as to how I can create the wrapper so that i can set/call the function in C# (or even the simplest example code), that would be truly appreciated.
解决方案
这篇关于Lib文件C#的托管包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!