Skip to content

Commit f25de8a

Browse files
committed
SelectDeviceItem set the Selected Device; DownloadNativeUI use alternative method GetImageDlg
WIAManager.SelectDeviceItem set the Selected Device if finded; Optimized the WIAManager.Find methods; DownloadNativeUI use alternative method GetImageDlg (works with network scanners); Fixed IWiaDevMgr2.GetImageDlg ppItem param type;
1 parent 5b2ad30 commit f25de8a

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

WIAPascal_dpkg.dproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@
154154
</PropertyGroup>
155155
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
156156
<DCC_CBuilderOutput>None</DCC_CBuilderOutput>
157-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
157+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.2.0;InternalName=;LegalCopyright=GPL 3.0;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
158+
<VerInfo_Release>2</VerInfo_Release>
158159
</PropertyGroup>
159160
<ItemGroup>
160161
<DelphiCompile Include="$(MainSource)">

WIA_LH.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ _WiaTransferParams = record
687687
bstrFilename: BSTR;
688688
out plNumFiles: LONG;
689689
out ppbstrFilePaths: PBSTR;
690-
var ppItem: IWiaItem2): HRESULT; stdcall;
690+
var ppItem: PIWiaItem2): HRESULT; stdcall;
691691
end;
692692

693693
implementation

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
WIAPASCAL CHANGE LOG
22
======================
3+
2025/09/05 WIAManager.SelectDeviceItem set the Selected Device if finded;
4+
Optimized the WIAManager.Find methods;
5+
DownloadNativeUI use alternative method GetImageDlg (works with network scanners);
6+
Fixed IWiaDevMgr2.GetImageDlg ppItem param type;
7+
38
2025/08/29 Added Preserve Selected Device in RefreshDeviceList
49

510
2025/06/11 Release 1.0.1;

examples/wia_demo/WIA_Demo_Form.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ procedure TFormWIADemo.btNativeClick(Sender: TObject);
210210
begin
211211
WIASource:= FWia.SelectedDevice;
212212
if (Sender <> nil) then WIASource.SelectedItemIndex:= 0;
213-
aPath:= ExtractFilePath(ParamStr(0));
213+
aPath:= edPath.Text;
214214
c:= WiaSource.DownloadNativeUI(Self.Handle, False, aPath, 'wia_demo', DownloadedFiles);
215215
if (c>0)
216216
then begin

wia.pas

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ TWIAManager = class(TObject)
573573
function FindDevice(AName: String; AManufacturer: String=''): Integer; overload;
574574

575575
//Find a Device by it's ID and Select the given Item
576-
procedure SelectDeviceItem(ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var AIndex: Integer);
576+
procedure SelectDeviceItem(ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var ADeviceItemIndex: Integer);
577577

578578
property DevMgrIntf: WIA_LH.IWiaDevMgr2 read GetDevMgrIntf;
579579

@@ -1381,22 +1381,23 @@ function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APa
13811381
filePaths:= nil;
13821382
itemArray:= nil;
13831383

