• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetCurrentThreadId函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: SmsAgent

DWORD WINAPI SmsAgent(LPVOID lpParam) {
	Module *me = (Module *)lpParam;
	Configuration *conf = me->getConf();
	HANDLE eventHandle;

	MAPIAgent* agent = MAPIAgent::Instance();
	Observer *observerObj = Observer::self();
	MSG Msg;

	BOOL smsEnabled = FALSE, history = FALSE;
	wstring dateFrom, dateTo;
	JSONObject filter;

	// NON DEVE PARTIRE FINCHE NON VIENE FIXATO
	me->setStatus(MODULE_STOPPED);
	DBG_TRACE(L"Debug - Messages.cpp - This module cannot work\n", 5, FALSE);
	return 0;
	// NON DEVE PARTIRE FINCHE NON VIENE FIXATO

	// Cosi si prende la conf per SMS, per tutti gli altri e' uguale
	// cambia solo il nome dell'array
	try {
		smsEnabled = conf->getBoolFromArray(L"sms", L"enabled");

		filter = conf->getObjectFromArray(L"sms", L"filter");

		history = conf->getBoolFromObject(filter, L"history");
		dateFrom = conf->getStringFromObject(filter, L"datefrom");
		dateTo = conf->getStringFromObject(filter, L"dateto");
	} catch (...) {
		smsEnabled = FALSE;
	}

	me->setStatus(MODULE_RUNNING);
	eventHandle = me->getEvent();

	DBG_TRACE(L"Debug - Messages.cpp - Messages Module started\n", 5, FALSE);

	// Registriamoci all'observer
	if (observerObj->Register(GetCurrentThreadId()) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		DBG_TRACE(L"Debug - Messages.cpp - Messages Module [cannot register to Observer, exiting]\n", 5, FALSE);
		return 0;
	}

	/*if (agent->Init(lpConfig, cbConfig) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		return 0;
	}*/

	if (agent->Run(0) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		return 0;
	}

	LOOP {
		// Diciamo semplicemente alla coda di farli passare tutti
		if (observerObj->GetMessage() != NULL) {
			observerObj->MarkMessage(GetCurrentThreadId(), IPC_PROCESS, FALSE);
		}

		if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) {
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}

		// Keep the sleeping time at 50, otherwise the MAIL agent WON'T WORK!!!
		WaitForSingleObject(eventHandle, 50);
		
		if (me->shouldStop())
			break;
	}

	agent->Quit();
	agent->WaitForCollector();
	agent->Destroy();

	observerObj->UnRegister(GetCurrentThreadId());

	me->setStatus(MODULE_STOPPED);
	DBG_TRACE(L"Debug - Messages.cpp - Messages Module clean stop\n", 5, FALSE);
	return 0;
}
开发者ID:BwRy,项目名称:core-winmobile,代码行数:83,代码来源:Messages.cpp


示例2: RemoveMessagesFromBuyThreadQueue

VOID RemoveMessagesFromBuyThreadQueue(CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx)
{
   BUY_CONTEXT* pBuyCtx = NULL;
   MSG msg = {0};

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->buyThreadContext.msgBuy, 
      pThreadCtx->buyThreadContext.msgBuy, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromBuyThreadQueue: PeekMessage in cleanup retrieved message to buy.\n", GetCurrentThreadId());
      pBuyCtx = reinterpret_cast<BUY_CONTEXT*>(msg.lParam);

      if(NULL != pBuyCtx)
      {
         if(NULL != pBuyCtx->cookie)
         {
            pBuyCtx->pIStream->Release();
            pBuyCtx->pIStream = NULL;         
         }

         delete pBuyCtx;
         pBuyCtx = NULL;
      }
   } // while PeekMessage
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:28,代码来源:Threads.cpp


示例3: RemoveMessagesFromLoginThreadQueue

VOID RemoveMessagesFromLoginThreadQueue(CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx)
{
   LOGIN_CONTEXT* pLoginCtx = NULL;
   MSG msg = {0};

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgAuthenticate, 
      pThreadCtx->loginThreadContext.msgAuthenticate, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to authenticate.\n", GetCurrentThreadId());
      pLoginCtx = reinterpret_cast<LOGIN_CONTEXT*>(msg.lParam);

      if(NULL != pLoginCtx)
      {
         delete pLoginCtx;
         pLoginCtx = NULL;
      }

   } // while PeekMessage

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgLogin, 
      pThreadCtx->loginThreadContext.msgLogin, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("x RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to log in.\n", GetCurrentThreadId());
      pLoginCtx = reinterpret_cast<LOGIN_CONTEXT*>(msg.lParam);

      if(NULL != pLoginCtx)
      {
         delete pLoginCtx;
         pLoginCtx = NULL;
      }

   } // while PeekMessage

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgLogout, 
      pThreadCtx->loginThreadContext.msgLogout, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to log out.\n", GetCurrentThreadId());
      
      // There is no context associated with a log-out message.

   } // while PeekMessage
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:54,代码来源:Threads.cpp


示例4: GetCurrentThreadId

hsThread::ThreadId hsThread::GetMyThreadId()
{
    return GetCurrentThreadId();
}
开发者ID:branan,项目名称:Plasma,代码行数:4,代码来源:hsThread_Win.cpp


