Strange return values from Microsoft Fax API

  • Thread starter Thread starter =?ISO-8859-1?Q?Mathias_W=FChrmann?=
  • Start date Start date
?

=?ISO-8859-1?Q?Mathias_W=FChrmann?=

Hi,

I'm using api function FaxConnectFaxServer and FaxEnumJobs from
Microsoft FAX api with VB6 and getting a very strange array returned, it
does not seem like an array at all!

FaxEnumJobs return the correct number of FaxJobs, but the array
containing the interesting data is crappy...

Ubound(myarray) returns numbers like 299307488 (changing with every
call), but when I try to get the value like this: myarray(0).JobID an
error "out of bounds" raises.

Even Ubound(myarray,1) to ubound(myarray,94) returns silly values!

I also tried API GetLastDLLError with no result (there is no error).

Heres the code:

<Code>
Declare Function FaxConnectFaxServerA Lib "winfax.dll" (ByVal
MachineName As String, ByRef FaxHandle As Long) As Long

Declare Function FaxEnumJobsA Lib "winfax.dll" _
(ByVal FaxHandle As Long, ByRef JobEntry() As PFAX_JOB_ENTRY, _
ByRef JobsReturned As Long) _
As Long

Public Type Systemtime
wYear As Long
wMonth As Long
wDayOfWeek As Long
wDay As Long
wHour As Long
wMinute As Long
wSecond As Long
wMilliseconds As Long
End Type

Public Type PFAX_JOB_ENTRY
SizeOfStruct As Long '//structure size, in bytes
JobId As Long '//identifier of fax job
UserName As String '//pointer to user who submitted job
JobType As String '//job type (send/receive)
QueueStatus As String '//set of job status bit flags
Status As String '//status code for device
Size As Long '//size of document, in bytes
PageCount As Long '//total pages in transmission
RecipientNumber As String '//pointer to recipient's fax number
RecipientName As String '//pointer to recipient's name
Tsid As String '//pointer to transmitting station identifier
SenderName As String '//pointer to sender's name
SenderCompany As String '//pointer to sender's company
SenderDept As String '//pointer to sender's department
BillingCode As String '//pointer to billing code
ScheduleAction As Long '//job scheduling action code
ScheduleTime As Systemtime '//local time to schedule job
DeliveryReportType As Long '//e-mail delivery report type
DeliveryReportAddress As String '//pointer to e-mail address
DocumentName As String '//pointer to document name to display
End Type

Public Function GetFaxJobs() As Long
On Error GoTo Err_GetFaxJobs
Dim lngNumberOfJobs as Long
Dim lngHandle As Long
Dim lngRetVal As Long
Dim FaxJobs() As PFAX_JOB_ENTRY
Dim strMachineName as String

strMachineName="WORKER" 'Insert your computer name here

lngRetVal = FaxConnectFaxServerA(strMachineName, lngHandle)
FaxEnumJobsA lngHandle, FaxJobs, lngNumberOfJobs

msgbox lngNumberOfJobs & vbcrlf & _
ubound(FaxJobs) & vbcrlf & _
ubound(FaxJobs, 1)

'This causes an error
msgbox FaxJobs(0).JobID & vbcrlf & faxJobs(0).Status

Exit Function

Err_GetFaxJobs:
msgbox Err.Number & " " & Err.Description
End Function

</Code>


Did I miss something? This drives me crazy!

BTW: Using GetFaxJob does not change much. The API executes without
erros but my PFAX_JOB_ENTRY structure contains a value at range
160952328 for .StructureSize and empty values for strings and 0 for longs.

Every time an array should be return from the API, nonsense is given
back. This seems to be a consistent problem, so whats going wrong? False
declarations?

Thank you,

Mathias Wuehrmann
 
I am not really familiar with using C functions in VB6 apps but you can try
this, instead of using FaxJobs index as 0 try starting with an index of 1
and see if it succeeds. meanwhile considering that you are programming in VB
why are you not making use of the COM models available for fax service. If
you are using Win2k then you can make use of the legacy COM model (
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fax/faxlegacy_9lf4.asp)
and if you are using Win XP or greater you can use
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fax/faxabout_699l.asp.


Thanks,
--
Chandrasekar R
Microsoft Printing, Imaging and Fax Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
 
Back
Top