?? faxapi.cpp
字號(hào):
/*****************************************************************************
* RelayFax Open Source Project
* Copyright 1996-2004 Alt-N Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the RelayFax Open
* Source License. A copy of this license is available in file LICENSE
* in the top-level directory of the distribution.
*
* RelayFax is a registered trademark of Alt-N Technologies, Ltd.
*
* Individual files and/or contributed packages may be copyright by
* other parties and subject to additional restrictions.
*****************************************************************************/
#include "stdafx.h"
#include "FaxAPI.h"
#include "ModemDetect.h"
#include "ClassOne.h"
#include "ClassOnePointZero.h"
#include "ClassTwo.h"
#include "ClassTwoPointZero.h"
#include "ClassTwoPointOne.h"
HINSTANCE g_Instance = NULL;
//////////////////////////////////////////////////////////////////////
// TiffWarningHandler
//////////////////////////////////////////////////////////////////////
static void TiffWarningHandler(const char* module, const char* fmt, va_list ap)
{
#ifdef DEBUG
char buf[256] = {0};
_vsnprintf( buf, sizeof(buf) - 1, fmt, ap);
OutputDebugString( "Warning: " );
OutputDebugString( buf );
OutputDebugString( "\n" );
#endif
}
//////////////////////////////////////////////////////////////////////
// TiffErrorHandler
//////////////////////////////////////////////////////////////////////
static void TiffErrorHandler(const char* module, const char* fmt, va_list ap)
{
#ifdef DEBUG
char buf[256] = {0};
_vsnprintf( buf, sizeof(buf) - 1, fmt, ap);
OutputDebugString( "Error: " );
OutputDebugString( buf );
OutputDebugString( "\n" );
#endif
}
//////////////////////////////////////////////////////////////////////
// DllMain
//////////////////////////////////////////////////////////////////////
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD dwReason,
LPVOID lpReserved
)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
g_Instance = (HINSTANCE)hModule;
CHiddenWindow::RegisterWindowClass( g_Instance );
// set tiff error handlers
TIFFSetErrorHandler( TiffErrorHandler );
TIFFSetWarningHandler( TiffWarningHandler );
break;
case DLL_PROCESS_DETACH:
CHiddenWindow::UnRegisterWindowClass();
break;
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// FaxApiGetModem - internal function
//////////////////////////////////////////////////////////////////////
CModem* FaxApiGetModem( FaxApiModem pModem )
{
// check the obvious
if( pModem == NULL )
return NULL;
// and the not so obvious
if( IsBadWritePtr( pModem, sizeof(CModem) ) )
{
return NULL;
}
// cast it
return (CModem*) pModem;
}
//////////////////////////////////////////////////////////////////////
// FaxApiCreateModem
//////////////////////////////////////////////////////////////////////
FaxApiModem FAXAPI_CALL FaxApiCreateModem( int nClass )
{
FaxApiModem pModem = NULL;
CModem* pMdm;
switch( nClass )
{
case FAXAPI_DETECT:
pMdm = new CModemDetect;
break;
case FAXAPI_CLASS_1:
pMdm = new CClassOne;
break;
case FAXAPI_CLASS_1_0:
pMdm = new CClassOnePointZero;
break;
case FAXAPI_CLASS_2:
pMdm = new CClassTwo;
break;
case FAXAPI_CLASS_2_0:
pMdm = new CClassTwoPointZero;
break;
case FAXAPI_CLASS_2_1:
pMdm = new CClassTwoPointOne;
break;
default:
pMdm = NULL;
break;
}
if( pMdm )
{
pModem = pMdm;
}
return pModem;
}
//////////////////////////////////////////////////////////////////////
// FaxApiDeleteMessage
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiDeleteMessage( MSG* pMsg )
{
// todo: check pMsg->cbm_cbSize
if( pMsg == NULL )
{
return FAXAPI_ERROR_BAD_MSG;
}
if( pMsg->lParam == NULL )
{
return FAXAPI_ERROR_BAD_MSG;
}
switch( pMsg->lParam )
{
case FAXAPI_EVENT_DETECT_FINISHED:
{
FaxApiModemDetectMsg* pMMsg = (FaxApiModemDetectMsg*)pMsg->wParam;
if( IsBadWritePtr( pMMsg, sizeof(FaxApiModemDetectMsg) ) )
{
return FAXAPI_ERROR_BAD_MSG;
}
delete pMMsg;
}
break;
default:
{
FaxApiModemMsg* pMMsg = (FaxApiModemMsg*)pMsg->wParam;
if( IsBadWritePtr( pMMsg, sizeof(FaxApiModemMsg) ) )
{
return FAXAPI_ERROR_BAD_MSG;
}
delete pMMsg;
}
}
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetCommParam
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetCommParam( FaxApiModem pModem, DWORD BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetCommParam( BaudRate, ByteSize, Parity, StopBits );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetFlowControl
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetFlowControl( FaxApiModem pModem, bool bDSRFlowControl, bool bCTSFlowControl, bool bSoftFlowControl )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetFlowControl( bDSRFlowControl, bCTSFlowControl, bSoftFlowControl );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetPort
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetPort( FaxApiModem pModem, char* szPort )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetPort( szPort );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetSpkrParams
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetSpkrParams( FaxApiModem pModem, int nSpkrVol, int nSpkrMode )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetSpkrParams( nSpkrVol, nSpkrMode );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetDistinctiveRing
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetDistinctiveRing( FaxApiModem pModem, LPCSTR szRingCodes )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetDistinctiveRing( szRingCodes );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetInitString
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetInitString( FaxApiModem pModem, LPCSTR szString )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetInitString( szString );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetSendEncoding
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetSendEncoding( FaxApiModem pModem, int nEncoding )
{
CModem* pMdm = FaxApiGetModem( pModem );
if( pMdm == NULL )
{
return FAXAPI_ERROR_BAD_MODEM;
}
if( pMdm->ThreadStarted() )
{
// can't change the port once the thread is started.
return FAXAPI_ERROR_THREAD_STARTED;
}
pMdm->SetSendEncoding( nEncoding );
return FAXAPI_SUCCESS;
}
//////////////////////////////////////////////////////////////////////
// FaxApiSetSendECM
//////////////////////////////////////////////////////////////////////
int FAXAPI_CALL FaxApiSetSendECM( FaxApiModem pModem, bool bECMSupported )
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -