comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » calling function in DLL compiled with C++
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
calling function in DLL compiled with C++ [message #28680] Mon, 07 January 2002 05:11 Go to next message
Dominik[1] is currently offline  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 #28770 is a reply to message #28680] Tue, 08 January 2002 02:46 Go to previous messageGo to next message
Gert Van de Wouwer is currently offline  Gert Van de Wouwer
Messages: 21
Registered: January 2002
Junior Member
Hi,

I struggled with this problem too. The problem is probably to be solved by
changing the build parameters of your dll.
I use IDL on window2000 and Visual Studio 6.0. I use an exports.def file to
export the dll symbols (rather than declspec-things)
see example below - hope this helps

Gert


exports.def:
--------------------
LIBRARY LocMinDll
DESCRIPTION 'ILD dll LocMin (c)GVDW'

EXPORTS
GetVersion
LocMinDll

------------------------

the code goes in a cpp file
--------------
IDL_LONG IDL_STDCALL LocMinDll( int argc, void* argv[])
{
<your super code here>
}





"Dominik Paul" <dpaul@ukl.uni-freiburg.de> wrote in message
news:a1c6k0$16f$1@n.ruf.uni-freiburg.de...
> 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 #28798 is a reply to message #28680] Thu, 10 January 2002 14:11 Go to previous messageGo to next message
Richard Younger is currently offline  Richard Younger
Messages: 43
Registered: November 2000
Member
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 #28857 is a reply to message #28798] Mon, 14 January 2002 00:01 Go to previous messageGo to next message
Dominik[1] is currently offline  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 Go to previous messageGo to next message
Richard Younger is currently offline  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 Go to previous message
wbiagiot is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: idl5.5 widget_draw and color
Next Topic: All day FFT....

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:51:37 PDT 2025

Total time taken to generate the page: 0.00563 seconds