📄 exports.cpp
字号:
WriteDebugString(L"%s",L"CR_ERROR");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
return FALSE;
break;
case CR_CNCT: //连接建立,对方为语音信号
case CR_FAXTONE: //连接建立,对方为传真信号
{
DF_IOTT *iott;
char * szFileName;
EnterCriticalSection(&pd->cs);
szFileName = WStringToString(FaxSend->FileName);
LeaveCriticalSection(&pd->cs);
if (NULL == szFileName)
{
WriteDebugString(L"%s",L"FaxDevSend: Error Not Enough Memory");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
return FALSE;
}
int filehandle = dx_fileopen(szFileName,O_RDONLY|O_BINARY,0);
if (filehandle == -1)
{
WriteDebugString(L"%s",L"FaxDevSend: Error Dialogic Function Call dx_fileopen error");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
MemFreeMacro(szFileName);
return FALSE;
}
MemFreeMacro(szFileName);
unsigned short Pages = GetTiffPages(FaxSend->FileName);
if (0 == Pages)
{
WriteDebugString(L"%s",L"FaxDevSend: Error Not Enough Memory");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
dx_fileclose(filehandle);
return FALSE;
}
EnterCriticalSection(&pd->cs);
pJobInfo->TotoalPages = Pages;
LeaveCriticalSection(&pd->cs);
iott = (DF_IOTT *)MemAllocMacro(sizeof(DF_IOTT)*Pages);
if (NULL == iott)
{
WriteDebugString(L"%s",L"FaxDevSend: Error Not Enough Memory");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
dx_fileclose(filehandle);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
for ( unsigned short i = 0 ; i < Pages ; i++)
{
iott[i].io_offset = (long)i;
iott[i].io_length = 1L;
iott[i].io_fhandle = filehandle;
iott[i].io_type = IO_DEV | IO_CONT;
iott[i].io_datatype = DF_TIFF;
iott[i].io_phdcont = DFC_MPS;
}
iott[i - 1].io_type = IO_DEV | IO_EOT;
iott[i - 1].io_phdcont = DFC_EOP;
int cont;
cont = DFC_MPS;
fx_setparm(pd->FaxHandle,FC_SENDCONT,(void*)&cont);
cont = DF_HDRDISABLE;
fx_setparm(pd->FaxHandle,FC_HDRATTRIB,(void *)&cont);
char * szLocalId;
szLocalId = WStringToString(FaxSend->CallerNumber);
fx_setparm(pd->FaxHandle,FC_LOCALID,(void *)szLocalId);
MemFreeMacro(szLocalId);
cont = DF_RETRYDCN | DF_RETRY2;
fx_setparm(pd->FaxHandle,FC_RETRYCNT,(void *)&cont);
cont = DF_MMR;
fx_setparm(pd->FaxHandle,FC_TXCODING,(void *)&cont);
nRet = fx_sendfax(pd->FaxHandle,iott,DF_PHASED|DF_PHASEB|EV_SYNC);
if (nRet == -1)
{
dx_fileclose(filehandle);
switch(ATDV_LASTERR(pd->FaxHandle))
{
case EFX_BADTIF: //TIFF 文件格式不支持
case EFX_BADTAG: //页面TIFF标记错误
case EFX_NOPAGE: //没有该页
case EFX_BADPAGE: //页面错误
case EFX_BADIOTT:
case EFX_RETRYDCN:
WriteDebugString(L"FaxDevSend: Error ");
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_FATAL_ERROR;
SetLastError(ERROR_FILE_NOT_FOUND);
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
MemFreeMacro(iott);
return FALSE;
break;
case EFX_DISCONNECT:
/* WriteDebugString(L"%s,Pager#:%d Total#:%d",L"Disconnected",pJobInfo->PageCount,Pages);
if (pJobInfo->PageCount == Pages)
{
WriteDebugString(L"%s",L"EFX_DISCONNECT");
MemFreeMacro(iott);
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_COMPLETED;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
return TRUE;
}
else
{
*/
EnterCriticalSection(&pd->cs);
pJobInfo->Status = FS_DISCONNECTED;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
MemFreeMacro(iott);
return FALSE;
// }
break;
}
}
dx_fileclose(filehandle);
MemFreeMacro(iott);
EnterCriticalSection(&pd->cs);
WriteDebugString(L"%s",L"FaxDevSend: Information Send Completed");
pJobInfo->Status = FS_COMPLETED;
PostJobStatus2(pd,ERROR_SUCCESS);
LeaveCriticalSection(&pd->cs);
WriteDebugString(L"%s",L"========FaxDevSend Normal Leave========");
return TRUE;
}
break;
}
WriteDebugString(L"%s",L"========FaxDevSend Failure Leave========");
return FALSE;
}
BOOL WINAPI FaxDevStartJob(
IN HLINE LineHandle,
IN DWORD DeviceId,
OUT PHANDLE FaxHandle,
IN HANDLE CompletionPortHandle,
IN ULONG_PTR CompletionKey
)
{
WriteDebugString(L"%s",L"========FaxDevStartJob Enter========");
PJOB_INFO pJobInfo;
PDEVICE_INFO pd;
*FaxHandle = NULL;
/*
PDEVICE_INFO pDeviceInfo = g_pDeviceInfo[DeviceId];
EnterCriticalSection(&pDeviceInfo->cs);
if (pDeviceInfo->Status != DEVICE_IDLE)
{
WriteDebugString(L"FaxDevStartJob: Not Idle , return false");
LeaveCriticalSection(&pDeviceInfo->cs);
return FALSE;
}
LeaveCriticalSection(&pDeviceInfo->cs);
*/
//校验所有堆,确认他们的可用性
/* DWORD dwHeaps;
HANDLE hHeap[50];
dwHeaps = GetProcessHeaps(50,hHeap);
WriteDebugString(L"Heap Count:%d",dwHeaps);
for (DWORD dwCount = 0 ; dwCount < dwHeaps ; dwCount ++)
{
if (HeapValidate(hHeap[dwCount],0,NULL) == FALSE)
WriteDebugString(L"%s",L"Error in some Heap");
}
if(!HeapValidate(g_HeapHandle,0,NULL))
WriteDebugString(L"%s",L"Error in main Heap");
*/
//创建JOB_INFO对象
pJobInfo = (PJOB_INFO)(MemAllocMacro(sizeof(JOB_INFO)));
if (NULL == pJobInfo)
{
WriteDebugString(L"%s",L"FaxDevStartJob: Allocate Job_Info Error , outof memory");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
pd = g_pDeviceInfo[DeviceId];
*FaxHandle = (PHANDLE)pJobInfo;
EnterCriticalSection(&pd->cs);
pJobInfo->CompletionPortHandle = CompletionPortHandle;
pJobInfo->CompletionKey = CompletionKey;
pJobInfo->JobType = JOB_UNKNOWN;
pJobInfo->Branding = FALSE;
pJobInfo->CallerId = NULL;
pJobInfo->CallerName = NULL;
pJobInfo->CallerNumber = NULL;
pJobInfo->ReceiverName = NULL;
pJobInfo->ReceiverNumber = NULL;
pJobInfo->RetryCount = 0;
pJobInfo->CallHandle = (HCALL)0;
pJobInfo->CSI = NULL;
pJobInfo->FileName = NULL;
pJobInfo->LineHandle = LineHandle;
pJobInfo->PageCount = 0;
pJobInfo->TotoalPages = 0;
pJobInfo->RoutingInfo = NULL;
pJobInfo->Status = FS_INITIALIZING;
pJobInfo->pDeviceInfo = pd;
pd->Status = DEVICE_START;
pd->pJobInfo = pJobInfo;
LeaveCriticalSection(&pd->cs);
WriteDebugString(L"%s",L"========FaxDevStartJob Leave========");
return TRUE;
}
//==============================================================================
//函数:FaxDevVirtualDeviceCreation
//功能:返回虚拟设备的数目和名字前缀以及ID前缀,Fax Service 将根据这些数据生成
// 虚拟传真线路,还需要保存的就是CompletionPort和Completionkey
//参数:
// OUT LPDWORD DeviceCount
// OUT LPWSTR DeviceNamePrefix
// OUT LPDWORD DeviceIdPrefix
// IN HANDLE CompletionPort
// IN ULONG_PTR CompletionKey
//返回值:TRUE FALSE
//==============================================================================
BOOL WINAPI FaxDevVirtualDeviceCreation(
OUT LPDWORD DeviceCount,
OUT LPWSTR DeviceNamePrefix,
OUT LPDWORD DeviceIdPrefix,
IN HANDLE CompletionPort,
IN ULONG_PTR CompletionKey
)
{
WriteDebugString(L"%s",L"=========FaxDevVirtualDeviceCreation Start========");
*DeviceCount = 0, *DeviceIdPrefix = 0;
ZeroMemory(DeviceNamePrefix,128*sizeof(WCHAR));
HKEY hKey = ERROR_SUCCESS;
BOOL bRet = FALSE;
LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,DEVICE_LINES_REG,0,KEY_ALL_ACCESS,&hKey);
if (lRet == ERROR_SUCCESS)
{
//读取当前配置的线路信息
lRet = RegQueryInfoKey(hKey,NULL,NULL,NULL,NULL,NULL,NULL,
&g_dwLines,NULL,NULL,NULL,NULL);
if (lRet == ERROR_SUCCESS)
{
lstrcpyn(DeviceNamePrefix,DEVICE_NAME_PREFIX,128);
if (g_dwLines >= MAX_LINES)
g_dwLines = MAX_LINES;
bRet = TRUE;
}
RegCloseKey(hKey);
}
//虚拟线路数目
*DeviceCount = g_dwLines;
//虚拟线路ID前缀
*DeviceIdPrefix = DEVICE_ID_PREFIX;
//模拟振铃Fax Server IOCP
g_hIocpRing = CompletionPort;
//模拟振铃Fax Server Completion Key
g_dwComKeyRing = CompletionKey;
//虚拟线路名称前缀
lstrcpyn(DeviceNamePrefix,DEVICE_NAME_PREFIX,128);
WriteDebugString(L"%s",L"=========FaxDevVirtualDeviceCreation End========");
return bRet;
}
VOID CALLBACK FaxLineCallback(
IN HANDLE FaxHandle,
IN DWORD hDevice,
IN DWORD dwMessage,
IN DWORD_PTR dwInstance,
IN DWORD_PTR dwParam1,
IN DWORD_PTR dwParam2,
IN DWORD_PTR dwParam3
)
{
int nRet;
WriteDebugString(L"%s",L"============FaxLineCallback Start============");
if (dwMessage == LINE_DEVSPECIFIC) //Device Config Event
{
PDEVICE_INFO pd;
pd = g_pDeviceInfo[hDevice - DEVICE_ID_PREFIX];
if (dwParam1) //Enable Receive Fax
{
EnterCriticalSection(&pd->cs);
pd->EnableReceive = 1;
LeaveCriticalSection(&pd->cs);
if (pd->Status == DEVICE_IDLE)
{
nRet = dx_setevtmsk(pd->VoxHandle,DM_RINGS);
if (nRet == -1)
WriteDebugString(L"%s",L"FaxLineCallback: Dialogic Function Call dx_setevtmsk error");
nRet = dx_setparm(pd->VoxHandle,DXCH_RINGCNT,(void *)&(pd->Rings));
if (nRet == -1)
WriteDebugString(L"%s",L"FaxLineCallback: Dialogic Function Call dx_setparm error");
}
}
else
{
EnterCriticalSection(&pd->cs);
pd->EnableReceive = 0;
LeaveCriticalSection(&pd->cs);
if(pd->Status == DEVICE_IDLE)
{
nRet = dx_setevtmsk(pd->VoxHandle,0);
if (nRet == -1)
WriteDebugString(L"%s",L"FaxLineCallback: Dialogic Function Call dx_setevtmsk RINGS OFF errro");
}
}
}
WriteDebugString(L"%s",L"============FaxLineCallback End============");
return;
}
STDAPI DllRegisterServer()
{
// HRESULT hr;
HANDLE hModWinfax;
WCHAR szDestinationFilename[MAX_PATH+1];
PFAXREGISTERSERVICEPROVIDER pFaxRegisterServiceProvider;
hModWinfax = LoadLibrary( L"winfax.dll" );
if (hModWinfax == NULL) {
WriteDebugString(L" ERROR: LoadLibrary Failed: 0x%08x\n", GetLastError());
WriteDebugString(L" ERROR: DllRegisterServer Failed\n");
WriteDebugString(L"---NewFsp: DllRegisterServer Exit---\n");
return E_UNEXPECTED;
}
pFaxRegisterServiceProvider = (PFAXREGISTERSERVICEPROVIDER) GetProcAddress((HINSTANCE)hModWinfax, "FaxRegisterServiceProviderW");
if (pFaxRegisterServiceProvider == NULL) {
WriteDebugString(L" ERROR: GetProcAddress Failed: 0x%08x\n", GetLastError());
WriteDebugString(L" ERROR: DllRegisterServer Failed\n");
FreeLibrary((HINSTANCE)hModWinfax);
WriteDebugString(L"---NewFsp: DllRegisterServer Exit---\n");
return E_UNEXPECTED;
}
//ExpandEnvironmentStrings(PROVIDER_IMAGENAME,szDestinationFilename,MAX_PATH);
// Register the fax service provider
if (pFaxRegisterServiceProvider(L"SIVFax", L"SIVFax", PROVIDER_IMAGENAME, L"SIVFax") == FALSE) {
WriteDebugString(L" ERROR: FaxRegisterServiceProvider Failed: 0x%08x\n", GetLastError());
WriteDebugString(L" ERROR: DllRegisterServer Failed\n");
FreeLibrary((HINSTANCE)hModWinfax);
WriteDebugString(L"---NewFsp: DllRegisterServer Exit---\n");
return E_UNEXPECTED;
}
FreeLibrary((HINSTANCE)hModWinfax);
return S_OK;
}
STDAPI DllUnregisterServer()
{
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -