c代碼:
void GetNextEventExample()
{
DWORD Tid;
//Note: getting events process has to be done in a separate thread!
hThread = CreateThread( NULL,100, GetNextEventLoopInThread, NULL, 0,&Tid );
//The following events will be received by the thread
CtiStartCallExample(); //starting a call. see the call chapter
CtiEndCallExample(); //ending a call. see the call chapter
}static unsigned long __stdcall GetNextEventLoopInThread(void* temp)
{
CLS_RET_CODE RetCode;
GENERIC_EVENT GenericEvent;
long MaxSize = sizeof(ALL_EVENTS_UNION);
GenericEvent.SpecificEvents = new (char[MaxSize]);
do{
// Calling the CAPI in order to retrieve the next event
RetCode = clsGetNextEventEx ( &GenericEvent, MaxSize );
// Note: here you handle the event, if the handling takes a long time
// it shold be done in a different thread
if ( RetCode == CLS_RC_SUCCESS )
DisplayEventDetails( &GenericEvent );
}while ( RetCode == CLS_RC_SUCCESS );
printf("stopped getting events");
delete GenericEvent.SpecificEvents;
// Killing the thread
if ( GetExitCodeThread( hThread, &ThreadExitCode ))
ExitThread( ThreadExitCode );
else
printf("Error: can’t close the thread");
return true;
}ˍˍˍˍˍˍˍˍˍˍˍˍˍˍˍˍˍˍˍ
以前沒有用過thread,上面的c代碼用delphi怎麼實現呢?