怎样防止一个程序运行多个实例?请写一段代码。
解决方案 »
- 新手请教几行代码的含义。谢谢。
- 我的好友马克思(大胡子)说他‘我得罪了奸党,被全站封禁了’,为什么?,谁给个答案
- 用loadpicture的方式能将picture里的图片放大缩小吗?
- 帮帮我
- 小弟今年6月份毕业,学习编程数5年,可是学习实在是不可思意!前途一片黑暗!希望大家指个明路。。。。
- 关于word书签的问题,急急急!!!
- 关于窗体和模块的组合
- 急求,实现保存问题(小弟分数不多了只能给这么多了)
- 如何在pictruebox里用代码写字,使字成为pic的image中的一部分
- 讨论:你是否会用专门的Flash播放器/浏览器来观看Flash动画?为什么?回答最佳者给10分。
- 创建对象实例的问题。
- 如何判断一个对象变量是否用New申请了对象实例?
'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
用互斥体来限制程序的多次运行如果用app.PrevInstance 也可以,但是编译后的程序如果在同一目录下是可以的
如果在不同目录,则无效