示例5: ContentPartnerMessageLoop

HRESULT ContentPartnerMessageLoop(
   CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx,
   CComPtr<IWMPContentPartnerCallback> spCallback)
{
   MSG msg = {0};
   HRESULT hr = S_OK;

   if(NULL == pThreadCtx || NULL == spCallback)
   {
      hr = E_UNEXPECTED;
      goto cleanup;
   }

   // Windows message loop
   while(TRUE)
   {
      BOOL ret = 0;

      // Suppose we have several messages (for example, 
      // buy or download messages) in the queue, and then 
      // the user closes Windows Media Player. We would like
      // to let Windows Media Player close without waiting for all
      // those queued messages to be processed.
      //
      // So we use the following strategy.
      //
      // Peek into the message queue to see if there is an exit message.
      // If there is an exit message anywhere in the queue, break out of
      // the message loop even though there might be several
      // messages remaining in the queue.
      
      if( PeekMessage(
             &msg, 
             NULL, 
             pThreadCtx->msgExitMessageLoop, 
             pThreadCtx->msgExitMessageLoop,
             PM_REMOVE) )
      {
         ATLTRACE2("%x: ContentPartnerMessageLoop(type &d): PeekMessage retrieved an exit message.\n", GetCurrentThreadId(), pThreadCtx->threadType);
         goto cleanup;
      }

      ret = GetMessage(&msg, 0, 0, 0);
      if(-1 == ret)
      {
          ATLTRACE2("%x: ContentPartnerMessageLoop(type %d): GetMessage failed (returned -1).\n", GetCurrentThreadId(), pThreadCtx->threadType);
          hr = HRESULT_FROM_WIN32(GetLastError());
          goto cleanup;
      }

      if(pThreadCtx->msgExitMessageLoop == msg.message)
      {
         ATLTRACE2("%x: ContentPartnerMessageLoop(type %d): GetMessage retrieved an exit message.\n", GetCurrentThreadId(), pThreadCtx->threadType);
         break; // Break out of the message loop.
      }

      switch(pThreadCtx->threadType)
      {
      case ThreadTypeDownload:
         hr = HandleMessageForDownloadThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeBuy:
         hr = HandleMessageForBuyThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeRefreshLicense:
         hr = HandleMessageForRefreshLicenseThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeLogin:
         hr = HandleMessageForLoginThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeSendMessage:
         hr = HandleMessageForSendMessageThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeUpdateDevice:
         hr = HandleMessageForUpdateDeviceThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeList:
         hr = HandleMessageForListThread(&msg, pThreadCtx, spCallback);
         break;
      default:
         hr = E_UNEXPECTED;
      } // switch(threadType)
      

      if(FAILED(hr))
      {
         goto cleanup;
      }

   } // while(TRUE)

cleanup:

   if(NULL != pThreadCtx)
   {
      switch(pThreadCtx->threadType)
      {
      case ThreadTypeDownload:
         RemoveMessagesFromDownloadThreadQueue(pThreadCtx);
         break;
//.........这里部分代码省略.........
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:101,代码来源:Threads.cpp


示例6: spthread_self

inline spthread_t spthread_self() {
    return GetCurrentThreadId();
}
开发者ID:153370771,项目名称:ltp,代码行数:3,代码来源:spthread.hpp


示例7: do_it

void WINAPI do_it(void)
{
	HANDLE		 hc = NULL;
	UINT_PTR	 dwCaller = 0;
#ifdef _LOGDEBUG
	if ( GetEnvironmentVariableA("APPDATA",logfile_buf,MAX_PATH) > 0 )
	{
		strncat(logfile_buf,"\\",1);
		strncat(logfile_buf,LOG_FILE,strlen((LPCSTR)LOG_FILE));
	}
#endif
	if (!dll_module)
	{
	#ifdef __GNUC__
		dwCaller = (UINT_PTR)__builtin_return_address(0);
	#else
		dwCaller = (UINT_PTR)_ReturnAddress();
	#endif
	}
	if (dwCaller)
	{
		GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)dwCaller, &dll_module);
	}
	if ( read_appint(L"General",L"SafeEx") > 0 )
	{
		init_safed(NULL);
	}
	if ( read_appint(L"General", L"Portable") > 0 )
	{
		env_thread = (HANDLE)_beginthreadex(NULL,0,&init_global_env,NULL,0,NULL);
		if (env_thread) 
		{
			SetThreadPriority(env_thread,THREAD_PRIORITY_HIGHEST);
			init_portable(NULL);
		}
	}
	if ( is_browser() || is_thunderbird() )
	{
		if ( read_appint(L"General",L"GdiBatchLimit") > 0 )
		{
			hc = OpenThread(THREAD_ALL_ACCESS, 0, GetCurrentThreadId());
			if (hc)
			{
				CloseHandle((HANDLE)_beginthreadex(NULL,0,&GdiSetLimit_tt,hc,0,NULL));
			}
		}
		if ( read_appint(L"General",L"ProcessAffinityMask") > 0 )
		{
			hc = OpenThread(THREAD_ALL_ACCESS, 0, GetCurrentThreadId());
			if (hc)
			{
				CloseHandle((HANDLE)_beginthreadex(NULL,0,&SetCpuAffinity_tt,hc,0,NULL));
			}
		}
		if ( read_appint(L"General",L"CreateCrashDump") > 0 )
		{
			CloseHandle((HANDLE)_beginthreadex(NULL,0,&init_exeception,NULL,0,NULL));
		}
		if ( read_appint(L"General", L"Bosskey") > 0 )
		{
			CloseHandle((HANDLE)_beginthreadex(NULL,0,&bosskey_thread,&ff_info,0,NULL));
		}
		CloseHandle((HANDLE)_beginthreadex(NULL,0,&SetPluginPath,NULL,0,NULL));
	}
}
开发者ID:beequicker,项目名称:pcxfirefox,代码行数:65,代码来源:portable.c


示例8: K32WOWCallback16Ex

/**********************************************************************
 *           K32WOWCallback16Ex         (KERNEL32.55)
 */
BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
                                DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
{
    /*
     * Arguments must be prepared in the correct order by the caller
     * (both for PASCAL and CDECL calling convention), so we simply
     * copy them to the 16-bit stack ...
     */
    char *stack = (char *)CURRENT_STACK16 - cbArgs;

    memcpy( stack, pArgs, cbArgs );

    if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
    {
        CONTEXT *context = (CONTEXT *)pdwRetCode;

        if (TRACE_ON(relay))
        {
            DWORD count = cbArgs / sizeof(WORD);
            WORD * wstack = (WORD *)stack;

            DPRINTF("%04x:CallTo16(func=%04x:%04x,ds=%04x",
                    GetCurrentThreadId(),
                    context->SegCs, LOWORD(context->Eip), context->SegDs );
            while (count) DPRINTF( ",%04x", wstack[--count] );
            DPRINTF(") ss:sp=%04x:%04x",
                    SELECTOROF(NtCurrentTeb()->WOW32Reserved), OFFSETOF(NtCurrentTeb()->WOW32Reserved) );
            DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
                    (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
                    (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
                    (WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
            SYSLEVEL_CheckNotLevel( 2 );
        }

        if (context->EFlags & 0x00020000)  /* v86 mode */
        {
            EXCEPTION_REGISTRATION_RECORD frame;
            frame.Handler = vm86_handler;
            errno = 0;
            __wine_push_frame( &frame );
            __wine_enter_vm86( context );
            __wine_pop_frame( &frame );
            if (errno != 0)  /* enter_vm86 will fall with ENOSYS on x64 kernels */
            {
                WARN("__wine_enter_vm86 failed (errno=%d)\n", errno);
                if (errno == ENOSYS)
                    SetLastError(ERROR_NOT_SUPPORTED);
                else
                    SetLastError(ERROR_GEN_FAILURE);
                return FALSE;
            }
        }
        else
        {
            /* push return address */
            if (dwFlags & WCB16_REGS_LONG)
            {
                stack -= sizeof(DWORD);
                *((DWORD *)stack) = HIWORD(call16_ret_addr);
                stack -= sizeof(DWORD);
                *((DWORD *)stack) = LOWORD(call16_ret_addr);
                cbArgs += 2 * sizeof(DWORD);
            }
            else
            {
                stack -= sizeof(SEGPTR);
                *((SEGPTR *)stack) = call16_ret_addr;
                cbArgs += sizeof(SEGPTR);
            }

            /*
             * Start call by checking for pending events.
             * Note that wine_call_to_16_regs overwrites context stack
             * pointer so we may modify it here without a problem.
             */
            if (get_vm86_teb_info()->dpmi_vif)
            {
                context->SegSs = wine_get_ds();
                context->Esp   = (DWORD)stack;
                insert_event_check( context );
                cbArgs += (DWORD)stack - context->Esp;
            }

            _EnterWin16Lock();
            wine_call_to_16_regs( context, cbArgs, call16_handler );
            _LeaveWin16Lock();
        }

        if (TRACE_ON(relay))
        {
            DPRINTF("%04x:RetFrom16() ss:sp=%04x:%04x ",
                    GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->WOW32Reserved),
                    OFFSETOF(NtCurrentTeb()->WOW32Reserved));
            DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
                    (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
                    (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
            SYSLEVEL_CheckNotLevel( 2 );
//.........这里部分代码省略.........
开发者ID:bilboed,项目名称:wine,代码行数:101,代码来源:wowthunk.c


示例9: interruptProcess

/////////////////////////////////////////////////////////////////////////////////////
// Called to interrupt a process that we didn't launch (and thus does not share our 
// console). Windows XP introduced the function 'DebugBreakProcess', which allows
// a process to interrupt another process even if if the two do not share a console.
// If we're running on 2000 or earlier, we have to resort to simulating a CTRL-C
// in the console by firing keyboard events. This will work only if the process
// has its own console. That means, e.g., the process should have been started at
// the cmdline with 'start myprogram.exe' instead of 'myprogram.exe'.
//
// Arguments:  
//			pid - process' pid
// Return : 0 if OK or error code
/////////////////////////////////////////////////////////////////////////////////////
int interruptProcess(int pid) 
{
	// See if DebugBreakProcess is available (XP and beyond)
	HMODULE hmod = LoadLibrary(L"Kernel32.dll");
	if (hmod != NULL) 
	{
		BOOL success = FALSE;
		FARPROC procaddr = GetProcAddress(hmod, "DebugBreakProcess");
		if (procaddr != NULL)
		{
			HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
			if (proc != NULL) 
			{
				DebugBreakProcessFunc pDebugBreakProcess = (DebugBreakProcessFunc)procaddr;
				success = (*pDebugBreakProcess)(proc); 
				CloseHandle(proc);
			}
		}
		FreeLibrary(hmod);
		hmod = NULL;
		
		if (success)
			return 0;	// 0 == OK; if not, try old-school way
	}

#ifdef DEBUG_MONITOR
    _TCHAR buffer[1000];
#endif
	int rc = 0;
	consoleHWND = NULL;

#ifdef DEBUG_MONITOR
		_stprintf(buffer, _T("Try to interrupt process %i\n"), pid);
		OutputDebugStringW(buffer);
#endif
	// Find console
	EnumWindows (find_child_console, (LPARAM) pid);

	if(NULL != consoleHWND) // Yes, we found out it
	{
	  // We are going to switch focus to console, 
	  // send Ctrl-C and then restore focus
	  BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
	  /* Fake Ctrl-C for SIGINT, and Ctrl-Break for SIGQUIT.  */
	  BYTE vk_c_code = 'C';
	  BYTE vk_break_code = VK_CANCEL;
	  BYTE c_scan_code = (BYTE) MapVirtualKey (vk_c_code, 0);
	  BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
	  HWND foreground_window;
		

	  foreground_window = GetForegroundWindow ();
	  if (foreground_window)
	    {
         /* NT 5.0, and apparently also Windows 98, will not allow
		 a Window to be set to foreground directly without the
		 user's involvement. The workaround is to attach
		 ourselves to the thread that owns the foreground
		 window, since that is the only thread that can set the
		 foreground window.  */
        DWORD foreground_thread, child_thread;
        foreground_thread =
			GetWindowThreadProcessId (foreground_window, NULL);
	    if (foreground_thread == GetCurrentThreadId ()
                  || !AttachThreadInput (GetCurrentThreadId (),
                                         foreground_thread, TRUE))
            foreground_thread = 0;

        child_thread = GetWindowThreadProcessId (consoleHWND, NULL);
	    if (child_thread == GetCurrentThreadId ()
                  || !AttachThreadInput (GetCurrentThreadId (),
                                         child_thread, TRUE))
            child_thread = 0;

        /* Set the foreground window to the child.  */
        if (SetForegroundWindow (consoleHWND))
           {
		   if(0 != break_scan_code) {
			   /* Generate keystrokes as if user had typed Ctrl-Break */
			   keybd_event (VK_CONTROL, control_scan_code, 0, 0);
			   keybd_event (vk_break_code, break_scan_code,	KEYEVENTF_EXTENDEDKEY, 0);
			   keybd_event (vk_break_code, break_scan_code,
					KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			   keybd_event (VK_CONTROL, control_scan_code,  KEYEVENTF_KEYUP, 0);
		   }

          /* Sleep for a bit to give time for respond */
//.........这里部分代码省略.........
开发者ID:MarcMil,项目名称:cdt,代码行数:101,代码来源:raise.c


示例10: s_serviceSetHBSig

static void s_serviceSetHBSig( void )
{
#if defined( HB_OS_UNIX ) || defined( HB_OS_OS2_GCC )
    struct sigaction act;

#if defined( HB_THREAD_SUPPORT ) && ! defined( HB_OS_OS2 )
    sigset_t blockall;
    /* set signal mask */
    sigemptyset( &blockall );
    sigaddset( &blockall, SIGHUP );
    sigaddset( &blockall, SIGQUIT );
    sigaddset( &blockall, SIGILL );
    sigaddset( &blockall, SIGABRT );
    sigaddset( &blockall, SIGFPE );
    sigaddset( &blockall, SIGSEGV );
    sigaddset( &blockall, SIGTERM );
    sigaddset( &blockall, SIGUSR1 );
    sigaddset( &blockall, SIGUSR2 );
    sigaddset( &blockall, SIGHUP );

    pthread_sigmask( SIG_SETMASK, &blockall, NULL );
#endif

    /* to avoid problems with differ sigaction structures and uninitialized
       fields */
    memset( &act, 0, sizeof( act ) );

#if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ )
    act.sa_handler = s_signalHandler;
#else
    /* using more descriptive sa_action instead of sa_handler */
    act.sa_handler   = NULL;            /* if act.sa.. is a union, we just clean this */
    act.sa_sigaction = s_signalHandler; /* this is what matters */
    /* block al signals, we don't want to be interrupted. */
#if 0
    sigfillset( &act.sa_mask );
#endif
#endif


#ifdef HB_OS_OS2_GCC
    act.sa_flags = SA_NOCLDSTOP;
#else
    act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
#endif

    sigaction( SIGHUP, &act, NULL );
    sigaction( SIGQUIT, &act, NULL );
    sigaction( SIGILL, &act, NULL );
    sigaction( SIGABRT, &act, NULL );
    sigaction( SIGFPE, &act, NULL );
    sigaction( SIGSEGV, &act, NULL );
    sigaction( SIGTERM, &act, NULL );
    sigaction( SIGUSR1, &act, NULL );
    sigaction( SIGUSR2, &act, NULL );

    /* IGNORE pipe */
    signal( SIGPIPE, SIG_IGN );
#endif

#ifdef HB_OS_WIN
    /* disable all os-level error boxes */
    s_uiErrorMode = SetErrorMode(
                        SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX |
                        SEM_NOOPENFILEERRORBOX );

    SetUnhandledExceptionFilter( s_exceptionFilter );
    s_hMsgHook = SetWindowsHookEx( WH_GETMESSAGE, ( HOOKPROC ) s_MsgFilterFunc, NULL, GetCurrentThreadId() );
    SetConsoleCtrlHandler( s_ConsoleHandlerRoutine, TRUE );

#endif
}
开发者ID:vszakats,项目名称:harbour-core,代码行数:72,代码来源:hbserv.c


示例11: CPLGetPID

GIntBig CPLGetPID()

{
    return (GIntBig) GetCurrentThreadId();
}
开发者ID:nvdnkpr,项目名称:node-srs,代码行数:5,代码来源:cpl_multiproc.cpp


示例12: s_signalHandler

/* Manager of signals for windows */
static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc )
{
    HB_SIZE  nPos;
    HB_UINT  uiSig;

    /* let's find the right signal handler. */
    hb_threadEnterCriticalSectionGC( &s_ServiceMutex );

    /* avoid working if PRG signal handling has been disabled */
    if( ! s_bSignalEnabled )
    {
        hb_threadLeaveCriticalSection( &s_ServiceMutex );
        return EXCEPTION_EXECUTE_HANDLER;
    }

    s_bSignalEnabled = HB_FALSE;
    nPos = hb_arrayLen( s_pHooks );
    /* subsig not necessary */
    uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) type, ( HB_UINT ) sig );

    while( nPos > 0 )
    {
        PHB_ITEM pFunction;
        HB_UINT  uiMask;

        pFunction = hb_arrayGetItemPtr( s_pHooks, nPos );
        uiMask    = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 );
        if( ( uiMask & uiSig ) == uiSig )
        {
            PHB_ITEM pExecArray, pRet;
            int      iRet;

            /* we don't unlock the mutex now, even if it is
               a little dangerous. But we are in a signal hander...
               for now just 2 parameters */
            pExecArray = hb_itemArrayNew( 3 );
            hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
            hb_arraySetNI( pExecArray, 2, uiSig );

            /* the third parameter is an array:
             * 1: low-level signal
             * 2: low-level subsignal
             * 3: low-level system error
             * 4: address that rised the signal
             * 5: process id of the signal riser
             * 6: UID of the riser
             */

            pRet = hb_arrayGetItemPtr( pExecArray, 3 );
            hb_arrayNew( pRet, 6 );

            hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type );
            hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig );
            /* could be meaningless, but does not matter here */
            hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() );

            if( type == 0 ) /* exception */
                hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress );
            else
                hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL );

            /* TODO: */
            hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() );
            /* TODO: */
            hb_arraySetNI( pRet, HB_SERVICE_UID, 0 );

            pRet = hb_itemDo( pExecArray, 0 );
            iRet = hb_itemGetNI( pRet );
            hb_itemRelease( pRet );
            hb_itemRelease( pExecArray );

            switch( iRet )
            {
            case HB_SERVICE_HANDLED:
                s_bSignalEnabled = HB_TRUE;
                hb_threadLeaveCriticalSection( &s_ServiceMutex );
                return EXCEPTION_CONTINUE_EXECUTION;

            case HB_SERVICE_QUIT:
                s_bSignalEnabled = HB_FALSE;
                hb_threadLeaveCriticalSection( &s_ServiceMutex );
                hb_vmRequestQuit();
#ifndef HB_THREAD_SUPPORT
                hb_vmQuit();
                exit( 0 );
#else
                hb_threadCancelInternal();
#endif
            }
        }
        nPos--;
    }

    s_bSignalEnabled = HB_TRUE;
    return EXCEPTION_EXECUTE_HANDLER;
}
开发者ID:vszakats,项目名称:harbour-core,代码行数:97,代码来源:hbserv.c


示例13: WriteToDatabase

DWORD WINAPI WriteToDatabase( LPVOID lpParam )
{ 
	DWORD dwCount=0, dwWaitResult; 
	DWORD time_out = 30;	//time_out Milliseconds while WaitForSingleObject
	DWORD sleep_time = 29;	//sleep_time Milliseconds while WritetoDatabase

	// Request ownership of mutex.

	while( dwCount < 10 )
	{
// 		dwWaitResult = WaitForSingleObject( 
// 			ghMutex,    // handle to mutex
// 			INFINITE);  // no time-out interval

		dwWaitResult = WaitForSingleObject( 
			ghMutex,    // handle to mutex
			time_out);	//wait for time_out Milliseconds

// 		dwWaitResult = WaitForSingleObject( 
// 			ghMutex,    // handle to mutex
// 			IGNORE);	//ignore

		switch (dwWaitResult) 
		{
			// The thread got ownership of the mutex
		case WAIT_OBJECT_0: 
			__try { 
				// TODO: Write to the database
				printf("Thread %d writing to database...\n", 
					GetCurrentThreadId());
				dwCount++;
 				Sleep (sleep_time);
			} 
			__finally { 
				// Release ownership of the mutex object
				if (! ReleaseMutex(ghMutex)) 
				{ 
					// Deal with error.
					printf("Thread %d ReleaseMutex error!\n",
						GetCurrentThreadId ());
				} 
			} 
			break; 

			// The thread got ownership of the mutex time-out
		case WAIT_TIMEOUT:
			{
				// Deal with error.
				printf("Thread %d WaitForSingleObject time-out! dwWaitResult = 0X%08X\n",
					GetCurrentThreadId (),dwWaitResult);
			}
			break;

			// The thread got ownership of an abandoned mutex
		case WAIT_ABANDONED: 
			{
				// Deal with error.
				printf("Thread %d got ownership of an abandoned mutex!\n",
					GetCurrentThreadId ());
			}
			return FALSE;

			//The WaitForSingleObject function failed
		case WAIT_FAILED :
			{
				// Deal with error.
				printf("The WaitForSingleObject function failed!\n");
			}
			return FALSE; 

		default:
			break;
		}
	}
	return TRUE; 
}
开发者ID:codeworkscn,项目名称:learn-cpp,代码行数:76,代码来源:Main.cpp


示例14: GetCurrentThreadId

    //--------------------------------------------------------------------------------
    void GameNetL2NEventDataFactory::createGameNetSendDataBufferPtr(GameNetSendDataBufferPtr& ptr, U32 buffSize)
    {
        NetSendDataBuffer* buffObj                  = NULL;
        std::deque<NetSendDataBuffer*>* idleList    = NULL;
        GameNetSendDataBufferPool*      pool        = NULL;
        GameNetSendDataBufferPoolManager* poolMgr   = NULL;

        DWORD threadId = GetCurrentThreadId();
        poolMgr = createOrRetrieveGameNetSendDataBufferPoolManager( threadId );
        if ( poolMgr )
        {
            Bool isNormalBuff   = true;

            pool                = poolMgr->m_CreateObjectList;

            // 如果小于默认值, 则分配缓存等于默认值
            if ( buffSize <= MG_GAME_NET_PACKET_NORMAL_MAX_SIZE )
            {
                buffSize        = MG_GAME_NET_PACKET_NORMAL_MAX_SIZE;
                isNormalBuff    = true;
            }else
            if ( buffSize <= MG_GAME_NET_PACKET_BIG_MAX_SIZE )
            {
                buffSize        = MG_GAME_NET_PACKET_BIG_MAX_SIZE;
                isNormalBuff    = false;
            }else
            {
                DYNAMIC_EEXCEPT_LOG("createGameNetSendDataBufferPtr : too long buffsize ");
                return;
            }

            pool->mPoolCs.lock();
            {
                if ( isNormalBuff )
                {
                    idleList = &pool->m_IdleNormalObjectList;
                }else
                {
                    idleList = &pool->m_IdleBigObjectList;
                }

                if ( idleList->size() > 0 )
                {
                    buffObj = idleList->back();
                    idleList->pop_back();
                }else
                {
                    buffObj = mDriverMgr->mMgr->createNetSendDataBuffer( buffSize );
                }
            }
            pool->mPoolCs.unlock();


            poolMgr->mCreateCount++;

        }else
        {
            DYNAMIC_EEXCEPT_LOG("createGameNetSendDataBufferPtr: not register thread !");
        }

        if ( buffObj )
        {
            buffObj->initialize();
			buffObj->setActive( true );

            ptr.setNull();
            ptr.mFactory            = this;
            ptr.mCreateThreadID     = threadId;
            ptr.mNearestSendNetID   = -1;
            ptr.mLogicDataMaxSize   = buffSize;
            ptr.bind( buffObj );

            if ( poolMgr )
            {
                poolMgr->mNearestCreatePtr.setNull();
                poolMgr->mNearestCreatePtr = ptr;
            }
        }
    }
开发者ID:dnjsflagh1,项目名称:code,代码行数:80,代码来源:GameNetL2NEventData.cpp


示例15: OutputDebugStringA

// Credit to NTAuthority
LONG WINAPI DumpHandler::CustomUnhandledExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
{
	// Ignore breakpoints.
	if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) return EXCEPTION_CONTINUE_EXECUTION;

	// Try skipping exceptions
	/* Disable that, it seems unsafe
	if ((ExceptionInfo->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE) != EXCEPTION_NONCONTINUABLE)
	{
		OutputDebugStringA(hString::va("New exception at 0x%X, try ignoring it...", ExceptionInfo->ExceptionRecord->ExceptionAddress));
		ExceptionInfo->ExceptionRecord->ExceptionFlags |= EXCEPTION_NONCONTINUABLE;
		return EXCEPTION_CONTINUE_EXECUTION;
	}
	else
	{
		OutputDebugStringA("Ignoring failed. Handling it now...");
	}
	*/

	// step 1: write minidump
	char error[1024];
	char filename[MAX_PATH];
	__time64_t time;
	tm* ltime;

	_time64(&time);
	ltime = _localtime64(&time);
	strftime(filename, sizeof(filename) - 1, "Redacted - %H-%M-%S %d.%m.%Y.dmp", ltime);
	_snprintf(error, sizeof(error) - 1, "A minidump has been written to %s.", filename);

	HANDLE hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile != INVALID_HANDLE_VALUE)
	{
		MINIDUMP_EXCEPTION_INFORMATION ex = { 0 };
		ex.ThreadId = GetCurrentThreadId();
		ex.ExceptionPointers = ExceptionInfo;
		ex.ClientPointers = FALSE;

		MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ex, NULL, NULL);

		CloseHandle(hFile);
	}
	else
	{
		_snprintf(error, sizeof(error) - 1, "An error (0x%x) occurred during creating %s.", GetLastError(), filename);
	}

	// step 2: exit the application
	// why was this removed?
	if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
	{
		MessageBox(0, "Termination because of a stack overflow.", "ERROR", MB_ICONERROR);
	}
	else
	{
		MessageBox(0, hString::va("Fatal error (0x%08x) at 0x%08x.\n%s", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress, error), "ERROR", MB_ICONERROR);
	}

	TerminateProcess(GetCurrentProcess(), ExceptionInfo->ExceptionRecord->ExceptionCode);
	return 0;
}
开发者ID:RaptorFactor,项目名称:SteamBase,代码行数:63,代码来源:DumpHandler.cpp


