⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exports.cpp

📁 Dialogic VFX传真卡编程,程序实现了在Windows Fax服务中注册Dialogic VFX传真的功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	}
	int val;
	char * szLocalId;
	char * pszFileName = NULL;

	EnterCriticalSection(&pd->cs);
	szLocalId = pd->LOCALID;
	fx_setparm(pd->FaxHandle,FC_LOCALID,(void *)szLocalId);
//	val = DF_RETRYDCN | DF_RETRY2;
//	fx_setparm(pd->FaxHandle,FC_RETRYCNT,(void *)&val);
	val = DFS_EOP;
	fx_setparm(pd->FaxHandle,FC_ENDDOC,(void *)&val);
	val = 50;
	fx_setparm(pd->FaxHandle,FC_RTN,(void *)&val);
	val = 50;
	fx_setparm(pd->FaxHandle,FC_RTP,(void *)&val);
	val = DF_MMR;
	fx_setparm(pd->FaxHandle,FC_RXCODING,(void *)&val);
	val = DF_9600BAUD;
	fx_setparm(pd->FaxHandle,FC_TXBAUDRATE,(void *)&val);
	pszFileName = WStringToString(pJobInfo->FileName);
	LeaveCriticalSection(&pd->cs);
	//DF_RXRESHI |
	char szPath[1024];
	char szTempFileName[1024];
	GetTempPathA(1023,szPath);
	GetTempFileNameA(szPath,"Fax",0,szTempFileName);
	WriteDebugString(L"%S",szTempFileName);
	nRet = fx_rcvfax(pd->FaxHandle,szTempFileName, DF_NOPOLL | DF_TIFF | EV_SYNC | DF_PHASEB | DF_PHASED);
	if (nRet == -1)
	{
		if (ATDV_LASTERR(pd->FaxHandle) == EDX_SYSTEM)
		{
			WriteDebugString(L"%s",L"FaxDevReceive: Error fx_rcvfax error");
			WriteDebugString(L"Error Message:%s",StringToWString(ATDV_ERRMSGP(pd->FaxHandle)));
			EnterCriticalSection(&pd->cs);
			pJobInfo->Status = FS_FATAL_ERROR;
			PostJobStatus2(pd,ERROR_SUCCESS);
			LeaveCriticalSection(&pd->cs);
			MemFreeMacro(pszFileName);
			DeleteFileA(szTempFileName);
			return FALSE;
		}
		else
		{
			WriteDebugString(L"Error Message:%s",StringToWString(ATDV_ERRMSGP(pd->FaxHandle)));
			EnterCriticalSection(&pd->cs);
			pJobInfo->Status = FS_DISCONNECTED ;
			PostJobStatus2(pd,ERROR_SUCCESS);
			LeaveCriticalSection(&pd->cs);
			MemFreeMacro(pszFileName);
			DeleteFileA(szTempFileName);
			return FALSE;
		}
	}
	CopyFileA(szTempFileName,pszFileName,FALSE);
	DeleteFileA(szTempFileName);
	MemFreeMacro(pszFileName);
	EnterCriticalSection(&pd->cs);
	pJobInfo->Status = FS_COMPLETED;
//	WriteDebugString(L"FaxDevReceive:PageCount:%d",pJobInfo->PageCount);
	PostJobStatus2(pd,ERROR_SUCCESS);
	LeaveCriticalSection(&pd->cs);
	WriteDebugString(L"%s",L"=============FaxDevReceive: Infromation Leave=============");
	return TRUE;
}

