- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a library of dozens of subroutines which I use from various applications: S-Plus, R, and Fortran/C code. These three can call a DLL directly. Unfortunately, R now requires a different calling convention (C and REFERENCE), whereas S-Plus and Fortran/C code use the Windows standard calling convention. Is there anyway to use the ATTRIBUTES directive to have one source program to do both? I've tried to get different entry points, with different calling specifications by using something like:
subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysub1
...
This doesn't work - only the first name 'mysub' appears in the DLL.
A complicating factor is that I have dozens of functions that I want to be exports in the DLL, and some of them are called internally from other parts of the library. When I eliminate the first ATTRIBUTES (manually or with a conditional compile), the second symbol 'mysub1' appears in the DLL, but other parts of the Fortran code now can't see mysub (they are looking for mysub@12).
I've experimented with the ALIAS attribute, but had no luck.
The only way I can see to do this is to make a second subroutine and give it the different calling specifications, but then have it call the first. For example,
subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
...
subroutine mysubA(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysubA
call mysub(a,b,c)
return
end
Then S-Plus and Fortran can call the DLL with name mysub using the standard calling sequence, whereas R can call the DLL with name mysuba and teh C calling convention. Of course, this leaves two sets of code to maintain. When there are tens of thousands of lines of code in a project and dozens of entry points, this becomes a headache.
I guess the R developers found it easier to NOT use the windows standard for calling DLLs, but it is a pain.
subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysub1
...
This doesn't work - only the first name 'mysub' appears in the DLL.
A complicating factor is that I have dozens of functions that I want to be exports in the DLL, and some of them are called internally from other parts of the library. When I eliminate the first ATTRIBUTES (manually or with a conditional compile), the second symbol 'mysub1' appears in the DLL, but other parts of the Fortran code now can't see mysub (they are looking for mysub@12).
I've experimented with the ALIAS attribute, but had no luck.
The only way I can see to do this is to make a second subroutine and give it the different calling specifications, but then have it call the first. For example,
subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
...
subroutine mysubA(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysubA
call mysub(a,b,c)
return
end
Then S-Plus and Fortran can call the DLL with name mysub using the standard calling sequence, whereas R can call the DLL with name mysuba and teh C calling convention. Of course, this leaves two sets of code to maintain. When there are tens of thousands of lines of code in a project and dozens of entry points, this becomes a headache.
I guess the R developers found it easier to NOT use the windows standard for calling DLLs, but it is a pain.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume that by "Windows calling convention" you mean STDCALL.
Jacket routines are the only reasonable solution I can think of. You can use ATTRIBUTES ALIAS to give the jacket the external name expected.
Jacket routines are the only reasonable solution I can think of. You can use ATTRIBUTES ALIAS to give the jacket the external name expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I meant STDCALL for "Windows calling convention".
I figured the "jacket" or "wrapper" routines were the only way to go. Since I have 79 of these entry points, I wrote a script to "parse" my fortran source files and automatically produce the wrapper function. A pain, but it works.
Thanks for your reply.
I figured the "jacket" or "wrapper" routines were the only way to go. Since I have 79 of these entry points, I wrote a script to "parse" my fortran source files and automatically produce the wrapper function. A pain, but it works.
Thanks for your reply.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page