回答編集履歴

1

DLL修正方法追加。

2019/07/04 12:48

投稿

menshan
menshan

スコア54

test CHANGED
@@ -10,8 +10,70 @@
10
10
 
11
11
 
12
12
 
13
- 私の環境 Windows10 32bit + .NET Framework4.7 なのすが 32bit は見捨てられているのでしょか?
13
+ ともあれここ使われている修正版 DLL で希望処理がきそです。
14
14
 
15
15
 
16
16
 
17
+ ※以下にDLLの修正方法がありましたので追記しておきます。
18
+
19
+ https://blogs.msdn.microsoft.com/dimeby8/2006/12/05/enumerating-wpd-devices-in-c/
20
+
21
+
22
+
23
+ PortableDeviceApiLib.dll をプロジェクトの参照から削除
24
+
25
+ 再度システムオリジナルの PortableDeviceApiLibを参照に追加
26
+
27
+ obj\Release に Interop.PortableDeviceApiLib.dll ができるので
28
+
29
+ VSのコマンドプロンプトでこれを修正していきます。
30
+
31
+
32
+
33
+ 最初の方に以下の様に書かれていますが
34
+
35
+
36
+
37
+ ```
38
+
39
+ 1.Disassemble the PortableDeviceApi interop using the command -
40
+
41
+ ildasm Interop.PortableDeviceApiLib.dll /out:pdapi.il
42
+
43
+ 2.Open the IL in Notepad and search for the following string
44
+
45
+ instance void GetDevices([in][out] string& marshal( lpwstr) pPnPDeviceIDs,
46
+
47
+ 3.Replace all instances of the string above with the following string
48
+
49
+ instance void GetDevices([in][out] string[] marshal([]) pPnPDeviceIDs,
50
+
51
+ 4.Save the IL and reassemble the interop using the command -
52
+
53
+ ilasm pdapi.il /dll /output=Interop.PortableDeviceApiLib.dll
54
+
55
+ ```
56
+
17
- 何はともあれこで使われている修正版 DLL で希望処理ができそうです。
57
+ 「3」の所をのページの下の方のコメントに書かれている以下様にします。
58
+
59
+ ```
60
+
61
+ instance void GetDevices([in][out] string[] marshal( lpwstr[]) pPnPDeviceIDs,
62
+
63
+ ```
64
+
65
+
66
+
67
+ C#の呼び出し側は同じページに書かれている通りでOKでした。
68
+
69
+ ```
70
+
71
+ uint cDevices = 1;
72
+
73
+ devMgr.GetDevices(null, ref cDevices);
74
+
75
+ string[] deviceIDs = new string[cDevices];
76
+
77
+ devMgr.GetDevices(deviceIDs, ref cDevices);
78
+
79
+ ```