كيفية استخدام تابع ضمن ملف dll
#1
السلام عليكم
لدي مشكله في التعامل مع تابع ضمن ملف SNAPI.dll التابع موصف كالآتي:
PHP كود :
SNAPI_Init Lifecycle Command
Initializing command that registers the window that will receive Windows messages from the library
. It returns
an 
array of the Symbol Image scanners that are connected to the host through USB. No command is sent to
the scanner during this API call
.
Syntax
SNAPIDLL_API int __stdcall SNAPI_Init
(
HWND hwnd,
HANDLE *DeviceHandles,
int *NumDevices);
Parameters
hwnd
The handle of the window whose procedure will receive Windows messages from the library
.
DeviceHandles
A pointer to an 
array that will store handles for the devices that are found.
NumDevices
Pointer to the number of devices that were found
. 
الرجاء معرفه ماهو قيمة المتغير HWND التي يجب وضعها
ولكم جزيل الشكر
الرد
#2
للتوضيح اكثر استخدمت الكود التالي:
PHP كود :
unit Unit1;

interface

uses
  Windows
, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  
Dialogs, StdCtrls;

type
  TForm1 
= class(TForm)
    
Button1: TButton;
    
procedure Button1Click(Sender: TObject);
  private
    { Private 
declarations }
  public
    { Public 
declarations }
  
end;
  function 
SNAPI_Init(hwnd: HWND;var DeviceHandles:  array of Integer; var NumDevices: integer): Integer;external 'SNAPI.dll';

var
  
Form1: TForm1;
implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var 
dh : array[0..9] of integer;
    
i,l,n:integer;
    
vm_hWnd :TMessage;
begin
 l
:=0;
 for 
I := 0 to 9 do
 
dh[i] := 0;
 
n:=0;
 
l:= SNAPI_Init(Form1.Handle,dh,n);
end;


end. 
وظهر عندي رسالة خطأ كالأتي:
access violation at address 10004f61 in module 'snapi.dll'. write of address 000000
الرد
#3
السلام عليكم...

أعتقد أن المشكلة في تصريح الدالة SNAPI_Init من حيث تعريف البارامترات. فالشرح المرفق يبين أن البارامتر الثاني و الثالث يجب أن يكونا مؤشرين (Pointers). فالثاني مؤشر إلى مصفوفة من النوع Handle (في دلفي THandle) و الثالث مؤشر إلى متغير من النوع int (في دلفي Integer).

= قبل التصريح عن الدالة عرف نوع مصفوفة من النوع THandle و نوع مؤشر (Pointer) لها.

كود :
TDHArray = array of THandle; PDHArray = ^TDHArray;

= اجعل التصريح عن الدالة كالتالي. و بما أن التعريف الأصلي للدالة يحتوي على عبارة stdcall فمن المهم جداً تضمين هذه العبارة في تصريح دلفي أيضاً:

كود :
function SNAPI_Init(hwnd: HWND; DeviceHandles: PDHArray; NumDevices: PInteger): Integer; stdcall; external 'SNAPI.dll';

= في إجراء الزر غير تعريف المصفوفة كالتالي:

كود :
dh: TDHArray;

= ثم قم بتحديد حجمها و تهيئتها:

كود :
SetLength(dh, 10); for i := 0 to 9 do dh[i] := 0; n := 0;

= أخيراً يكون الاستدعاء كالتالي:

كود :
l := SNAPI_Init(Form1.Handle, @dh, @n);

* إذا لم ينجح فجرب إرسال عنوان أول عنصر في المصفوفة:

كود :
l := SNAPI_Init(Form1.Handle, @dh[0], @n);
و السلام عليكم.
الرد
#4
شكرا اخي ناجي
تم تنفيذ التابع بنجاح واطلب تفسيرك إذا كان بالامكان للتابعين التاليين ضمن نفس المكتبة وشكرا:
التابع الأول SNAPI_SnapShot:
PHP كود :
SNAPI_SnapShot Host to Scanner Command
If the scanner supports imaging, this sends a command to the scanner to enter Image Capture Mode. The
scanner remains in Image Capture Mode until the trigger is pulled 
(physically or with a call to
SNAPI_PullTrigger
) and an image is captured, or until the timeout for a trigger pull expires. The scanner then
returns to Decode Mode
.
If 
the trigger is pulled, the image data is sent to the DLL. WM_XFERSTATUS is sent to the host application with
information about the size of the image
.
When the first transfer status message is received, the host application should provide a destination buffer for
the image by calling SNAPI_SetImageBuffer. After the entire image is transferred from the scanner to the DLL,
the application receives a Windows message indicating that the image data was stored.
Syntax
SNAPIDLL_API int __stdcall SNAPI_SnapShot
(
HANDLE DeviceHandle);
Parameters
DeviceHandle
Handle of the device used in the call to SNAPI_Connect
. 

التابع الآخر :
PHP كود :
SNAPI_GetSerialNumber Data Request Command
This command returns the serial number of the connected scanner
. No command is sent to scanner.
Syntax
SNAPIDLL_API int __stdcall SNAPI_GetSerialNumber
(
HANDLE DeviceHandle,
unsigned char *SerialNo);
Parameters
DeviceHandle
Handle of the device used in the call to SNAPI_Connect
.
SerialNo
Pointer to a buffer to receive serial number of connected scanner
. 

في التابع الثاني كيفية معرفة ماهي قيمه المتغير
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم