本文整理汇总了C++中CreateMutexA函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateMutexA函数的具体用法?C++ CreateMutexA怎么用?C++ CreateMutexA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateMutexA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateMutex_12_bad
void CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateMutex_12_bad()
{
if(globalReturnsTrueOrFalse())
{
{
HANDLE hMutex = NULL;
hMutex = CreateMutexA(NULL, FALSE, NULL);
/* FLAW: If CreateMutexA() failed, the return value will be NULL,
but we are checking to see if the return value is INVALID_HANDLE_VALUE */
if (hMutex == INVALID_HANDLE_VALUE)
{
exit(1);
}
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hMutex);
}
}
else
{
{
HANDLE hMutex = NULL;
hMutex = CreateMutexA(NULL, FALSE, NULL);
/* FIX: check for the correct return value */
if (hMutex == NULL)
{
exit(1);
}
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hMutex);
}
}
}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:34,代码来源:CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateMutex_12.c
示例2: good1
/* good1() uses the GoodSink on both sides of the "if" statement */
static void good1()
{
if(globalReturnsTrueOrFalse())
{
{
HANDLE hMutex = NULL;
hMutex = CreateMutexA(NULL, FALSE, NULL);
/* FIX: check for the correct return value */
if (hMutex == NULL)
{
exit(1);
}
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hMutex);
}
}
else
{
{
HANDLE hMutex = NULL;
hMutex = CreateMutexA(NULL, FALSE, NULL);
/* FIX: check for the correct return value */
if (hMutex == NULL)
{
exit(1);
}
/* We'll leave out most of the implementation since it has nothing to do with the CWE
* and since the checkers are looking for certain function calls anyway */
CloseHandle(hMutex);
}
}
}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:34,代码来源:CWE253_Incorrect_Check_of_Function_Return_Value__char_w32CreateMutex_12.c
示例3: sprintf_s
// =================================================================
// Texture access mutex locks
//
// A general mutex lock for DirectX 9 and for DirectX11 textures
//
// =================================================================
bool spoutDirectX::CreateAccessMutex(const char *name, HANDLE &hAccessMutex)
{
DWORD errnum;
char szMutexName[300]; // name of the mutex
// Create the mutex name to control access to the shared texture
sprintf_s((char*)szMutexName, 300, "%s_SpoutAccessMutex", name);
// Create or open mutex depending, on whether it already exists or not
hAccessMutex = CreateMutexA ( NULL, // default security
FALSE, // No initial owner
(LPCSTR)szMutexName);
if (hAccessMutex == NULL) {
return false;
}
else {
errnum = GetLastError();
if(errnum == ERROR_INVALID_HANDLE) {
printf("access mutex [%s] invalid handle\n", szMutexName);
}
}
return true;
}
示例4: publish_session_bus
static gboolean
publish_session_bus (const char *address)
{
HANDLE init_mutex;
init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX);
published_daemon_mutex = CreateMutexA (NULL, FALSE, DBUS_DAEMON_MUTEX);
if (WaitForSingleObject (published_daemon_mutex, 10 ) != WAIT_OBJECT_0)
{
release_mutex (init_mutex);
CloseHandle (published_daemon_mutex);
published_daemon_mutex = NULL;
return FALSE;
}
published_shared_mem = set_shm (DBUS_DAEMON_ADDRESS_INFO, address);
if (!published_shared_mem)
{
release_mutex (init_mutex);
CloseHandle (published_daemon_mutex);
published_daemon_mutex = NULL;
return FALSE;
}
release_mutex (init_mutex);
return TRUE;
}
示例5: shutdown
void ofxOscReceiver::setup( int listen_port )
{
// if we're already running, shutdown before running again
if ( listen_socket )
shutdown();
// create the mutex
#ifdef TARGET_WIN32
mutex = CreateMutexA( NULL, FALSE, NULL );
#else
pthread_mutex_init( &mutex, NULL );
#endif
// create socket
socketHasShutdown = false;
listen_socket = new UdpListeningReceiveSocket( IpEndpointName( IpEndpointName::ANY_ADDRESS, listen_port ), this );
// start thread
#ifdef TARGET_WIN32
thread = CreateThread(
NULL, // default security attributes
0, // use default stack size
&ofxOscReceiver::startThread, // thread function
(void*)this, // argument to thread function
0, // use default creation flags
NULL); // we don't the the thread id
#else
pthread_create( &thread, NULL, &ofxOscReceiver::startThread, (void*)this );
#endif
}
示例6: CreateMutexA
bool CourseTrainerApp::OnInit()
{
#ifdef WINDOWS
CreateMutexA(0, FALSE, "Local\\$myprogram$"); // try to create a named mutex
if(GetLastError() == ERROR_ALREADY_EXISTS) // did the mutex already exist?
{
wxMessageDialog(NULL, "Another process already running.","Error").ShowModal();
return false;
}
#else
pid_t pid = getpid();
std::stringstream command;
command << "ps -eo pid,comm | grep CourseTrainer | grep -v " << pid;
int isRuning = system(command.str().c_str());
if (isRuning==0)
{
wxMessageDialog(NULL, "Another process already running.","Error").ShowModal();
return false;
}
#endif // WINDOWS
frame = new CourseTrainerFrame(0L, _("Course Calculatings"));
WelcomeScreen* dialog=new WelcomeScreen(nullptr,wxID_ANY,"Identification",frame);
dialog->Show();
return true;
}
示例7: _name
NamedMutexImpl::NamedMutexImpl(const std::string& name):
_name(name)
{
_mutex = CreateMutexA(NULL, FALSE, _name.c_str());
if (!_mutex)
throw SystemException("cannot create named mutex", _name);
}
示例8: mutexNew
/**
* Mutex
*/
LPDM_MUTEX mutexNew(const char *name)
{
LPDM_MUTEX m = NULL;
#ifdef WIN32
m = CreateMutexA(NULL, FALSE, name);
if(m == NULL){
DWORD dwError = GetLastError();
if(dwError == ERROR_ACCESS_DENIED)
m = OpenMutexA(SYNCHRONIZE, FALSE, name);
}
#else
pthread_mutexattr_t mutexattr;
pthread_mutexattr_init(&mutexattr);
m = (LPDM_MUTEX)malloc(sizeof(DM_MUTEX));
m->context = NULL;
if(name){
int mutexexist = 0;
mutexexist = shm_exist(name);
m->context = mmapOpen(name, sizeof(pthread_mutex_t));
m->mutex = (pthread_mutex_t*)m->context->data;
if(mutexexist)
return m;
pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED);
pthread_mutexattr_setrobust(&mutexattr, PTHREAD_MUTEX_ROBUST);
}
else
m->mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(m->mutex, &mutexattr);
pthread_mutexattr_destroy(&mutexattr);
#endif
return m;
}
示例9: FT_EXPORT
//
// Create a memory-mapping to the Freetrack data.
// It contains the tracking data, a handle to the main-window and the program-name of the Game!
//
//
FT_EXPORT(bool) FTCreateMapping(void)
{
//
// Memory-mapping already exists!
//
if ( pMemData != NULL ) {
return true;
}
dbg_report("FTCreateMapping request (pMemData == NULL).\n");
//
// A FileMapping is used to create 'shared memory' between the FTClient and the FTServer.
//
// Try to create a FileMapping to the Shared Memory. This is done to check if it's already there (what
// may mean the face-tracker program is already running).
//
// If one already exists: close it and open the file-mapping to the existing one.
//
hFTMemMap = CreateFileMappingA( INVALID_HANDLE_VALUE , 00 , PAGE_READWRITE , 0 ,
sizeof( FTMemMap ),
(LPCSTR) FT_MM_DATA );
if (hFTMemMap == NULL)
{
pMemData = NULL;
return false;
}
pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_WRITE, 0, 0, sizeof( FTMemMap ) );
hFTMutex = CreateMutexA(NULL, false, FREETRACK_MUTEX);
return true;
}
示例10: cbOpenMutexA
static void cbOpenMutexA()
{
char mutex_name[20]="";
long mutex_addr=0;
long esp_addr=0;
unsigned int return_addr=0;
DeleteAPIBreakPoint((char*)"kernel32.dll", (char*)"OpenMutexA", UE_APISTART);
esp_addr=(long)GetContextData(UE_ESP);
if(!ReadProcessMemory(g_fdProcessInfo->hProcess, (const void*)esp_addr, &return_addr, 4, 0))
{
VF_FatalError(rpmerror(), g_ErrorMessageCallback);
return;
}
if(!ReadProcessMemory(g_fdProcessInfo->hProcess, (const void*)(esp_addr+12), &mutex_addr, 4, 0))
{
VF_FatalError(rpmerror(), g_ErrorMessageCallback);
return;
}
if(!ReadProcessMemory(g_fdProcessInfo->hProcess, (const void*)mutex_addr, &mutex_name, 20, 0))
{
VF_FatalError(rpmerror(), g_ErrorMessageCallback);
return;
}
CreateMutexA(0, FALSE, mutex_name);
if(GetLastError()==ERROR_SUCCESS)
SetAPIBreakPoint((char*)"kernel32.dll", (char*)"VirtualProtect", UE_BREAKPOINT, UE_APISTART, (void*)cbVirtualProtect);
else
{
char log_message[256]="";
sprintf(log_message, "[Fail] Failed to create mutex %s", mutex_name);
VF_FatalError(log_message, g_ErrorMessageCallback);
}
}
示例11: main
int main(int argc, char const *argv[])
{
CreateMutexA(0,0,"Dr.COM_AUTH_SERVICE_MUTEX");
if (GetLastError()==ERROR_ALREADY_EXISTS){
printf("%s\n", "Drcom auth service is running!");
}
return 0;
}
示例12: CreateMutexA
ofxOscReceiver::ofxOscReceiver()
{
#ifdef TARGET_WIN32
mutex = CreateMutexA( NULL, FALSE, NULL );
#else
pthread_mutex_init( &mutex, NULL );
#endif
}
示例13: acquire
bool acquire() {
mMutex = CreateMutexA(nullptr, FALSE, "TempleofElementalEvilMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
MessageBoxA(nullptr, "Temple of Elemental Evil is already running.", "Temple of Elemental Evil", MB_OK | MB_ICONERROR);
return false;
}
return true;
}
示例14: assert
bool SpoutSharedMemory::Open(const char* name)
{
// Don't call open twice on the same object without a Close()
assert(name);
if (m_hMap)
{
assert(strcmp(name, m_pName) == 0);
assert(m_pBuffer && m_hMutex);
return true;
}
m_hMap = OpenFileMappingA ( FILE_MAP_ALL_ACCESS,
FALSE,
(LPCSTR)name);
if (m_hMap == NULL)
{
return false;
}
DWORD err = GetLastError();
if (err == ERROR_ALREADY_EXISTS)
{
// We should ensure the already existing mapping is at least
// the size we expect
}
m_pBuffer = (char*)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (!m_pBuffer)
{
Close();
return false;
}
std::string mutexName;
mutexName = name;
mutexName += "_mutex";
m_hMutex = CreateMutexA(NULL, FALSE, mutexName.c_str());
if (!m_hMutex)
{
Close();
return false;
}
// m_pName = strdup(name);
m_pName = _strdup(name);
m_size = 0;
return true;
}
示例15: WeAreAlone
//***********************************************************************
static BOOL WeAreAlone(LPSTR szName)
{
HANDLE hMutex = CreateMutexA(NULL, true, szName);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(hMutex);
return false;
}
return true;
}