forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Generic procedure interface using external procedures

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Thu Feb 21, 2013 9:22 am    Post subject: Generic procedure interface using external procedures Reply with quote

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
View user's profile Send private message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Thu Feb 21, 2013 9:39 am    Post subject: Reply with quote

Just figured it out myself! Very Happy

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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