Software Archive
Read-only legacy content
17061 Discussions

File Handling in COM server.....

Intel_C_Intel
Employee
624 Views
Hi Friends,
I have written a function in my COM server component which accepts the name of a file as an input string.Inside the function I am generating 20 random numbers and storing those numbers into a data file and sending the average of those numbers to the client.Here I am able to build the dll but while I am calling this function either in VB or in ASP it is not responding.
I am attaching the code below. I will be glad if I will get any suggestion from anybody.
Thanks in Advance
Debaprasad Tripathy
tripathd@timken.com

Fortran Code
*****************

function IFileCOMServerClass_CallFile( ObjectData ,&
FileName,&
Avg) result (hresult)
use FileCOMServerClass_Types
use oleaut32
use dfwinty
implicit none
type(FileCOMServerClass_InstanceData) ObjectData
!dec$ attributes reference :: ObjectData
CHARACTER(*), intent(in) :: FileName
TYPE(VARIANT), intent(inout) :: Avg
integer(LONG) hresult
! TODO: Add implementation
REAL x, total,value
INTEGER count,I
OPEN (1, FILE = FileName)
DO I = 1, 20
CALL RANDOM_NUMBER(x)
WRITE (1, '(F6.3)') x * 100.0
END DO
CLOSE(1)
OPEN (1, FILE = FileName)
DO WHILE (.NOT. EOF(1))
count = count + 1
READ (1, *) value
total = total + value
END DO
100 IF ( count .GT. 0) THEN
call VariantInit(Avg)
Avg%vt = VT_R8
Avg%vu%DOUBLE_VAL=total/count
END IF
STOP
hresult = S_OK
end function
0 Kudos
5 Replies
Intel_C_Intel
Employee
624 Views
Remove the STOP statement in your code and it will work.
In general, STOP statements don't belong in DLLs or COM servers.

hth,
John
0 Kudos
Intel_C_Intel
Employee
624 Views
hi john,
it is working great in ASP page after removing STOP from the code.I have a small doubt.By default it creates the data file in c:winntsystem32 .Is it possible to give a particular folder name in the OPEN st.
Thanks,
Debaprasad Tripathy
0 Kudos
Intel_C_Intel
Employee
624 Views
Sure, have the caller specify the full path to the file.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
624 Views
I don't know exactly what's the intention of the code, however, note that writing to WinntSystem32 is a) "impolite" b) if the disk is NTFS and system well configured, you probably won't even be able to write there without Administrator privileges. Consider writing to temp directory (GetTempPath).
0 Kudos
Intel_C_Intel
Employee
624 Views
Hi Jugoslav,

This was my thinking of how the file got to system32:

if the caller doesn't include the full path to the file, then the file is opened in the current directory. If the COM object is called by an ASP page, then the calling app is IIS and system32 is the apps current dir.

In any case, the ASP script should use a full path in the call.

-John
0 Kudos
Reply