BOOL WINAPI FaxDevReportStatus(
    IN  HANDLE           FaxHandle OPTIONAL,
    OUT PFAX_DEV_STATUS  FaxStatus,
    IN  DWORD            FaxStatusSize,
    OUT LPDWORD          FaxStatusSizeRequired
	)
{
	WriteDebugString(L"%s",L"========FaxDevReportStatus Enter========");

    PJOB_INFO     pJobInfo;
    PDEVICE_INFO  pDeviceInfo;
    DWORD         dwSize;
    UINT_PTR      upStringOffset;
    if (FaxHandle == NULL) {
        SetLastError(ERROR_INVALID_HANDLE);
        WriteDebugString(L"   ERROR: FaxDevReportStatus Failed: ERROR_INVALID_HANDLE\n");
        return FALSE;
    }

    if (FaxStatusSizeRequired == NULL) {
        SetLastError(ERROR_INVALID_PARAMETER);
        WriteDebugString(L"   ERROR: FaxDevReportStatus Failed: ERROR_INVALID_PARAMETER\n");
        return FALSE;
    }
//	WriteDebugString(L"SizeInfo:%d,%d",sizeof(FAX_DEV_STATUS),FaxStatusSize);
    if ((FaxStatus == NULL) && (FaxStatusSize != 0)) {
        SetLastError(ERROR_INVALID_PARAMETER);
        WriteDebugString(L"   ERROR: FaxDevReportStatus Failed: ERROR_INVALID_PARAMETER\n");
        return FALSE;
    }

    pJobInfo = (PJOB_INFO) FaxHandle;
    pDeviceInfo = (PDEVICE_INFO) pJobInfo->pDeviceInfo;
	if (NULL == pDeviceInfo)
	{
		WriteDebugString(L"%s",L"DeviceInfo is NULL");
		return FALSE;
	}
    EnterCriticalSection(&pDeviceInfo->cs);
    dwSize = sizeof(FAX_DEV_STATUS);
    if (pJobInfo->CSI != NULL) 
	{
//		WriteDebugString(L"CSI:%s",pJobInfo->CSI);
        dwSize += (lstrlen(pJobInfo->CSI) + 1) * sizeof(WCHAR);
    }
    if (pJobInfo->CallerId != NULL) 
	{
//		WriteDebugString(L"CallerId:%s",pJobInfo->CallerId);
        dwSize += (lstrlen(pJobInfo->CallerId) + 1) * sizeof(WCHAR);
    }
    if (pJobInfo->RoutingInfo != NULL) 
	{
//		WriteDebugString(L"RoutingInfo:%s",pJobInfo->RoutingInfo);
        dwSize += (lstrlen(pJobInfo->RoutingInfo) + 1) * sizeof(WCHAR);
    }

    *FaxStatusSizeRequired = dwSize;

    if ((FaxStatus == NULL) && (FaxStatusSize == 0)) 
	{
        LeaveCriticalSection(&pDeviceInfo->cs);
		WriteDebugString(L"%s",L"FaxDevReportStatus: Exit becourse faxstatussize is NULL");
//        WriteDebugString(L"---NewFsp: FaxDevReportStatus Exit---\n");
        return TRUE;
    }

    if (FaxStatusSize < dwSize) {
        LeaveCriticalSection(&pDeviceInfo->cs);
        WriteDebugString(L"   ERROR: FaxDevReportStatus Failed: ERROR_INSUFFICIENT_BUFFER\n");
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return FALSE;
    }

    upStringOffset = sizeof(FAX_DEV_STATUS);
    FaxStatus->SizeOfStruct = sizeof(FAX_DEV_STATUS);

	if (pJobInfo->Status == FS_TRANSMITTING)
	{
		WriteDebugString(L"%s",L"Ohhhhh,TRANSMIITING");
	}

	if (pJobInfo->Status == FS_COMPLETED)
	{
		WriteDebugString(L"%s",L"Ohhhhh,COMPLETED");
//		pJobInfo->Status = 0x20100000;
//		pJobInfo->PageCount = 0;
	}

    FaxStatus->StatusId = pJobInfo->Status;
    FaxStatus->StringId = 0;
    FaxStatus->PageCount = pJobInfo->PageCount;
    if (pJobInfo->CSI != NULL) {
        FaxStatus->CSI = (LPWSTR) ((UINT_PTR) FaxStatus + upStringOffset);
        lstrcpy(FaxStatus->CSI, pJobInfo->CSI);
        upStringOffset += (lstrlen(pJobInfo->CSI) + 1) * sizeof(WCHAR);
    }
    FaxStatus->CallerId = NULL;
    if (pJobInfo->CallerId != NULL) {
        FaxStatus->CallerId = (LPWSTR) ((UINT_PTR) FaxStatus + upStringOffset);
        lstrcpy(FaxStatus->CallerId, pJobInfo->CallerId);
        upStringOffset += (lstrlen(pJobInfo->CallerId) + 1) * sizeof(WCHAR);
    }
    FaxStatus->RoutingInfo = NULL;
    if (pJobInfo->RoutingInfo != NULL) {
        FaxStatus->RoutingInfo = (LPWSTR) ((UINT_PTR) FaxStatus + upStringOffset);
        lstrcpy(FaxStatus->RoutingInfo, pJobInfo->RoutingInfo);
        upStringOffset += (lstrlen(pJobInfo->RoutingInfo) + 1) * sizeof(WCHAR);
    }
    FaxStatus->ErrorCode = ERROR_SUCCESS;
/*
	WriteDebugString(L"PostJobStatus2: StatusId:%8x,PageCount:%d,ErrorCode:%8x",FaxStatus->StatusId,
		FaxStatus->PageCount,FaxStatus->ErrorCode);
	if (FaxStatus->CSI)
		WriteDebugString(L"CSI:%s",FaxStatus->CSI);
	if (FaxStatus->CallerId)
		WriteDebugString(L"CallerId:%s",FaxStatus->CallerId);
	if (FaxStatus->RoutingInfo)
		WriteDebugString(L"RoutingInfo:%s",FaxStatus->RoutingInfo);
*/	
    LeaveCriticalSection(&pDeviceInfo->cs);

	WriteDebugString(L"%s",L"========FaxDevReportStatus Leave========");
	return TRUE;
}

BOOL WINAPI FaxDevSend(
    IN HANDLE              FaxHandle,
    IN PFAX_SEND           FaxSend,
    IN PFAX_SEND_CALLBACK  FaxSendCallback
	)
{
	WriteDebugString(L"%s",L"========FaxDevSend Enter========");
	PJOB_INFO pJobInfo;

	pJobInfo = (PJOB_INFO)FaxHandle;
	PDEVICE_INFO pd;

	pd = pJobInfo->pDeviceInfo;
	
	EnterCriticalSection(&pd->cs);
	pd->Status = DEVICE_SEND;
	pJobInfo->JobType = JOB_SEND;
	pJobInfo->CallHandle = FaxSend->CallHandle;
	if(FaxSend->FileName != NULL)
	{
		pJobInfo->FileName = (LPWSTR)MemAllocMacro((lstrlen(FaxSend->FileName) + 1)*sizeof(WCHAR));
		if(pJobInfo->FileName)
		{
			lstrcpy(pJobInfo->FileName,FaxSend->FileName);
		}
	}

	if (FaxSend->CallerName != NULL) {
		pJobInfo->CallerName = (LPWSTR)MemAllocMacro((lstrlen(FaxSend->CallerName) + 1) * sizeof(WCHAR));
		if (pJobInfo->CallerName) 
		{
            lstrcpy(pJobInfo->CallerName, FaxSend->CallerName);
        }
    }
    if (FaxSend->CallerNumber != NULL) {
        pJobInfo->CallerNumber = (LPWSTR)MemAllocMacro((lstrlen(FaxSend->CallerNumber) + 1) * sizeof(WCHAR));
        if (pJobInfo->CallerNumber) {
            lstrcpy(pJobInfo->CallerNumber, FaxSend->CallerNumber);
        }
    }

    if (FaxSend->ReceiverName != NULL) {
        pJobInfo->ReceiverName = (LPWSTR)MemAllocMacro((lstrlen(FaxSend->ReceiverName) + 1) * sizeof(WCHAR));
        if (pJobInfo->ReceiverName) {
            lstrcpy(pJobInfo->ReceiverName, FaxSend->ReceiverName);
        }
    }

    if (FaxSend->ReceiverNumber != NULL) {
        pJobInfo->ReceiverNumber = (LPWSTR)MemAllocMacro((lstrlen(FaxSend->ReceiverNumber) + 1) * sizeof(WCHAR));
        if (pJobInfo->ReceiverNumber) {
            lstrcpy(pJobInfo->ReceiverNumber, FaxSend->ReceiverNumber);
        }
    }

    pJobInfo->Branding = FaxSend->Branding;
	LeaveCriticalSection(&pd->cs);

	DX_CAP dxcap;
	int nRet;
	nRet = dx_setevtmsk(pd->VoxHandle,0);
	if (nRet == -1)
		WriteDebugString(L"%s",L"FaxDevSend: Dialogic Function Call dx_setevtmsk RINGS OFF errro");
	
	//在任何状态改变的情况下,都应该向Fax Service 报告当前状态
	EnterCriticalSection(&pd->cs);
	pd->Status = DEVICE_SEND;
	pJobInfo->JobType = JOB_SEND;
	pJobInfo->Status = FS_INITIALIZING;
	PostJobStatus2(pd,ERROR_SUCCESS);
	LeaveCriticalSection(&pd->cs);

	nRet = dx_sethook(pd->VoxHandle,DX_ONHOOK,EV_SYNC);
	if (nRet == -1)
	{
		WriteDebugString(L"%s",L"FaxDevSend: dx_sethook ONHOOK error");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
	}
	Sleep(1000);
	nRet = fx_initstat(pd->FaxHandle,DF_TX);
	if (nRet == -1)
	{
		WriteDebugString(L"%s",L"FaxDevSend: fx_initstat error");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
	}
	if (dx_deltones(pd->VoxHandle) == -1) 
	{
		WriteDebugString(L"%s",L"FaxDevSend: dx_deltones error");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
	}
	EnterCriticalSection(&pd->cs);
	pJobInfo->Status = FS_DIALING;
	PostJobStatus2(pd,ERROR_SUCCESS);
	LeaveCriticalSection(&pd->cs);
	
	nRet = dx_sethook(pd->VoxHandle,DX_OFFHOOK,EV_SYNC);
	if (nRet == -1)
	{
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		WriteDebugString(L"%s",L"FaxDevSend: dx_sethook OFFHook Error");
		return TRUE;
	}

	nRet = dx_initcallp(pd->VoxHandle);
	if (nRet == -1)
	{
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		WriteDebugString(L"%s",L"FaxDevSend: Initcallp Error");
		return FALSE;
	}

	dx_clrcap(&dxcap);
	dxcap.ca_nbrdna = (unsigned short)pd->Rings;
	
	char *szDialNumber = WStringToString(FaxSend->ReceiverNumber);
	if(NULL == szDialNumber)
	{
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_FATAL_ERROR;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		WriteDebugString(L"%s",L"FaxDevSend: dx_dial with callp error");
		return FALSE;

	}

	//开始拨号
	nRet = dx_dial(pd->VoxHandle,szDialNumber,0,EV_SYNC | DX_CALLP | DX_CNGTONE);
	if (nRet == -1)
	{
		MemFreeMacro(szDialNumber);
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_LINE_UNAVAILABLE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		WriteDebugString(L"%s",L"FaxDevSend: dx_dial with callp error");
		return FALSE;
	}
	MemFreeMacro(szDialNumber);
	
	//判断拨号状态
	switch(nRet)
	{
	case CR_BUSY:		//线路忙
		WriteDebugString(L"%s",L"CR_BUSY");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_BUSY;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
		break;
	case CR_CEPT:		//用户中断
		WriteDebugString(L"%s",L"CR_CEPT");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_USER_ABORT;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
		break;
	case CR_NOANS:		//没有应答
		WriteDebugString(L"%s",L"CR_NOANS");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_NO_ANSWER;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
		break;
	case CR_NODIALTONE:	//没有拨号音
		WriteDebugString(L"%s",L"CR_NODIALTONE");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_NO_DIAL_TONE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return TRUE;
		break;
	case CR_NORB:		//没有回铃
		WriteDebugString(L"%s",L"CR_NORB");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_NO_DIAL_TONE;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
		break;
	case CR_STOPD:		//强行终止
		WriteDebugString(L"%s",L"CR_STOPD");
		EnterCriticalSection(&pd->cs);
		pJobInfo->Status = FS_USER_ABORT;
		PostJobStatus2(pd,ERROR_SUCCESS);
		LeaveCriticalSection(&pd->cs);
		return FALSE;
		break;
	case CR_ERROR:		//错误

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -