View previous topic :: View next topic |
Author |
Message |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Tue May 13, 2008 8:05 am Post subject: COM Interface |
|
|
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 |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Tue May 13, 2008 12:00 pm Post subject: |
|
|
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 |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Thu May 15, 2008 7:10 am Post subject: |
|
|
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 |
|
|
|