Windows FormsとHULFTを組み合わせて、ファイル転送機能を持った画面を開発しています。
開発環境
Windows10
.NetFramework4.6
HULFT 8
フォームのボタンクリックイベントでHULFTの配信要求を実行後に、コマンドプロンプトから配信キャンセルコマンドを実行すると「指定したファイルIDに該当するものがありません」のようなメッセージが返され、配信のキャンセルができません。
コマンドプロンプトを2つ開いて、プログラムに設定しているのと同じファイルIDで配信要求後に配信キャンセルを行うと正常にキャンセルされます。
プログラムから外部機能を呼び出した場合と、コマンドプロンプトなどから直接起動した場合では何か違うのでしょうか?
この現象の原因がわからず困り果てています…。
何か原因特定のためのアドバイスがありましたらご教授願います。
追記
HULFTの配信要求を行うメソッドの定義です。
フォームのボタンクリックでこのメソッドを呼出し、配信要求~ファイル送信処理は問題無く行えています。
C#
1//配信要求拡張API定義 2[DllImport("hulapi.dll", SetLastError = true, EntryPoint = "utlsendex")] 3 private static extern int _hulapi_utlsendex( 4 string lpszFileID, 5 string lpszHostName, 6 bool bRsend, 7 short nPriority, 8 bool bSync, 9 int nWait, 10 string lpszFileName, 11 IntPtr group, 12 bool bNp, 13 IntPtr lpMsg, 14 int nTransMode 15 ); 16 17 //配信要求拡張APIのラッパーメソッド 18 public static int UtlSendEx(string FileID, string HostName, string FileName, string[] Msgs, string[] exMsgs, bool isAsync, int wait) 19 { 20 IntPtr tagptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 3); 21 uint infoptr = (uint)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * 6); 22 uint[] msgarr = new uint[6]; 23 for (int i = 0; i < 6; i++) 24 { 25 msgarr[i] = (uint)Marshal.AllocHGlobal(51); 26 for (int k = 0; k < 51; k++) 27 { 28 Marshal.WriteByte((IntPtr)(msgarr[i] + k), (byte)0); 29 } 30 if (Msgs != null && i < Msgs.Length) 31 { 32 int offset = 0; 33 foreach (char c in Msgs[i].ToCharArray()) 34 { 35 Marshal.WriteByte((IntPtr)(msgarr[i] + offset), (byte)c); 36 offset++; 37 } 38 } 39 Marshal.WriteInt32((IntPtr)(infoptr + i * Marshal.SizeOf(typeof(IntPtr))), (int)msgarr[i]); 40 } 41 uint exptr = (uint)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * 2); 42 uint[] exarr = new uint[2]; 43 for (int i = 0; i < 2; i++) 44 { 45 exarr[i] = (uint)Marshal.AllocHGlobal(201); 46 for (int k = 0; k < 201; k++) 47 { 48 Marshal.WriteByte((IntPtr)(exarr[i] + k), (byte)0); 49 } 50 if (exMsgs != null && i < exMsgs.Length) 51 { 52 int offset = 0; 53 foreach (char c in exMsgs[i].ToCharArray()) 54 { 55 Marshal.WriteByte((IntPtr)(exarr[i] + offset), (byte)c); 56 offset++; 57 } 58 } 59 Marshal.WriteInt32((IntPtr)(exptr + i * Marshal.SizeOf(typeof(IntPtr))), (int)exarr[i]); 60 } 61 Marshal.WriteInt32(tagptr, 8); 62 Marshal.WriteInt32((IntPtr)((uint)tagptr + Marshal.SizeOf(typeof(IntPtr))), (int)infoptr); 63 Marshal.WriteInt32((IntPtr)((uint)tagptr + Marshal.SizeOf(typeof(IntPtr)) * 2), (int)exptr); 64 try 65 { 66 return _hulapi_utlsendex(FileID, HostName, false, 0, isAsync, wait, FileName, (IntPtr)0, false, tagptr, 0); 67 } 68 catch (DllNotFoundException e) 69 { 70 return -1; 71 } 72 finally 73 { 74 Marshal.FreeHGlobal(tagptr); 75 Marshal.FreeHGlobal((IntPtr)infoptr); 76 for (int i = 0; i < 6; i++) 77 { 78 Marshal.FreeHGlobal((IntPtr)msgarr[i]); 79 } 80 Marshal.FreeHGlobal((IntPtr)exptr); 81 for (int i = 0; i < 2; i++) 82 { 83 Marshal.FreeHGlobal((IntPtr)exarr[i]); 84 } 85 } 86 } 87 88// 配信キャンセルコマンド 89public virtual void CancelUpload(string fileId) 90 { 91 Process process = new Process(); 92 process.StartInfo.FileName = "utlscan"; 93 process.StartInfo.Arguments = string.Format("-f \"{0}\"", fileId); 94 process.Start(); 95 process.WaitForExit(); 96 process.Close(); 97 }
ボタンクリック時の処理
C#
1 Task task2 = Task.Run(() => { 2 UtlSendEx( 3 HULFTのファイルID, 4 送信先のホスト名, 5 送信対象のファイルパス, 6 メッセージ1, 7 メッセージ2, 8 同期、非同期フラグ, 9 同期転送時の処理結果待ち時間 10 ); 11 }); 12 Task task1 = Task.Run(() => { cancelDialog.ShowDialog(); }); 13 task2.Wait(); 14 15 if(cancelDialog != null || !cancelDialog.IsDisposed) 16 { 17 task1.Dispose(); 18 }
キャンセルダイアログの処理
C#
1 public CancelDialog() 2 { 3 InitializeComponent(); 4 } 5 6 private void btnOk_Click(object sender, EventArgs e) 7 { 8 CancelUpLoad(HULFTのファイルID) 9 }


回答1件
あなたの回答
tips
プレビュー