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 

COM Interface

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



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Tue May 13, 2008 8:05 am    Post subject: COM Interface Reply with quote

Hello,

die latest version of the FEM software makes use of the COM technologies. This means that I can use Fortran as programming language. However, I am not familiar with COM.

Has anyone perhaps a small getting started example?

Jacques
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Tue May 13, 2008 12:00 pm    Post subject: Reply with quote

FTN95 has no direct interface to COM objects.

The way to achieve this would be to use a C DLL to broker the calls between FTN95 and the COM. You would need some familiarity with COM to achieve this though, but the basic things you need to do (in C/C++) are:

- Call CoInitialize
- Obtain a pointer to an instance of the interface
- The COM object can then be called

If you expose all of this using extern "C" in the C code and then write appropriate C_EXTERNAL statements to use within your Fortran then you can make calls through to the COM object.

There is some sample code below which shows basically how to write this in C (Microsoft C in this example). There are lots of replacements that would have to made for a real world example (mostly the bits with 'My' in) and as such this should not be taken as a full example.

Code:

#import "C:\\Path_to_my_COM_dll" no_namespace named_guids

#define DllExport __declspec(dllexport)

extern "C" DllExport int _MyCRoutine() {
   int ret = 0;
   IMyInterfacePtr pMyIPtr = NULL;
   if (!SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
      return -1;
   if (!SUCCEEDED(pMyIPtr.CreateInstance(__uuidof(MyObjectName))))
      return -2;
   ret = pMyIPtr->SomeInterfaceMethod();
   CoUninitialize();
   return ret;
}



Your Fortran would look something like:

Code:

C_EXTERNAL MYCROUTINE "_MyCRoutine" () : INTEGER
INTEGER i
i = MYCROUTINE()


Hope this helps. If you know what you are doing in C, COM and Fortran then you shouldn't have a problem, otherwise it could get quite tricky.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Thu May 15, 2008 7:10 am    Post subject: Reply with quote

Hi Andrew,

thanks for the example. This is a good starting point for experimenting. It seems however that with my expierence it would take quite a while to get the things working.

As I understand it, one needs to use C/C++ as an interface between COM and Fortran.

Jacques
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 -> General 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