Problem, with accessing Excel through COM

Problem, with accessing Excel through COM

I wanted to change original function i have got from Fortran Module Wizard for Excel02.
The variables RowIndex and ColumnIndex are originally supposed to be VARIANTS. I thought
to make them integers, and inside of the body of the function to apply neccessary
transformation to variants. The return value should be pointer
to range object (specified by RowIndex and ColIndex).
Does any have an idea why this does not work?

FUNCTION Worksheet_Cells($OBJECT,RowIndex,ColumnIndex,$STATUS)

use....!whatever is neccessary

!DEC$ ATTRIBUTES DLLEXPORT :: Worksheet_Cells
implicit none
integer(INT_PTR_KIND()),intent(IN) :: $OBJECT !Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
integer :: RowIndex
!DEC$ ATTRIBUTES REFERENCE :: RowIndex
integer :: ColumnIndex
!DEC$ ATTRIBUTES REFERENCE :: ColumnIndex
integer(4),intent(OUT),optional :: $STATUS ! Method status
!DEC$ ATTRIBUTES REFERENCE :: $STATUS
integer(4) $$STATUS,ret
integer(INT_PTR_KIND()) invokeargs
integer(INT_PTR_KIND()),volatile :: $RETURN
integer(INT_PTR_KIND()) Worksheet_Cells
type(VARIANT) vRowIndex,vColumnIndex

!transformation of the integers in variants..might be wrong
call VariantInit(vRowIndex)
vRowIndex%VT=VT_I2
vRowIndex%VU%LONG_VAL=RowIndex
call VariantInit(vColumnIndex)
vColumnIndex%VT=VT_I2
vColumnIndex%VU%LONG_VAL=ColumnIndex

invokeargs=AUTOALLOCATEINVOKEARGS()
call AUTOADDARG(invokeargs,'$RETURN',$RETURN,AUTO_ARG_OUT)
call AUTOADDARG(invokeargs,'$ARG1',vRowIndex,AUTO_ARG_IN)
call AUTOADDARG(invokeargs,'$ARG2',vColumnIndex,AUTO_ARG_IN)
$$STATUS=AUTOINVOKE($OBJECT,238,invokeargs)
if(present($STATUS)) $STATUS=$$STATUS
Worksheet_Cells=$RETURN
call AUTODEALLOCATEINVOKEARGS(invokeargs)
ret=VariantClear(vRowIndex)
ret=VariantClear(vColumnIndex)
END FUNCTION Worksheet_Cells

thnaks

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Ok..now it works, sorry for disturbing...for those who might be interested this is how it should look like:

FUNCTION Worksheet_Cells($OBJECT,RowIndex,ColumnIndex,$STATUS)
!DEC$ ATTRIBUTES DLLEXPORT :: Worksheet_Cells
implicit none
integer(INT_PTR_KIND()),intent(IN) :: $OBJECT !Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
integer :: RowIndex
!DEC$ ATTRIBUTES REFERENCE :: RowIndex
integer :: ColumnIndex
!DEC$ ATTRIBUTES VALUE :: ColumnIndex
integer(4),intent(OUT),optional :: $STATUS ! Method status
!DEC$ ATTRIBUTES REFERENCE :: $STATUS
integer(4) $$STATUS,ret
integer(INT_PTR_KIND()) invokeargs
integer(INT_PTR_KIND()),volatile :: $RETURN
integer(INT_PTR_KIND()) Worksheet_Cells
type(VARIANT) vRowIndex,vColumnIndex

call VariantInit(vRowIndex)
vRowIndex%VT=VT_I2
vRowIndex%VU%SHORT_VAL=RowIndex
call VariantInit(vColumnIndex)
vColumnIndex%VT=VT_I2
vColumnIndex%VU%SHORT_VAL=ColumnIndex
invokeargs=AUTOALLOCATEINVOKEARGS()
call AUTOADDARG(invokeargs,'Cells',$RETURN,AUTO_ARG_OUT,VT_DISPATCH)
call AUTOADDARG(invokeargs,'$ARG1',vRowIndex,AUTO_ARG_IN)
call AUTOADDARG(invokeargs,'$ARG2',vColumnIndex,AUTO_ARG_IN)
!$$STATUS=AUTOINVOKE($OBJECT,238,invokeargs)
$$STATUS=AUTOGETPROPERTYBYID($OBJECT,238,invokeargs)
if(present($STATUS)) $STATUS=$$STATUS
Worksheet_Cells=$RETURN
call AUTODEALLOCATEINVOKEARGS(invokeargs)
ret=VariantClear(vRowIndex)
ret=VariantClear(vColumnIndex)
END FUNCTION Worksheet_Cells

Leave a Comment

Please sign in to add a comment. Not a member? Join today