一个关于调用C++的DLL调用的问题。(200分)

  • 主题发起人 主题发起人 tanke
  • 开始时间 开始时间
T

tanke

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在有个DLL库(CP2101.DLL),只能知道DLL中的这么多东西。
Prototype: CP2101_STATUS CP2101_Open( DWORD DeviceNum, HANDLE* Handle )
Prototype: CP2101_STATUS CP2101_GetDevicePid( HANDLE Handle, LPWORD Pid )
Parameters: 1. Handle - Handle to the device to close as returned by CP2101_Open().
      2. Pid - Pointer to a 2-byte value that returns the Product ID of the CP2101 device.

Return Value: CP2101_STATUS = CP2101_SUCCESS,
               CP2101_INVALID_PARAMETER,
               CP2101_INVALID_HANDLE,
               CP2101_DEVICE_IO_FAILED
Type Definitions from C++ Header File CP2101.h
// GetProductString() function flags #define CP2101_RETURN_SERIAL_NUMBER 0x00 #define CP2101_RETURN_DESCRIPTION 0x01 #define CP2101_RETURN_FULL_PATH 0x02
// Return codes #define CP2101_SUCCESS 0x00 #define CP2101_DEVICE_NOT_FOUND 0xFF #define CP2101_INVALID_HANDLE 0x01 #define CP2101_INVALID_PARAMETER 0x02 #define CP2101_DEVICE_IO_FAILED 0x03
// Buffer size limits #define CP2101_MAX_DEVICE_STRLEN 256 #define CP2101_MAX_PRODUCT_STRLEN 126 #define CP2101_MAX_SERIAL_STRLEN 63 #define CP2101_MAX_MAXPOWER 250
// Type definitions typedef int CP2101_STATUS;
typedef char CP2101_DEVICE_STRING[CP2101_MAX_DEVICE_STRLEN];
typedef char CP2101_PRODUCT_STRING[CP2101_MAX_PRODUCT_STRLEN];
typedef char CP2101_SERIAL_STRING[CP2101_MAX_SERIAL_STRLEN];
本人是DELPHI新手,不知如何在DELPHI中调用,请教高手哦。请说明白点
 
最简单的,翻开WINDOWS.PAS看看,看DELPHI是如何调用系统DLL的,同理。
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
// Type definitions
type
CP2101_STATUS = Integer;
const
// GetProductString() function flags
CP2101_RETURN_SERIAL_NUMBER = $00;
CP2101_RETURN_DESCRIPTION = $01;
CP2101_RETURN_FULL_PATH = $02;
// Return codes
CP2101_SUCCESS = $00;
CP2101_DEVICE_NOT_FOUND = $FF;
CP2101_INVALID_HANDLE = $01;
CP2101_INVALID_PARAMETER = $02;
CP2101_DEVICE_IO_FAILED = $03;
// Buffer size limits
CP2101_MAX_DEVICE_STRLEN = 256;
CP2101_MAX_PRODUCT_STRLEN = 126;
CP2101_MAX_SERIAL_STRLEN = 63;
CP2101_MAX_MAXPOWER = 250;
function CP2101_Open( DeviceNum : DWORD;
var Handle : THandle ) : CP2101_STATUS;
stdcall;external 'CP2101.DLL';
function CP2101_GetDevicePid( Handle : THandle;
var id : WORD ) : CP2101_STATUS;stdcall;external 'CP2101.DLL';
implementation
{$R *.dfm}
end.
 
amli,你好,你给的东西运行后没有错,再问一个很菜的问题:
我在一个窗体中有一个文本框和一个按钮,如何在按按钮后调用CP2101_GetDevicePid函数,并使它的反回值在文本框中显示出来?
 
procedure TForm1.Button1Click(Sender: TObject);
var
nStatus : CP2101_STATUS;
hDevice : THandle;
wId : WORD;
begin
nStatus := CP2101_Open( 1, hDevice );
if nStatus = CP2101_SUCCESS then
begin
nStatus := CP2101_GetDevicePid( hDevice, wId );
if nStatus = CP2101_SUCCESS then
begin
Edit1.Text := IntToStr(wId);
end;
//CloseDevice( hDevice );
end;
end;
 
amli
你好,你给的程序我运行了,但不能给出正确结果,我有个同事用VC做了个程序能用,
但我不懂如何在DEKPHI中调用或转成DELPHI中的语法,能再帮我一下吗?
 
问题没能解决,算了,别想别的办法了。
 
后退
顶部