calling function in DLL compiled with C++ [message #28680] |
Mon, 07 January 2002 05:11  |
Dominik[1]
Messages: 46 Registered: April 2001
|
Member |
|
|
Hi NG,
I tried to write a DLL suing C++. But I have a big problem, calling the
function in the DLL out of IDL, when the DLL is compiled using a
C++-compiler. Using a C-compiler, everything is fine, there is no problem,
calling the function.
Does somebody know why? Is there a difference in writing a DLL for IDL in C
and in C++?
Or does somebody has an DLL-example in C++?
Thanks for your help
Dom
|
|
|
|
|
Re: calling function in DLL compiled with C++ [message #28857 is a reply to message #28798] |
Mon, 14 January 2002 00:01   |
Dominik[1]
Messages: 46 Registered: April 2001
|
Member |
|
|
Hi Richard,
I allready tried the extern C construct. But then I got some problems, using
other C++ routines in the DLL.
So, this method didnt work for me.
But Gregs suggestion was ok. The DLL is running now, thanks
Dom
"Richard Younger" <younger@ll.mit.edu> schrieb im Newsbeitrag
news:3C3E119B.8A355D5B@ll.mit.edu...
> Dominik Paul wrote:
>>
>> Hi NG,
>>
>> I tried to write a DLL suing C++. But I have a big problem,
>> calling the function in the DLL out of IDL, when the DLL is
>> compiled using a C++-compiler.
> [...]
>>
>> Dom
>
> Hi, Dom.
>
> Are you still having trouble? I've got a few examples lying around for
> VC++, but I don't know what compiler you're using. I certainly second
> Gert's suggestion about using .def files if you're in VC++.
>
> If things still aren't working, you can use the extern "C" construct to
> force your C++ compiler to use C names and calling conventions in most
> compilers.
>
> Just add something like
>
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> /* C callable prototypes here */
>
> #ifdef __cplusplus
> }
> #endif
>
>
> to your header file around IDL_load() or the externally visible
> functions. More info at
> <http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html>.
>
>
> Best,
> Rich
>
> --
> Richard Younger
|
|
|
Re: calling function in DLL compiled with C++ [message #28996 is a reply to message #28857] |
Thu, 24 January 2002 12:44   |
Richard Younger
Messages: 43 Registered: November 2000
|
Member |
|
|
Dominik Paul wrote:
>
> Hi Richard,
>
> I allready tried the extern C construct. But then I got some problems,
> using other C++ routines in the DLL.
> So, this method didnt work for me.
>
> But Gregs suggestion was ok. The DLL is running now, thanks
> Dom
Hi Dom,
Glad you got everything working.
As an addendum, I was looking something up in my Windows programming
reference, and I stumbled upon something of interest. It seems that
even in straight C, the MSVC compiler mangles names (prepending an
underscore and tacking a @[# of bytes in parameters] onto the end) if
you're using the __stdcall calling convention, even if you extern "C"
your function calls. And yes, I agree that it's annoying.
The upshot is that using __declspec(dllexport) and __stdcall, you'd have
to call something like _MyGenData@12 instead of MyGenData. So, you can
either use a .def file like you are or include something like
#pragma comment(linker, "/export:MyGenData=_MyGenData@12")
to alias MyGenData to _MyGenData@12 in the DLL exports.
It seems like more trouble and work to do it this way than a .def file,
but I guess for anyone who wants to support multiple architecture
source, they can place it behind an #ifdef WIN32 or whatever, instead of
having to deal with the extra file and compiler options.
Just thought somebody somewhere might find some passing interest.
Best,
Rich
--
Richard Younger MIT Lincoln Laboratory
Phone: (781)981-4464 244 Wood St.
Fax: (781)981-0122 Lexington, MA 02421
|
|
|
Re: calling function in DLL compiled with C++ [message #29216 is a reply to message #28996] |
Wed, 06 February 2002 09:00  |
wbiagiot
Messages: 59 Registered: January 1999
|
Member |
|
|
Richard Younger <younger@ll.mit.edu> wrote in message news:<3C50723F.E0D299F9@ll.mit.edu>...
> Dominik Paul wrote:
>>
>> Hi Richard,
>>
>> I allready tried the extern C construct. But then I got some problems,
>> using other C++ routines in the DLL.
>> So, this method didnt work for me.
>>
>> But Gregs suggestion was ok. The DLL is running now, thanks
>> Dom
>
I just stumbled across this thread and wanted to remind everyone about
the TERRIFIC free DLM that Randall Frank has on Ronn Kling's website.
Here's a snipit about the relevant section:
------------------------------------------------------------ ------
* A generic interface for calling Windows DLL functions directly
This interface allows an IDL program to directly access the
exported functions in any Windows DLL. This interface can
replace the CALL_EXTERNAL wrappers for many functions under
Windows. The interface consists of two functions. One to
define the external function to IDL and one to query the
external function table.
------------------------------------------------------------ ------
I have used this interface with 3rd party DLLs (i.e. no source code)
with great success (National Instrument's VISA library). I consider
this DLM an essential part of my IDL code (gush gush). Check it out.
-Bill
|
|
|