.net调用dll出错

Firestone2003 2004-03-29 11:45:14

ePass1000 Full ActiveX Control Reference Manual Version 2.0
OpenDevice
The OpenDevice method finds and opens an ePass1000 for exclusive access, and create a session between application and device for further operation.

HRESULT
OpenDevice(
[in]long lFlags,
[in]unsigned char* pAppID
);
Requirement
epas_CreateContext

Parameters
lFlags
[in]This parameter defines a bit mask of options for opening a device. You may use bit-wise OR operation to select more than one option. This parameter can be a combination of one or more of the following flags: Flag Meaning
EPAS_OPEN_FIRST Open the first found device. This flag can be combined with EPAS_OPEN_BY_NAME, EPAS_OPEN_BY_GUID or EPAS_OPEN_BY_GUID_STR.
EPAS_OPEN_NEXT Open the next device. This flag can be combined with EPAS_OPEN_BY_NAME, EPAS_OPEN_BY_GUID or EPAS_OPEN_BY_GUID_STR.
EPAS_OPEN_CURRENT Open the currently opened device. This flag can NOT be combined with other flags.
EPAS_OPEN_SPECIFIC Open the device, that has same serial number value as which specified by pAppID parameter. This flag can NOT be combined with other flags.
EPAS_OPEN_BY_NAME Open the device containing a directory name pointed to by pAppID. This parameter may be combined with EPAS_OPEN_FIRST or EPAS_OPEN_NEXT.
EPAS_OPEN_BY_GUID Open the device containing a directory GUID as specified by pAppID. This flag must combined with EPAS_OPEN_FIRST or EPAS_OPEN_NEXT.
EPAS_OPEN_BY_GUID_STR Open the device containing a directory GUID as specified by pAppID. This flag must combined with EPAS_OPEN_FIRST or EPAS_OPEN_NEXT.

pAppID
[in]This optional parameter provide additional information for the open. This parameter is only used if one of the following flags is assigned. If none of the flags below are assigned, pAppID should be set to NULL. Flag Meaning
EPAS_OPEN_SPECIFIC pAppID point to an array of two unsigned longs which specified serial number of the device to be opened. Use GetProperty function to obtain a device's serial number.
EPAS_OPEN_BY_NAME pAppID point to a NULL terminated string that specifies the Application Directory Name to open. If a device is opened, the current directory will be set to the directory ID defined by the Application Directory Name.
EPAS_OPEN_BY_GUID pAppID point to an array of 16 bytes that specified the Application Directory GUID to open. If a device is opened, the current directory will be set to the directory ID defined by the Application Directory GUID.
EPAS_OPEN_BY_GUID_STR pAppID point to a NULL terminated string that specifies the Application Directory GUID to open. If a device is opened, the current directory will be set to the directory ID defined by the Application Directory GUID. The string format is "{xxxxxxxx - xxxx - xxxx - xxxx - xxxxxxxxxxxx}". Dashes and braces are optional.


Remarks
The order of devices opened (first and next) is based on the order they were detected by the system. To enumerate all devices connected to the system, use EPAS_OPEN_FIRST and EPAS_OPEN_NEXT until FT_UNIT_NOT_FOUND is returned.

Application access to ePass1000 is exclusive. Only one application can open an ePass1000 at one time. If any other application attempt to open this ePass1000, will get return code FT_DEVICE_IN_USE.

You can open specific ePass1000 by combining EPAS_OPEN_FIRST, EPAS_OPEN_NEXT flags with EPAS_OPEN_BY_NAME , EPAS_OPEN_BY_GUID, or EPAS_OPEN_BY_GUID_STR.

If you known serial number of the ePass1000 you intend to open, use EPAS_OPEN_SPECIFIC.

Return Values
If the function succeeds, FT_SUCCESS returned.

If the library failed to open the device driver, FT_CANNOT_OPEN_DRIVER is returned.

If the library do not support version of the driver, FT_INVALID_DRVR_VERSION is returned.

If there is no device connected to the system currently, FT_UNIT_NOT_FOUND is returned.

If the device is already opened by another application, FT_DEVICE_IN_USE is returned.

For a list of all return codes, see Error Code Values.




参数的定义private Byte[] epsAppName = new Byte[EPAS_APP_NAME_SIZE];

public const int EPAS_OPEN_FIRST = 0x1;

调用ePass.OpenDevice(EPAS_OPEN_FIRST, ref epsAppName[0]);对象浏览器里的函数

但是调用出错,调用没有参数传递的就没有问题!
我知道是参数的问题但是不知道怎么改???
大家帮帮忙a!
...全文
227 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqchen79 2004-03-30
  • 打赏
  • 举报
回复
1. According to the spec, EPAS_OPEN_FIRST doesn't require a second parameter.

2. Simple use byte[] as the second parameter, .NET knows how to marshal a byte[] into unsigned char* . According to the spec, you have to initialize the second parameter to certain value before make the function call. (Two long, or String or something else).
Firestone2003 2004-03-30
  • 打赏
  • 举报
回复
谢谢大家,已经解决了!
马上给分!
fengyecsdn 2004-03-29
  • 打赏
  • 举报
回复
参数使用了在C#中不合法的数据格式

需要你强制转换定义类型 或者自定义参数格式
具体常用的类型转换我现在记不住几个 回去我给你找找C++常用的的参数转换C#
你先自己找找

另,参数是结构或者类型的时候
还要强制指定结构成员的顺序
而且还可能涉及不安全代码


以上的具体解说 网上有很多文章
很容易找到

我回家以后给你找些发上来
favornwpu 2004-03-29
  • 打赏
  • 举报
回复
帮你顶一下
newman0708 2004-03-29
  • 打赏
  • 举报
回复
调用C#的dll我会,但是调用非C#的dll,还没有学会。

帮你顶
Firestone2003 2004-03-29
  • 打赏
  • 举报
回复
怎么没有人ding啊!!
又要结不了帖了

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