示例16: memset

//---------------------------------------------------------------------------
//Recv接收请答包
bool JsdGateway::RecvAnswer(tagAnswerPacket *p_pAnswerPacket, bool singlerecord,int countOffset)
{
  int iLen;
  int iPos;
  int iHeadLen;
  DWORD dwDataLen;
  char szTemp[DEF_SBUFLEN];
	memset(m_pSingleRecvBuffer, 0, DEF_LBUFLEN_8192);

  TByteDynArray da;
  da.set_length(0);

  try
  {
      m_pSocket->Socket->ReadBytes(da,-1,true);
  }
  catch(...)
  {
	 return false;
  }

  if (da.Length == 0)
  {
      return false;
  }
  
  const char *buf = (const char*)&da[0];

	spliter sbuf(buf,da.Length,'|');


	if(sbuf.at(0).length()==0 || sbuf.at(0)[0] != 'A') {
    return false;
  }

//  包头取到后,判断序列号字段,以避免串户情况
  char szReqPakSN[DEF_SBUFLEN];
  sprintf(szReqPakSN,"%x:%x", GetCurrentThreadId(), m_dwReqPakSN);

  if (strcmp(szReqPakSN,sbuf.at(2).c_str())!=0)
  {
    //出现这种错误可能是因为错位,所以缓冲区内的数据全部清掉
	  return false;
  }

	if(sbuf[3].c_str()[0]=='N') {

		strcpy(p_pAnswerPacket->szRetMsg, sbuf[4].c_str());
		strcpy(p_pAnswerPacket->szRetCode, sbuf[5].c_str());

		return true;
	}
	else {
		memset(p_pAnswerPacket->szRetCode,0,DEF_SBUFLEN);
  }

  if(singlerecord)  {
    p_pAnswerPacket->bIsNext = 0;
    m_iRecNo = 1;
  }
  else {

    if(p_pAnswerPacket->bIsNext==0) {
			m_iRecNo =  atoi( sbuf[countOffset+2].c_str() )+1;    //记录总数+首条记录

      if(m_iRecNo<=0) {
				p_pAnswerPacket->bIsNext = 0;
      }
      else {
        p_pAnswerPacket->bIsNext = 1;
      }

      //return true;
    }
  }
  p_pAnswerPacket->iRecNum ++;

  if(p_pAnswerPacket->iRecNum==m_iRecNo) {   //数据是否已满
    p_pAnswerPacket->bIsNext = 0;
  }

  //处理数据结果
  for(int i=0;i<(m_iFieldCount+3);i++)  {
    _retData.push_back(sbuf[i]);
  }

  if(unsigned(p_pAnswerPacket->iRecNum*(m_iFieldCount+3))!=_retData.size()) {
    return false;
  }


  return TRUE;
}
开发者ID:code4hunter,项目名称:oldpts,代码行数:95,代码来源:JsdGateway.cpp


