问题描述
我已经导入了 kernel32
库.所以,我有 createMutex
函数可用,但我不太确定各种参数和返回值.
I have imported the kernel32
library. So, I have the createMutex
function available but I am not quite sure of the various parameters and return values.
这是经典的 Visual Basic,而不是 Visual Basic.NET,但我可能可以以答案的形式使用任何一种语言.
This is classic Visual Basic, not Visual Basic.NET but I can probably work with either language in the form of an answer.
推荐答案
VB 代码如下所示:
hMutex = CreateMutex(ByVal 0&, 1, ByVal 0&)
第一个参数是指向 SECURITY_ATTRIBUTES
结构的指针.如果你不知道它是什么,你就不需要它.传递 NULL (0).
The first parameter is a pointer to an SECURITY_ATTRIBUTES
structure. If you don't know what it is, you don't need it. Pass NULL (0).
第二个参数是 TRUE
(非零或 1),如果调用线程应该获得互斥锁的所有权.FALSE
否则.
The second parameter is TRUE
(non-zero, or 1) if the calling thread should take ownership of the mutex. FALSE
otherwise.
第三个参数是互斥锁名称,可能为 NULL (0),如图所示.如果您需要一个命名的互斥体,请将名称(任何唯一的)传入.不确定 VB
包装器是否封送长度前缀 VB
字符串类型 (BSTR
) 转换为以空字符结尾的 Ascii/Unicode 字符串,否则,您将需要这样做,并且有很多示例.
The third parameter is the mutex name and may be NULL (0), as shown. If you need a named mutex, pass the name (anything unique) in. Not sure whether the VB
wrapper marshals the length-prefixed VB
string type (BSTR
) over to a null-terminated Ascii/Unicode string if not, you'll need to do that and numerous examples are out there.
祝你好运!
这篇关于如何在 Visual Basic 中使用互斥锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!