本文整理汇总了C++中HANDLE类的典型用法代码示例。如果您正苦于以下问题:C++ HANDLE类的具体用法?C++ HANDLE怎么用?C++ HANDLE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HANDLE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateThread
HANDLE WINAPI CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
) {
// a thread handle would actually contain an event
// the event would mark if the thread is running or not. it will be used in the Wait functions.
HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL);
h->ChangeType(CXHandle::HND_THREAD);
#ifdef __APPLE__
h->m_machThreadPort = MACH_PORT_NULL;
#endif
pthread_attr_t attr;
pthread_attr_init(&attr);
if (dwStackSize > PTHREAD_STACK_MIN)
pthread_attr_setstacksize(&attr, dwStackSize);
if (pthread_create(&(h->m_hThread), &attr, (void*(*)(void*))lpStartAddress, lpParameter) == 0)
h->m_threadValid = true;
else
{
CloseHandle(h);
h = NULL;
}
pthread_attr_destroy(&attr);
if (h && lpThreadId)
// WARNING: This can truncate thread IDs on x86_64.
*lpThreadId = (DWORD)h->m_hThread;
return h;
}
示例2: CreateThread
HANDLE WINAPI CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
) {
// a thread handle would actually contain an event
// the event would mark if the thread is running or not. it will be used in the Wait functions.
// DO NOT use SDL_WaitThread for waiting. it will delete the thread object.
HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL);
h->ChangeType(CXHandle::HND_THREAD);
InternalThreadParam *pParam = new InternalThreadParam;
pParam->threadFunc = lpStartAddress;
pParam->data = lpParameter;
pParam->handle = h;
h->m_nRefCount++;
h->m_hThread = SDL_CreateThread(InternalThreadFunc, (void*)pParam);
if (lpThreadId)
*lpThreadId = SDL_GetThreadID(h->m_hThread);
return h;
}
示例3:
void HandleMgr<DATA, HANDLE>::Release(HANDLE handle)
{
unsigned int index = handle.GetIndex();
if(magicNumbers[index] == handle.GetMagic() && index < data.size())
{
magicNumbers[index] = 0;
freeSlots.push_back(index);
}
}
示例4: usb_svc_setaddress
/**
* Sets the current device configuration
*/
void usb_svc_setaddress(HANDLE hnd, unsigned int adr)
{
/* Sends a zero-length packet and then set the device address */
if(hnd->tsk_write(NULL, 0, USB_SETUP_WRITE_TOUT)==RES_OK)
{
// note: Stall will be performed for the last endpoint used by this handle!!
hnd->dst.as_voidptr = (void*)usb_svc_setaddress_hook;
hnd->src.as_int = adr;
hnd->hcontrol(DCR_HANDLE);
}
}
示例5: ConfigureDacDma
static bool ConfigureDacDma(HANDLE dma_hnd, const DMA_DRIVER_MODE* dma_mode)
{
if(dma_mode->dma_index < INALID_DRV_INDX)
{
if(dma_hnd->res < RES_CLOSED)
{
dma_hnd->hcontrol(DCR_CANCEL);
dma_hnd->close();
}
return dma_hnd->drv_open(dma_mode->dma_index, dma_mode);
}
return true;
}
示例6: releaseHandle
void CHandleMgr <DATA, HANDLE> :: releaseHandle( HANDLE handle )
{
// okresl ktory uchwyt ma byc zwolniony
unsigned int index = handle.getIndex();
// sprawdz, czy na pewno jest prawidlowy
assert( index < m_UserData_.size() );
assert( m_MagicNumbers_[ index ] == handle.getMagic() );
// jesli wszystko sie powiodlo, ustaw magiczna liczbe na 0, co oznacza, ze uchwyt jest pusty
m_MagicNumbers_[ index ] = 0;
// dodaj dany uchwyt do listy wolnych uchwytow
m_FreeSlots_.push_back( index );
}
示例7: tsk_open_new_hnd
//*----------------------------------------------------------------------------
//* Helper functions
//*----------------------------------------------------------------------------
HANDLE tsk_open_new_hnd(DRIVER_INDEX index, const void * mode )
{
HANDLE hnd;
if( (hnd = new CHandle()) )
{
if(!hnd->tsk_open(index, mode))
{
delete hnd;
hnd = NULL;
}
}
return (hnd);
}
示例8: usb_svc_configendpoint
/**
* Sets the current device configuration
*/
void usb_svc_configendpoint(HANDLE hnd, const USBGenericDescriptor* ds)
{
// note: Stall will be performed for the last endpoint used by this handle!!
hnd->dst.as_voidptr = (void*)usb_svc_configendpoints_hook;
hnd->src.as_cvoidptr = ds;
hnd->hcontrol(DCR_HANDLE);
}
示例9: usb_svc_setconfiguration
/**
* Sets the current device configuration
*/
void usb_svc_setconfiguration(HANDLE hnd, unsigned int cfg)
{
// note: Stall will be performed for the last endpoint used by this handle!!
hnd->dst.as_voidptr = (void*)usb_svc_setconfiguration_hook;
hnd->src.as_int = cfg;
hnd->hcontrol(DCR_HANDLE);
}
示例10: usb_svc_unhalt
/**
* Sets the current device configuration
*/
void usb_svc_unhalt(HANDLE hnd, unsigned int eptnum)
{
// note: Stall will be performed for the last endpoint used by this handle!!
hnd->dst.as_voidptr = (void*)usb_svc_unhalt_hook;
hnd->src.as_int = eptnum;
hnd->hcontrol(DCR_HANDLE);
}
示例11: RequestHandler
void usb_cdc_acm_interface::RequestHandler(const void* drv,
const USBGenericRequest *pRequest, HANDLE hnd)
{
/* Check request code */
switch (pRequest->bRequest)
{
case CDCRequest_SET_LINE_CODING:
TRACE1_USB(" sLineCoding");
if (hnd->tsk_read(&lineCoding, sizeof(lineCoding), USB_SETUP_READ_TOUT)==RES_OK)
{
//read OK
TRACE_USB(" rate=%d", lineCoding.dwDTERate);
set_line_coding(drv);
usb_svc_send_control_status(hnd);
}
break;
case CDCRequest_GET_LINE_CODING:
TRACE1_USB(" gLineCoding");
hnd->tsk_write(&lineCoding, sizeof(lineCoding), USB_SETUP_WRITE_TOUT);
break;
case CDCRequest_SET_CONTROL_LINE_STATE:
{
TRACE_USB("sControlLineState(%02x) ", pRequest->wValue);
bControlLineState = (uint8_t)pRequest->wValue;
set_control_line_state(drv);
usb_svc_send_control_status(hnd);
break;
}
default:
TRACE_USB(" Unknown cdc acm request(%d)", pRequest->bRequest);
usb_svc_stall(hnd);
break;
}
}
示例12: OpenProcess
QString ProcessHandle::command() const
{
#ifdef Q_OS_WIN
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, id());
if(!process)
{
throwError("OpenProcessError", tr("Unable to open the process"));
return QString();
}
TCHAR buffer[256];
if(!GetModuleFileNameEx(process, NULL, buffer, 256))
{
throwError("GetModuleFilenameError", tr("Unable to retrieve the executable filename"));
return QString();
}
CloseHandle(process);
return QString::fromWCharArray(buffer);
#else
QProcess process;
process.start(QString("ps h -p %1 -ocommand").arg(id()), QIODevice::ReadOnly);
if(!process.waitForStarted(2000) || !process.waitForReadyRead(2000) || !process.waitForFinished(2000) || process.exitCode() != 0)
{
throwError("GetProcessError", tr("Failed to get the process command"));
return QString();
}
return process.readAll().trimmed();
#endif
}
示例13: CAN_DCR
//*----------------------------------------------------------------------------
//* DCR function
//*----------------------------------------------------------------------------
void CAN_DCR(CAN_INFO drv_info, unsigned int reason, HANDLE param)
{
CAN_DRIVER_DATA* drv_data;
drv_data = drv_info->drv_data;
switch(reason)
{
case DCR_RESET:
//Initialize the driver here
Task* task;
task = usr_task_create_dynamic("CANT", (TASK_FUNCTION) can_thread, 90,
CAN_TASK_STACK_SIZE);
if (task)
{
svc_task_schedule(task);
task->sp->r0.as_cvoidptr = drv_info;
}
break;
case DCR_OPEN:
param->res = RES_OK;
break;
case DCR_CANCEL:
if(param->mode.as_int)
{
param->svc_list_cancel(drv_data->waiting);
} else
{
param->svc_list_cancel(drv_data->helper);
}
break;
}
}
示例14: FindNextFile
BOOL FindNextFile(HANDLE hHandle, LPWIN32_FIND_DATA lpFindData)
{
if (lpFindData == NULL || hHandle == NULL || hHandle->GetType() != CXHandle::HND_FIND_FILE)
return FALSE;
if ((unsigned int) hHandle->m_nFindFileIterator >= hHandle->m_FindFileResults.size())
return FALSE;
CStdString strFileName = hHandle->m_FindFileResults[hHandle->m_nFindFileIterator++];
CStdString strFileNameTest = hHandle->m_FindFileDir + strFileName;
if (IsAliasShortcut(strFileNameTest))
TranslateAliasShortcut(strFileNameTest);
struct stat64 fileStat;
memset(&fileStat, 0, sizeof(fileStat));
if (stat64(strFileNameTest, &fileStat) == -1)
return FALSE;
bool bIsDir = false;
if (S_ISDIR(fileStat.st_mode))
{
bIsDir = true;
}
memset(lpFindData,0,sizeof(WIN32_FIND_DATA));
lpFindData->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
strcpy(lpFindData->cFileName, strFileName.c_str());
if (bIsDir)
lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
if (strFileName[0] == '.')
lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
if (access(strFileName, R_OK) == 0 && access(strFileName, W_OK) != 0)
lpFindData->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
TimeTToFileTime(fileStat.st_ctime, &lpFindData->ftCreationTime);
TimeTToFileTime(fileStat.st_atime, &lpFindData->ftLastAccessTime);
TimeTToFileTime(fileStat.st_mtime, &lpFindData->ftLastWriteTime);
lpFindData->nFileSizeHigh = (DWORD)(fileStat.st_size >> 32);
lpFindData->nFileSizeLow = (DWORD)fileStat.st_size;
return TRUE;
}
示例15: DACC_DCR
/** DACC Driver DCR routine
*
* @param drv_info
* @param reason
* @param param
*/
void DACC_DCR(DACC_INFO drv_info, unsigned int reason, HANDLE param)
{
DACC_DRIVER_DATA drv_data = drv_info->drv_data;
Dacc* pDacc = drv_info->hw_base;
switch(reason)
{
case DCR_RESET:
DACC_off(drv_info);
break;
case DCR_OPEN:
{
DRV_DACC_MODE pMode = (DRV_DACC_MODE)(param->mode.as_voidptr);
if(drv_data->cnt)
{
if(pMode->DACC_MR != pDacc->DACC_MR)
return;
} else
{
DACC_on(drv_info, pMode);
}
pDacc->DACC_CHER = pMode->DACC_CHER;
drv_data->cnt++;
param->res = RES_OK;
break;
}
case DCR_CLOSE:
if(!--drv_data->cnt)
DACC_off(drv_info);
break;
case DCR_CANCEL:
if (drv_data->pending == param)
{
pDacc->DACC_PTCR = DACC_PTCR_TXTDIS;
drv_data->pending = param->next;
if(drv_data->pending)
START_TX_HND(pDacc, drv_data->pending);
svc_HND_SET_STATUS(param, RES_SIG_IDLE);
} else
param->svc_list_cancel(drv_data->pending);
break;
}
}