Hi Guys,
I am trying to develop a fax application using the winfax API but i am
running into a problem at the FaxSendDocument call.
If i call FaxSendDocument the program terminates and start Ollydbg however
if i call FaxSendDocumentW then the program runs normally but it will not
find the file i am trying to send even if the file is available in the
directory.
The problem seems to be Ansi string vs Unicode String but i am sure. I am
running on a windows 2000 PC.
Any help greatly appreciated.

Shiny

;---------------------MakeFile-----------------------------------------------
FaxApp.exe: FaxApp.obj FaxDlg.res
Link /SUBSYSTEM:WINDOWS FaxApp.obj FaxDlg.res
FaxDlg.res: FaxDlg.rc
rc FaxDlg.rc
FaxApp.obj: FaxApp.asm
ml /c /coff FaxApp.asm
;----------------------------------------------------------------------------------

.486
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive

;----------------IMPORT LIBRARIES----------------------------------------
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \Masm32\lib\winfax.lib
;-------------------------------------------------------------------------------------

;----------------INCLUDE FILES------------------------------------------------
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \Masm32\include\winfax.inc
;--------------------------------------------------------------------------------------

;----------------PROCEDURE PROTOTYPES--------------------------------
SendProc proto hWnd:UINT
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
PERR PROTO :DWORD
;---------------------------------------------------------------------------------------

.const
btnSend equ 1004

.data
RName db "Shiny",0
RNumber db "228547",0
SName db "Shiny",0
SNumber db "202992",0
SId db "Gainaco",0
TPage db "confident.cov",0
msg db "Successful",0
AppName db "Fax Application",0
dlgName db "FaxDialog",0


.data?
hFax dd ?
hInstance dd ?
CommandLine dd ?
JobId dd ?

.code

start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
;Show dialogbox
invoke DialogBoxParam,hInstance,ADDR dlgName,NULL, addr DlgProc,NULL

invoke ExitProcess,0


DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,uMsg
.if eax==WM_INITDIALOG
.elseif eax==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0FFFFh
.if edx==BN_CLICKED
.if eax==btnBrowse
.elseif eax==btnSend
INVOKE SendProc, hWin
.elseif eax==btnCancel
.endif
.endif
.elseif eax==WM_CLOSE
invoke EndDialog,hWin,0
.else
mov eax,FALSE
ret
.endif

mov eax,TRUE
ret
DlgProc endp

SendProc proc hWnd:UINT
LOCAL fjp:FAX_JOB_PARAMA
LOCAL fci:FAX_COVERPAGE_INFOA

INVOKE FaxConnectFaxServer, NULL, ADDR hFax

cmp eax, 0 ;If equals an error has occured
je ErrorMessage
mov fjp.SizeOfStruct, SIZEOF FAX_JOB_PARAMA
mov fjp.RecipientNumber, OFFSET RNumber
mov fjp.RecipientName, OFFSET RName
mov fjp.Tsid, OFFSET SId
mov fjp.SenderName, OFFSET SName
mov fjp.ScheduleAction, JSA_NOW
mov fjp.DeliveryReportType, DRT_NONE
mov fjp.DeliveryReportAddress, NULL

mov fci.SizeOfStruct, SIZEOF FAX_COVERPAGE_INFOA

INVOKE FaxSendDocumentW, hFax, ADDR TPage, ADDR fjp, ADDR fci, ADDR JobId

cmp eax, 0 ;If equals an error has occured
je ErrorMessage
invoke MessageBox,hWnd,addr msg,addr AppName,MB_OK
jmp EndError
ErrorMessage:
INVOKE PERR, hWnd

EndError:

ret
SendProc endp


PERR PROC uses ebx edi esi hWnd:DWORD
LOCAL szMsgBuf[200]:BYTE

INVOKE GetLastError
mov ebx, eax
INVOKE FormatMessage, \
FORMAT_MESSAGE_FROM_SYSTEM,\
NULL, \
ebx, \ ;Message Id
LANG_NEUTRAL + SUBLANG_DEFAULT*1024, \ ;Message language
ADDR szMsgBuf, \ ;Buffer to store message
500, \ ;Buffer size
NULL ;No more arguments
INVOKE MessageBox, hWnd, ADDR szMsgBuf, NULL, MB_OK

ret
PERR ENDP

end start
;---------------------------------------------------------------------------------------



;---------------------FaxDlg.rc-------------------------------------------------------------
#define IDDD 1000
#define btnSend 1004
FaxDialog DIALOGEX 4,4,100,44
CAPTION "Send Fax Document"
FONT 12,"MS Sans Serif"
STYLE 0x10CE0000
EXSTYLE 0x00000000
BEGIN

PUSHBUTTON "Send",btnSend,30,20,57,12,NOT 0x00820000|0x50010000,0x00000000

END
;-------------------------------------------------------------------------------------------



;---------------------------------Structures------------------------------------------------
FAX_COVERPAGE_INFOA STRUCT
SizeOfStruct DWORD ? ; Size of this structure
CoverPageName LPCSTR ? ; coverpage document name
UseServerCoverPage BOOL ? ; coverpage exists on the fax server
RecName LPCSTR ? ;
RecFaxNumber LPCSTR ? ;
RecCompany LPCSTR ? ;
RecStreetAddress LPCSTR ? ;
RecCity LPCSTR ? ;
RecState LPCSTR ? ;
RecZip LPCSTR ? ;
RecCountry LPCSTR ? ;
RecTitle LPCSTR ? ;
RecDepartment LPCSTR ? ;
RecOfficeLocation LPCSTR ? ;
RecHomePhone LPCSTR ? ;
RecOfficePhone LPCSTR ? ;
SdrName LPCSTR ? ;
SdrFaxNumber LPCSTR ? ;
SdrCompany LPCSTR ? ;
SdrAddress LPCSTR ? ;
SdrTitle LPCSTR ? ;
SdrDepartment LPCSTR ? ;
SdrOfficeLocation LPCSTR ? ;
SdrHomePhone LPCSTR ? ;
SdrOfficePhone LPCSTR ? ;
Note LPCSTR ? ;
Subject LPCSTR ? ;
TimeSent SYSTEMTIME <> ; Time the fax was sent
PageCount DWORD ? ; Number of pages
FAX_COVERPAGE_INFOA ENDS


FAX_JOB_PARAMA STRUCT
SizeOfStruct DWORD ? ; size of this structure
RecipientNumber LPCSTR ? ; recipient fax number
RecipientName LPCSTR ? ; recipient name
Tsid LPCSTR ? ; transmitter's id
SenderName LPCSTR ? ; sender name
SenderCompany LPCSTR ? ; sender company
SenderDept LPCSTR ? ; sender department
BillingCode LPCSTR ? ; billing code
ScheduleAction DWORD ? ; when to schedule the fax, see JSA defines
ScheduleTime SYSTEMTIME <> ; time to send the fax when JSA_SPECIFIC_TIME is used (must be local time)
DeliveryReportType DWORD ? ; delivery report type, see DRT defines
DeliveryReportAddress LPCSTR ? ; email address for delivery report (ndr or dr) thru MAPI / SMTP
DocumentName LPCSTR ? ; document name (optional)
CallHandle DWORD 0 ; optional call handle
Reserved DWORD 3 dup(0) ; reserved for ms use only
FAX_JOB_PARAMA ENDS
;--------------------------------------------------------------------------------------------


---------------------Equates--------------------------------------------------------
JSA_NOW equ 00000000h
DRT_NONE equ 00000000h
;-----------------------------------------------------------------------------------
Posted on 2003-05-29 05:52:59 by shiny
Hi

I have managed to figure out the problem. The problem is that FAX_JOB_PARAMA and FAX_COVERPAGE_INFOA structures should not be declared as local. They should be in the data section. I have successfully sent a fax with the program.

shiny
Posted on 2003-07-03 06:09:20 by shiny