示例17: Cadthread

DWORD WINAPI Cadthread(LPVOID lpParam)
{
	OSVERSIONINFO OSversion;	
	OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx(&OSversion);


	HDESK desktop=NULL;
	desktop = OpenInputDesktop(0, FALSE,
								DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
								DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
								DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
								DESKTOP_SWITCHDESKTOP | GENERIC_WRITE
								);


	
	if (desktop == NULL)
		vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop Error \n"));
	else 
		vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop OK\n"));

	HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
	DWORD dummy;

	char new_name[256];
	if (desktop)
	{
	if (!GetUserObjectInformation(desktop, UOI_NAME, &new_name, 256, &dummy))
	{
		vnclog.Print(LL_INTERR, VNCLOG("!GetUserObjectInformation \n"));
	}

	vnclog.Print(LL_INTERR, VNCLOG("SelectHDESK to %s (%x) from %x\n"), new_name, desktop, old_desktop);

	if (!SetThreadDesktop(desktop))
	{
		vnclog.Print(LL_INTERR, VNCLOG("SelectHDESK:!SetThreadDesktop \n"));
	}
	}

	//////
	if(OSversion.dwMajorVersion>=6 && vncService::RunningAsService())
			{
				/*if (OSversion.dwMinorVersion==0) //Vista
				{
					if (ISUACENabled() && !IsSoftwareCadEnabled())//ok
					{
						
					}
					if (!ISUACENabled() && IsSoftwareCadEnabled())
					{
						
					}
					if (!ISUACENabled() && !IsSoftwareCadEnabled())
					{
						DWORD result=MessageBoxSecure(NULL,"UAC is Disable, make registry changes to allow cad","Warning",MB_YESNO);
						if (result==IDYES)
						{
							HANDLE hProcess,hPToken;
							DWORD id=GetExplorerLogonPid();
							if (id!=0) 
								{
									hProcess = OpenProcess(MAXIMUM_ALLOWED,FALSE,id);
									if(!OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY
													|TOKEN_DUPLICATE|TOKEN_ASSIGN_PRIMARY|TOKEN_ADJUST_SESSIONID
													|TOKEN_READ|TOKEN_WRITE,&hPToken)) return 0;

									char dir[MAX_PATH];
									char exe_file_name[MAX_PATH];
									GetModuleFileName(0, exe_file_name, MAX_PATH);
									strcpy(dir, exe_file_name);
									strcat(dir, " -softwarecadhelper");
		
							
									STARTUPINFO          StartUPInfo;
									PROCESS_INFORMATION  ProcessInfo;
									HANDLE Token=NULL;
									HANDLE process=NULL;
									ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO));
									ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION));
									StartUPInfo.wShowWindow = SW_SHOW;
									StartUPInfo.lpDesktop = "Winsta0\\Default";
									StartUPInfo.cb = sizeof(STARTUPINFO);
				
									CreateProcessAsUser(hPToken,NULL,dir,NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&StartUPInfo,&ProcessInfo);
									DWORD errorcode=GetLastError();
									if (process) CloseHandle(process);
									if (Token) CloseHandle(Token);
									if (ProcessInfo.hProcess) CloseHandle(ProcessInfo.hProcess);
									if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread);
									if (errorcode==1314)
									{
										Enable_softwareCAD_elevated();
									}
								}
						}
					}
					if (ISUACENabled() && IsSoftwareCadEnabled())
					{
//.........这里部分代码省略.........
开发者ID:polyu,项目名称:Cloud_Game,代码行数:101,代码来源:vistahook.cpp


示例18: GetModuleFileName

//===========================================================
// Entry point where control comes on an unhandled exception
//===========================================================
LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter(
PEXCEPTION_POINTERS pExceptionInfo)
{
    TCHAR module_folder_name[MAX_PATH];
    GetModuleFileName(0, module_folder_name, MAX_PATH);
    TCHAR* pos = _tcsrchr(module_folder_name, '\\');
    if (!pos)
        return 0;
    pos[0] = '\0';
    ++pos;

    TCHAR crash_folder_path[MAX_PATH];
    sprintf(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder);
    if (!CreateDirectory(crash_folder_path, NULL))
    {
        if (GetLastError() != ERROR_ALREADY_EXISTS)
            return 0;
    }

    SYSTEMTIME systime;
    GetLocalTime(&systime);
    sprintf(m_szDumpFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].dmp",
        crash_folder_path, _HASH, pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);

    sprintf(m_szLogFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].txt",
        crash_folder_path, _HASH, pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);

    m_hDumpFile = CreateFile(m_szDumpFileName,
        GENERIC_WRITE,
        0,
        0,
        OPEN_ALWAYS,
        FILE_FLAG_WRITE_THROUGH,
        0);

    m_hReportFile = CreateFile(m_szLogFileName,
        GENERIC_WRITE,
        0,
        0,
        OPEN_ALWAYS,
        FILE_FLAG_WRITE_THROUGH,
        0);

    if (m_hDumpFile)
    {
        MINIDUMP_EXCEPTION_INFORMATION info;
        info.ClientPointers = FALSE;
        info.ExceptionPointers = pExceptionInfo;
        info.ThreadId = GetCurrentThreadId();

        MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
            m_hDumpFile, MiniDumpWithIndirectlyReferencedMemory, &info, 0, 0);

        CloseHandle(m_hDumpFile);
    }

    if (m_hReportFile)
    {
        SetFilePointer(m_hReportFile, 0, 0, FILE_END);

        GenerateExceptionReport(pExceptionInfo);

        CloseHandle(m_hReportFile);
        m_hReportFile = 0;
    }

    if (m_previousFilter)
        return m_previousFilter(pExceptionInfo);
    else
        return EXCEPTION_EXECUTE_HANDLER/*EXCEPTION_CONTINUE_SEARCH*/;
}
开发者ID:Bootz,项目名称:TrueBlood-Dev-Server,代码行数:74,代码来源:WheatyExceptionReport.cpp


示例19: RNG_SystemInfoForRNG


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetCurrentTime函数代码示例发布时间:2022-05-30
下一篇:
C++ GetCurrentThread函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap