[code]
//=================================================================
// MonitorThread - Monitors event for timer notification
//
DWORD WINAPI MonitorThread (PVOID pArg) {
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
SMS_HANDLE smshHandle = (SMS_HANDLE)pArg;
PMYMSG_STRUCT pNextMsg;
BYTE bBuffer[MAXMESSAGELEN];
PBYTE pIn;
SYSTEMTIME st;
HANDLE hWait[2];
HRESULT hr;
int rc;
DWORD dwInSize, dwSize, dwRead = 0;
hWait[0] = g_hReadEvent; // Need two events since it isn't
hWait[1] = g_hQuitEvent; // allowed for us to signal SMS event.
while (g_fContinue) {
rc = WaitForMultipleObjects (2, hWait, FALSE, INFINITE);
if (!g_fContinue || (rc != WAIT_OBJECT_0))
break;
// Point to the next free entry in the array
pNextMsg = &g_pMsgDB->pMsgs[g_pMsgDB->nMsgCnt];
// Get the message size
hr = SmsGetMessageSize (smshHandle, &dwSize);
if (hr != ERROR_SUCCESS) continue;
// Check for message larger than std buffer
if (dwSize > sizeof (pNextMsg->wcMessage)) {
if (dwSize > MAXMESSAGELEN)
continue;
pIn = bBuffer;
dwInSize = MAXMESSAGELEN;
} else {
pIn = (PBYTE)pNextMsg->wcMessage;
dwInSize = sizeof (pNextMsg->wcMessage);
}
// Set up provider specific data
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS0;
tpsd.psReplaceOption = PSRO_NONE;
tpsd.dwHeaderDataSize = 0;
// Read the message
hr = SmsReadMessage (smshHandle, NULL, &pNextMsg->smsAddr, &st,
(PBYTE)pIn, dwInSize, (PBYTE)&tpsd,
sizeof(TEXT_PROVIDER_SPECIFIC_DATA),
&dwRead);
if (hr == ERROR_SUCCESS) {
// Convert GMT message time to local time
FILETIME ft, ftLocal;
SystemTimeToFileTime (&st, &ft);
FileTimeToLocalFileTime (&ft, &ftLocal);
FileTimeToSystemTime (&ftLocal, &pNextMsg->stMsg);
// If using alt buffer, copy to std buff
if ((DWORD)pIn == (DWORD)pNextMsg->wcMessage) {
pNextMsg->nSize = (int) dwRead;
} else {
memset (pNextMsg->wcMessage, 0,
sizeof(pNextMsg->wcMessage));
memcpy (pNextMsg->wcMessage, pIn,
sizeof(pNextMsg->wcMessage)-2);
pNextMsg->nSize = sizeof(pNextMsg->wcMessage);
}
// Increment message count
if (g_pMsgDB->nMsgCnt < MAX_MSGS-1) {
if (g_hMain)
PostMessage (g_hMain, MYMSG_TELLNOTIFY, 1,
g_pMsgDB->nMsgCnt);
g_pMsgDB->nMsgCnt++;
}
} else {
ErrorBox (g_hMain, TEXT("Error %x (%d) reading msg"),
hr, GetLastError());
break;
}
}
SmsClose (smshHandle);
return 0;
}
[/code]
//=================================================================
// MonitorThread - Monitors event for timer notification
//
DWORD WINAPI MonitorThread (PVOID pArg) {
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
SMS_HANDLE smshHandle = (SMS_HANDLE)pArg;
PMYMSG_STRUCT pNextMsg;
BYTE bBuffer[MAXMESSAGELEN];
PBYTE pIn;
SYSTEMTIME st;
HANDLE hWait[2];
HRESULT hr;
int rc;
DWORD dwInSize, dwSize, dwRead = 0;
hWait[0] = g_hReadEvent; // Need two events since it isn't
hWait[1] = g_hQuitEvent; // allowed for us to signal SMS event.
while (g_fContinue) {
rc = WaitForMultipleObjects (2, hWait, FALSE, INFINITE);
if (!g_fContinue || (rc != WAIT_OBJECT_0))
break;
// Point to the next free entry in the array
pNextMsg = &g_pMsgDB->pMsgs[g_pMsgDB->nMsgCnt];
// Get the message size
hr = SmsGetMessageSize (smshHandle, &dwSize);
if (hr != ERROR_SUCCESS) continue;
// Check for message larger than std buffer
if (dwSize > sizeof (pNextMsg->wcMessage)) {
if (dwSize > MAXMESSAGELEN)
continue;
pIn = bBuffer;
dwInSize = MAXMESSAGELEN;
} else {
pIn = (PBYTE)pNextMsg->wcMessage;
dwInSize = sizeof (pNextMsg->wcMessage);
}
// Set up provider specific data
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS0;
tpsd.psReplaceOption = PSRO_NONE;
tpsd.dwHeaderDataSize = 0;
// Read the message
hr = SmsReadMessage (smshHandle, NULL, &pNextMsg->smsAddr, &st,
(PBYTE)pIn, dwInSize, (PBYTE)&tpsd,
sizeof(TEXT_PROVIDER_SPECIFIC_DATA),
&dwRead);
if (hr == ERROR_SUCCESS) {
// Convert GMT message time to local time
FILETIME ft, ftLocal;
SystemTimeToFileTime (&st, &ft);
FileTimeToLocalFileTime (&ft, &ftLocal);
FileTimeToSystemTime (&ftLocal, &pNextMsg->stMsg);
// If using alt buffer, copy to std buff
if ((DWORD)pIn == (DWORD)pNextMsg->wcMessage) {
pNextMsg->nSize = (int) dwRead;
} else {
memset (pNextMsg->wcMessage, 0,
sizeof(pNextMsg->wcMessage));
memcpy (pNextMsg->wcMessage, pIn,
sizeof(pNextMsg->wcMessage)-2);
pNextMsg->nSize = sizeof(pNextMsg->wcMessage);
}
// Increment message count
if (g_pMsgDB->nMsgCnt < MAX_MSGS-1) {
if (g_hMain)
PostMessage (g_hMain, MYMSG_TELLNOTIFY, 1,
g_pMsgDB->nMsgCnt);
g_pMsgDB->nMsgCnt++;
}
} else {
ErrorBox (g_hMain, TEXT("Error %x (%d) reading msg"),
hr, GetLastError());
break;
}
}
SmsClose (smshHandle);
return 0;
}
[/code]
'Windows > MFC' 카테고리의 다른 글
Receiving SMS Messages Inside a Managed Application (0) | 2013.10.02 |
---|---|
Need to intercept sms to launch another program (0) | 2013.10.02 |
Sending mail using the Microsoft Windows CE Mail API (0) | 2013.10.02 |
개발자를 위한 스마트폰 애플리케이션 보안 및 코드 서명 모델 방법에 대한 가이드 (0) | 2013.10.02 |
Windows Mobile POOM Sample Code (0) | 2013.10.02 |