|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Thu Feb 21, 2013 9:22 am Post subject: Generic procedure interface using external procedures |
|
|
How to properly define interface for a generic procedure using external "alien" procedures?
What I have now is the following:
Code: |
module ExcelSupport
interface ExcelGetCell
module procedure GetCellInt
module procedure GetCellDouble
module procedure GetCellStr
end interface ExcelGetCell
contains
subroutine GetCellInt(row,col,value)
integer (SELECTED_INT_KIND(9)), intent(in) :: row, col
integer (SELECTED_INT_KIND(9)), intent(out) :: value
C_EXTERNAL ExcelGetCellInt 'ExcelGetCellInt' (val,val,ref)
call ExcelGetCellInt(row,col,value)
end subroutine GetCellInt
subroutine GetCellDouble(row,col,value)
integer (SELECTED_INT_KIND(9)), intent(in) :: row, col
real (SELECTED_REAL_KIND(15,307)), intent(out) :: value
C_EXTERNAL ExcelGetCellDouble 'ExcelGetCellDouble' (val,val,ref)
call ExcelGetCellDouble(row,col,value)
end subroutine GetCellDouble
subroutine GetCellStr(row,col,value)
integer (SELECTED_INT_KIND(9)), intent(in) :: row, col
character(len=*) , intent(out) :: value
C_EXTERNAL ExcelGetCellStr 'ExcelGetCellStr' (val,val,outstring)
call ExcelGetCellStr(row,col,value)
end subroutine GetCellStr
end module ExcelSupport
|
The problem is in the ExcelGetCellStr part. If I directly call C_EXTERNAL ExcelGetCellStr procedure, it works ok. As a part of generic procedure, I get garbage instead of a proper character string. Any ideas? |
|
Back to top |
|
|
jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Thu Feb 21, 2013 9:39 am Post subject: |
|
|
Just figured it out myself!
This seems to work:
Code: |
subroutine GetCellStr(row,col,value)
integer (SELECTED_INT_KIND(9)), intent(in) :: row, col
character(len=*) , intent(out) :: value
character (len=256) :: buf
C_EXTERNAL ExcelGetCellStr 'ExcelGetCellStr' (val,val,outstring)
call ExcelGetCellStr(row,col,buf)
value = buf
end subroutine GetCellStr
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|