|
分類:[.NET 全般]
Compact Framework で二重起動防止を行いたいと思い下記のようなコードを書きました
Public Declare Function CreateMutex Lib "CoreDll.dll" Alias "CreateMutexW" _ (ByVal lpMutexAttributes As IntPtr, _ ByVal InitialOwner As Boolean, _ ByVal MutexName As String) As IntPtr
'DLLのエラーを取得するAPI Public Declare Function GetLastError Lib "CoreDll.dll" () As Int32
Public Declare Function ReleaseMutex Lib "CoreDll.dll" _ (ByVal hMutex As IntPtr) As Boolean
Public Declare Function CloseHandle Lib "CoreDll.dll" _ (ByVal hObject As IntPtr) As Boolean
<MTAThread()> _ Shared Sub Main() '二重起動抑止 Dim mutexHandle As IntPtr = IntPtr.Zero Dim myName As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name mutexHandle = CreateMutex(IntPtr.Zero, False, myName) If GetLastError() <> 183 Then Application.Run(New LOGIN) Else MessageBox.Show("アプリケーションは既に起動しています。") End If ReleaseMutex(mutexHandle) CloseHandle(mutexHandle) End Sub 'Main
ところが、GetLastErrorが「87」を返してきます。 どこがおかしいのか、お手上げ状態です。ご回答どうぞよろしくお願いします。
|