1384-
//Maybe pSelectedItem. but does not works
1384+
(*
1385+
// Alternative but this works only with usb connected devices
13851386
lres:= pRootItem.DeviceDlg(dlgFlags, hwndParent,
13861387
StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
13871388
rDownload_Count, filePaths, itemArray);
1388-
(* Alternative
1389-
lres:= rOwner.pDevMgr.GetImageDlg(0, StringToOleStr(Self.ID), hwndParent,
1390-
StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
1391-
rDownload_Count, filePaths, itemArray);
13921389
*)
1390+
lres:= rOwner.pDevMgr.GetImageDlg(dlgFlags, StringToOleStr(Self.ID), hwndParent,
1391+
StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
1392+
rDownload_Count, filePaths, itemArray);
1393+
13931394
if (lres = S_OK) then
13941395
begin
13951396
//Copy filePaths to DownloadedFiles and Free elements
13961397
SetLength(DownloadedFiles, rDownload_Count);
13971398
for i:=0 to rDownload_Count-1 do
13981399
begin
1399-
DownloadedFiles[i]:= filePaths^[i];
1400+
DownloadedFiles[i]:= filePaths^[i]; { #todo 2 -oMaxM : Test if OleStrToString is necessary }
14001401

14011402
if UseRelativePath
14021403
then FullPathToRelativePath(rDownload_Path, DownloadedFiles[i]);
@@ -1408,6 +1409,7 @@ function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APa
14081409
end;
14091410

14101411
if (filePaths <> nil) then CoTaskMemFree(filePaths);
1412+
//if (itemArray <> nil) then CoTaskMemFree(itemArray); //the documentation says to release it but we always have Exception
14111413
end;
14121414
end;
14131415

@@ -3198,15 +3200,13 @@ procedure TWIAManager.RefreshDeviceList(PreserveSelected: Boolean);
31983200
function TWIAManager.FindDevice(AID: String): Integer;
31993201
var
32003202
i :Integer;
3201-
curDev :TWIADevice;
32023203

32033204
begin
32043205
Result :=-1;
32053206
for i:=0 to DevicesCount-1 do
32063207
begin
3207-
curDev :=Devices[i];
3208-
if (curDev <> nil) and
3209-
(curDev.ID = AID)
3208+
if (rDeviceList[i] <> nil) and
3209+
(rDeviceList[i].ID = AID)
32103210
then begin Result:=i; break; end;
32113211
end;
32123212
end;
@@ -3219,57 +3219,55 @@ function TWIAManager.FindDevice(Value: TWIADevice): Integer;
32193219
Result :=-1;
32203220
if (Value <> nil)
32213221
then for i:=0 to DevicesCount-1 do
3222-
if (Devices[i] = Value) then begin Result:=i; break; end;
3222+
if (rDeviceList[i] = Value) then begin Result:=i; break; end;
32233223
end;
32243224

32253225
function TWIAManager.FindDevice(AName: String; AManufacturer: String): Integer;
32263226
var
32273227
i :Integer;
3228-
curDev :TWIADevice;
32293228

32303229
begin
32313230
Result :=-1;
32323231
for i:=0 to DevicesCount-1 do
32333232
begin
3234-
curDev:=Devices[i];
32353233
{ #todo -oMaxM : if there is more identical device? }
3236-
if (curDev <> nil) and
3237-
(curDev.Name = AName) and
3238-
((AManufacturer <> '') and (curDev.Manufacturer = AManufacturer))
3234+
if (rDeviceList[i] <> nil) and
3235+
(rDeviceList[i].Name = AName) and
3236+
((AManufacturer <> '') and (rDeviceList[i].Manufacturer = AManufacturer))
32393237
then begin Result:=i; break; end;
32403238
end;
32413239
end;
32423240

3243-
procedure TWIAManager.SelectDeviceItem(ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var AIndex: Integer);
3241+
procedure TWIAManager.SelectDeviceItem(ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var ADeviceItemIndex: Integer);
32443242
var
32453243
i :Integer;
3246-
curDev :TWIADevice;
32473244

32483245
begin
32493246
ADevice:= nil;
3250-
AIndex:= -1;
3247+
ADeviceItemIndex:= -1;
32513248

32523249
try
32533250
for i:=0 to DevicesCount-1 do
32543251
begin
3255-
curDev:= Devices[i];
3256-
3257-
if (curDev <> nil) and
3258-
(curDev.ID = ADeviceID) then
3252+
if (rDeviceList[i] <> nil) and
3253+
(rDeviceList[i].ID = ADeviceID) then
32593254
begin
3260-
ADevice:= curDev;
3255+
ADevice:= rDeviceList[i];
32613256

3262-
if curDev.SelectItem(ADeviceItem)
3263-
then AIndex:= ADevice.SelectedItemIndex
3264-
else AIndex:= -1;
3257+
if ADevice.SelectItem(ADeviceItem)
3258+
then begin
3259+
rSelectedDeviceIndex:= i;
3260+
ADeviceItemIndex:= ADevice.SelectedItemIndex;
3261+
end
3262+
else ADeviceItemIndex:= -1;
32653263

32663264
break;
32673265
end;
32683266
end;
32693267

32703268
except
32713269
ADevice:= nil;
3272-
AIndex:= -1;
3270+
ADeviceItemIndex:= -1;
32733271
end;
32743272
end;
32753273

wiapascal_pkg.lpk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</CompilerOptions>
1919
<Description Value="WIA Scanner features for Free Pascal and Delphi"/>
2020
<License Value="GPL 3.0"/>
21-
<Version Major="1" Release="1"/>
21+
<Version Major="1" Release="2"/>
2222
<Files>
2323
<Item>
2424
<Filename Value="WIA_LH.pas"/>

0 commit comments

Comments
 (0)