質問編集履歴

4

呼出し処理を追加

2019/02/11 08:53

投稿

youkan_17
youkan_17

スコア12

test CHANGED
File without changes
test CHANGED
@@ -235,3 +235,69 @@
235
235
  }
236
236
 
237
237
  ```
238
+
239
+ ボタンクリック時の処理
240
+
241
+ ```C#
242
+
243
+ Task task2 = Task.Run(() => {
244
+
245
+ UtlSendEx(
246
+
247
+ HULFTのファイルID,
248
+
249
+ 送信先のホスト名,
250
+
251
+ 送信対象のファイルパス,
252
+
253
+ メッセージ1,
254
+
255
+ メッセージ2,
256
+
257
+ 同期、非同期フラグ,
258
+
259
+ 同期転送時の処理結果待ち時間
260
+
261
+ );
262
+
263
+ });
264
+
265
+ Task task1 = Task.Run(() => { cancelDialog.ShowDialog(); });
266
+
267
+ task2.Wait();
268
+
269
+
270
+
271
+ if(cancelDialog != null || !cancelDialog.IsDisposed)
272
+
273
+ {
274
+
275
+ task1.Dispose();
276
+
277
+ }
278
+
279
+ ```
280
+
281
+ キャンセルダイアログの処理
282
+
283
+ ```C#
284
+
285
+ public CancelDialog()
286
+
287
+ {
288
+
289
+ InitializeComponent();
290
+
291
+ }
292
+
293
+
294
+
295
+ private void btnOk_Click(object sender, EventArgs e)
296
+
297
+ {
298
+
299
+ CancelUpLoad(HULFTのファイルID)
300
+
301
+ }
302
+
303
+ ```

3

キャンセル処理のコード追加

2019/02/11 08:53

投稿

youkan_17
youkan_17

スコア12

test CHANGED
File without changes
test CHANGED
@@ -212,4 +212,26 @@
212
212
 
213
213
  }
214
214
 
215
+
216
+
217
+ // 配信キャンセルコマンド
218
+
219
+ public virtual void CancelUpload(string fileId)
220
+
221
+ {
222
+
223
+ Process process = new Process();
224
+
225
+ process.StartInfo.FileName = "utlscan";
226
+
227
+ process.StartInfo.Arguments = string.Format("-f \"{0}\"", fileId);
228
+
229
+ process.Start();
230
+
231
+ process.WaitForExit();
232
+
233
+ process.Close();
234
+
235
+ }
236
+
215
237
  ```

2

配信要求処理のソース追加

2019/02/11 07:47

投稿

youkan_17
youkan_17

スコア12

test CHANGED
File without changes
test CHANGED
@@ -29,3 +29,187 @@
29
29
  この現象の原因がわからず困り果てています…。
30
30
 
31
31
  何か原因特定のためのアドバイスがありましたらご教授願います。
