原代码如下:
strClassName = "datachange"
m_hMutex = OpenMutex(MUTEX_ALL_ACCESS, False, strClassName)
If m_hMutex = 0 Then
m_hMutex = CreateMutex(0, True, strClassName)
Else
MsgBox "datachange 已经存在!", vbOKOnly
End
End If
当我第一个进程执行时,我通过createmutex创建一个strclassname,保证系统里面只有一个我写的该应用程序执行,但是,第一个进程没有关闭,第二个进程起来的时候,使用OPENMUTEX函数得到为0?
我该如何取到我通过createmutex创建的strclassname?
请指教!!
strClassName = "datachange"
m_hMutex = OpenMutex(MUTEX_ALL_ACCESS, False, strClassName)
If m_hMutex = 0 Then
m_hMutex = CreateMutex(0, True, strClassName)
Else
MsgBox "datachange 已经存在!", vbOKOnly
End
End If
当我第一个进程执行时,我通过createmutex创建一个strclassname,保证系统里面只有一个我写的该应用程序执行,但是,第一个进程没有关闭,第二个进程起来的时候,使用OPENMUTEX函数得到为0?
我该如何取到我通过createmutex创建的strclassname?
请指教!!
解决方案 »
- access与sql之间进行 not in 查询
- Word文件中插入了一个PowerPoint、Excel对象的问题
- 数据更新为何总是只更新第一条记录?
- 如何在DataGrid控件中修改数据且刷新数据
- 为何OpenProcess()老是返回0,我明明用shell()打开一个窗口嘛
- 配置文件节名删除问题
- 获取服务器上数据库的表名问题,在线等待!
- 200分求助!!!SQL2000连接问题!!!在线等待!!参与者有分!(第二贴)
- Zee请进来拿分
- fuxc(Michael) 请进来拿分,谢谢你的类OUTLOO按纽控件,真是好用,给你100分,进来就加,其他朋友也可以看看,支持真彩和换背景色的
- 导出日期字段到excel里面出错的问题
- 数据库中有上百万条记录,请问如何才能最快地访问数据库中的数据。。
当然你用OPEN来判断其存在性也可以但是不该用MUTEX_ALL_ACCESS而是该用SYNCHRONIZE
你创建后检查err对象的DLLERROR看,返回的就是我说的那个错误码。
'Set the project's startup object to 'Sub Main' (-> Project -> Project Properties -> General Tab -> Startup Object)
Public Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const ERROR_ALREADY_EXISTS = 183&
Private Sub Main()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
' -> code by Raist Lin
Dim sa As SECURITY_ATTRIBUTES
sa.bInheritHandle = 1
sa.lpSecurityDescriptor = 0
sa.nLength = Len(sa)
'Try to create a new Mutex
Debug.Print CreateMutex(sa, 1, App.Title)
Debug.Print Err.LastDllError
'Check if the function was succesfull
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
'More than one instance detected
MsgBox "More than one instance"
Else
'No other instance detected...
'Your program-load code here
End If
End Sub
http://www.zjol.com.cn/vbbible/software/program/vb/ccw/htmapi73.htm