您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CreateMutexA函数代码示例

51自学网 2021-06-01 20:14:48
  C++
这篇教程C++ CreateMutexA函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中CreateMutexA函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateMutexA函数的具体用法?C++ CreateMutexA怎么用?C++ CreateMutexA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了CreateMutexA函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,


示例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,


示例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;}
开发者ID:jonburgstrom,项目名称:Spout2,代码行数:32,


示例4: publish_session_bus

static gbooleanpublish_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;}
开发者ID:183amir,项目名称:glib,代码行数:28,


示例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}
开发者ID:acarabott,项目名称:ofxRemoteUI,代码行数:31,


示例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;}
开发者ID:EXcEptik,项目名称:CourseTrainer,代码行数:26,


示例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);}
开发者ID:Adoni,项目名称:WiEngine,代码行数:7,


示例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;}
开发者ID:dmchen114,项目名称:dmUtils,代码行数:37,


示例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;}
开发者ID:vheathen,项目名称:opentrack,代码行数:39,


示例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);    }}
开发者ID:SmilingWolf,项目名称:akt,代码行数:33,


示例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;}
开发者ID:KohoT,项目名称:LiteDrcom,代码行数:8,


示例12: CreateMutexA

ofxOscReceiver::ofxOscReceiver(){#ifdef TARGET_WIN32	mutex = CreateMutexA( NULL, FALSE, NULL );#else	pthread_mutex_init( &mutex, NULL );#endif}
开发者ID:010175,项目名称:switchboard,代码行数:8,


示例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; }
开发者ID:ema29,项目名称:TemplePlus,代码行数:8,


示例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;}
开发者ID:charlesveasey,项目名称:vDome,代码行数:58,


示例15: WeAreAlone

//***********************************************************************static BOOL WeAreAlone(LPSTR szName){   HANDLE hMutex = CreateMutexA(NULL, true, szName);   if (GetLastError() == ERROR_ALREADY_EXISTS) {      CloseHandle(hMutex);      return false;   }   return true;}
开发者ID:DerellLicht,项目名称:winwiz,代码行数:10,


示例16: main

int main(int argc, char *argv[]){    KLUPD::CoreError result = KLUPD::CORE_ADMKIT_FAILURE;    IniConfiguration iniConfiguration;    if(iniConfiguration.parse(argc, argv))    {        if(iniConfiguration.writeDump())        {            MiniDumper::enable();            if(iniConfiguration.suppressErrorDialog())                MiniDumper::suppressErrorDialog();        }        // protection against multiple instances        #if defined(UNICODE) || defined(_UNICODE)            #ifdef WSTRING_SUPPORTED                HANDLE h = CreateMutex(0, FALSE, KLUPD::asciiToWideChar(iniConfiguration.applicaitonInstanceMutexName()).c_str());            #else                HANDLE h = CreateMutexA(0, FALSE, iniConfiguration.applicaitonInstanceMutexName().c_str());            #endif        #else                HANDLE h = CreateMutex(0, FALSE, iniConfiguration.applicaitonInstanceMutexName().c_str());        #endif        // there is already an instance of this application running, or failed to create mutex        if(!h || (GetLastError() == ERROR_ALREADY_EXISTS))        {            // TODO: change to code: failed to run several updater instances        }        else            result = mainLoop(iniConfiguration);        if(h)            CloseHandle(h);    }    // writing single line result report to file    KLUPD::AutoStream resultFile(0);    const KLUPD::CoreError openResultFileResult = resultFile.open(iniConfiguration.updateReadableResultFileName(), L"w");    if(isSuccess(openResultFileResult))    {        #ifdef WSTRING_SUPPORTED            fwprintf(resultFile.stream(), L"%d/n%s", result, KLUPD::toString(result).toWideChar());        #else            fprintf(resultFile.stream(), "%d/n%s", result, KLUPD::toString(result).toAscii());        #endif    }    else    {        std::cerr << "Failed to open trace file '" << iniConfiguration.updateReadableResultFileName().toAscii()            << "', result " << KLUPD::toString(openResultFileResult).toAscii();    }    return result;}
开发者ID:hackshields,项目名称:antivirus,代码行数:56,


示例17: WinMain

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){	HANDLE hMutex = CreateMutexA(NULL, FALSE, "Escape_");	if (hMutex != NULL && ERROR_ALREADY_EXISTS == GetLastError())	{		return 0;	}	nDialogRet = DialogBox( hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, DialogProc);	return 0;}
开发者ID:nervmor,项目名称:face_recognition,代码行数:10,


示例18: MyCreateMutexA

HOOKFUNC HANDLE WINAPI MyCreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCSTR lpName){	HANDLE rv = CreateMutexA(lpMutexAttributes, bInitialOwner, lpName);	debuglog(LCF_SYNCOBJ, __FUNCTION__ " returned 0x%X./n", rv);	EnterCriticalSection(&s_handleCS);	std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()];	handles.insert(rv);	LeaveCriticalSection(&s_handleCS);	return rv;}
开发者ID:Bobakanoosh55555,项目名称:hourglass-win32,代码行数:10,


示例19: CreateMutexA

/*!    /internal*/void QInterProcessChannel::init() {  // while(isRunning())  //  quit();  // create global mutex to check single instance  CreateMutexA(NULL, FALSE, qPrintable(globalMutexStr));  serverMode = !(GetLastError() == ERROR_ALREADY_EXISTS);  // start listening thread in single instance mode  if (serverMode) start();}
开发者ID:Greedysky,项目名称:qnapi,代码行数:14,


示例20: MyCreateMutexA

 HOOKFUNC HANDLE WINAPI MyCreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCSTR lpName) {     ENTER();     HANDLE rv = CreateMutexA(lpMutexAttributes, bInitialOwner, lpName);     LEAVE(rv);     EnterCriticalSection(&s_handleCS);     std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()];     handles.insert(rv);     LeaveCriticalSection(&s_handleCS);     return rv; }
开发者ID:Scepheo,项目名称:Hourglass-Resurrection,代码行数:11,


示例21: strcpy

void *try_open_single_program(const char *name) {    char full_name[255];    HANDLE program_instance;    strcpy(full_name, "Global//{");    strcat(full_name, name);    strcat(full_name, "}");    program_instance = CreateMutexA(NULL, FALSE, full_name);    if (GetLastError() == ERROR_ALREADY_EXISTS || program_instance == NULL) {        return NULL;    }    return program_instance;}
开发者ID:MikauSchekzen,项目名称:kb-profiler,代码行数:13,


示例22: Check

	void Check(const char *url, const char *post)	{		// 
C++ CreateMutexW函数代码示例
C++ CreateMutex函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。