32
+
33
+
34
+
35
+ 追記
36
+
37
+ HULFTの配信要求を行うメソッドの定義です。
38
+
39
+ フォームのボタンクリックでこのメソッドを呼出し、配信要求~ファイル送信処理は問題無く行えています。
40
+
41
+ ```C#
42
+
43
+ //配信要求拡張API定義
44
+
45
+ [DllImport("hulapi.dll", SetLastError = true, EntryPoint = "utlsendex")]
46
+
47
+ private static extern int _hulapi_utlsendex(
48
+
49
+ string lpszFileID,
50
+
51
+ string lpszHostName,
52
+
53
+ bool bRsend,
54
+
55
+ short nPriority,
56
+
57
+ bool bSync,
58
+
59
+ int nWait,
60
+
61
+ string lpszFileName,
62
+
63
+ IntPtr group,
64
+
65
+ bool bNp,
66
+
67
+ IntPtr lpMsg,
68
+
69
+ int nTransMode
70
+
71
+ );
72
+
73
+
74
+
75
+ //配信要求拡張APIのラッパーメソッド
76
+
77
+ public static int UtlSendEx(string FileID, string HostName, string FileName, string[] Msgs, string[] exMsgs, bool isAsync, int wait)
78
+
79
+ {
80
+
81
+ IntPtr tagptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 3);
82
+
83
+ uint infoptr = (uint)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * 6);
84
+
85
+ uint[] msgarr = new uint[6];
86
+
87
+ for (int i = 0; i < 6; i++)
88
+
89
+ {
90
+
91
+ msgarr[i] = (uint)Marshal.AllocHGlobal(51);
92
+
93
+ for (int k = 0; k < 51; k++)
94
+
95
+ {
96
+
97
+ Marshal.WriteByte((IntPtr)(msgarr[i] + k), (byte)0);
98
+
99
+ }
100
+
101
+ if (Msgs != null && i < Msgs.Length)
102
+
103
+ {
104
+
105
+ int offset = 0;
106
+
107
+ foreach (char c in Msgs[i].ToCharArray())
108
+
109
+ {
110
+
111
+ Marshal.WriteByte((IntPtr)(msgarr[i] + offset), (byte)c);
112
+
113
+ offset++;
114
+
115
+ }
116
+
117
+ }
118
+
119
+ Marshal.WriteInt32((IntPtr)(infoptr + i * Marshal.SizeOf(typeof(IntPtr))), (int)msgarr[i]);
120
+
121
+ }
122
+
123
+ uint exptr = (uint)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * 2);
124
+
125
+ uint[] exarr = new uint[2];
126
+
127
+ for (int i = 0; i < 2; i++)
128
+
129
+ {
130
+
131
+ exarr[i] = (uint)Marshal.AllocHGlobal(201);
132
+
133
+ for (int k = 0; k < 201; k++)
134
+
135
+ {
136
+
137
+ Marshal.WriteByte((IntPtr)(exarr[i] + k), (byte)0);
138
+
139
+ }
140
+
141
+ if (exMsgs != null && i < exMsgs.Length)
142
+
143
+ {
144
+
145
+ int offset = 0;
146
+
147
+ foreach (char c in exMsgs[i].ToCharArray())
148
+
149
+ {
150
+
151
+ Marshal.WriteByte((IntPtr)(exarr[i] + offset), (byte)c);
152
+
153
+ offset++;
154
+
155
+ }
156
+
157
+ }
158
+
159
+ Marshal.WriteInt32((IntPtr)(exptr + i * Marshal.SizeOf(typeof(IntPtr))), (int)exarr[i]);
160
+
161
+ }
162
+
163
+ Marshal.WriteInt32(tagptr, 8);
164
+
165
+ Marshal.WriteInt32((IntPtr)((uint)tagptr + Marshal.SizeOf(typeof(IntPtr))), (int)infoptr);
166
+
167
+ Marshal.WriteInt32((IntPtr)((uint)tagptr + Marshal.SizeOf(typeof(IntPtr)) * 2), (int)exptr);
168
+
169
+ try
170
+
171
+ {
172
+
173
+ return _hulapi_utlsendex(FileID, HostName, false, 0, isAsync, wait, FileName, (IntPtr)0, false, tagptr, 0);
174
+
175
+ }
176
+
177
+ catch (DllNotFoundException e)
178
+
179
+ {
180
+
181
+ return -1;
182
+
183
+ }
184
+
185
+ finally
186
+
187
+ {
188
+
189
+ Marshal.FreeHGlobal(tagptr);
190
+
191
+ Marshal.FreeHGlobal((IntPtr)infoptr);
192
+
193
+ for (int i = 0; i < 6; i++)
194
+
195
+ {
196
+
197
+ Marshal.FreeHGlobal((IntPtr)msgarr[i]);
198
+
199
+ }
200
+
201
+ Marshal.FreeHGlobal((IntPtr)exptr);
202
+
203
+ for (int i = 0; i < 2; i++)
204
+
205
+ {
206
+
207
+ Marshal.FreeHGlobal((IntPtr)exarr[i]);
208
+
209
+ }
210
+
211
+ }
212
+
213
+ }
214
+
215
+ ```

1

2019/02/11 07:45

投稿

youkan_17
youkan_17

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,16 @@
1
1
  Windows FormsとHULFTを組み合わせて、ファイル転送機能を持った画面を開発しています。
2
+
3
+
4
+
5
+ 開発環境
6
+
7
+ Windows10
8
+
9
+ .NetFramework4.6
10
+
11
+ HULFT 8
12
+
13
+
2
14
 
3
15
 
4
16
 
@@ -10,6 +22,10 @@
10
22
 
11
23
 
12
24
 
25
+ プログラムから外部機能を呼び出した場合と、コマンドプロンプトなどから直接起動した場合では何か違うのでしょうか?
26
+
27
+
28
+
13
29
  この現象の原因がわからず困り果てています…。
14
30
 
15
31
  何か原因特定のためのアドバイスがありましたらご教授願います。