Create c++ library for use in C

T

TBass

Hi,

I've dabbled in C++, but use ANSI C for most of my work. We have a
product written in ANSI C that operates on Windows, and we have a
request from a customer to add system-wide drag and drop.

Unfortunately, it seems that OLE doesn't allow me to use C, and I have
to use C++. My goal, then, is to write a C++ library to handle the OLE
functions, and be able to call it from the C program.

I wrote a product in C++ that used a C library, and accessed the
functions like so:

extern "C" {
#include "c_inc1.h"
#include "c_inc2.h"
}


That worked fine, but I've never written a "wrapper" for a C++ library
before. Is it as simple as adding extern "C" before the declaration.
What's involved?

Thanks!
Tom
 
P

Phlip

TBass said:
Hi,

I've dabbled in C++, but use ANSI C for most of my work. We have a
product written in ANSI C that operates on Windows, and we have a
request from a customer to add system-wide drag and drop.

Unfortunately, it seems that OLE doesn't allow me to use C

MIDL outputs C wrappers for OLE things, and raw OS-level OLE is all
implemented in C.

However, you ought to recompile your code as C++, then use raw ATL, via
#import. You have the odious choice between learning the horrors required
to drive OLE in C, or writing a C++ DLL that C can call, or upgrading your
C to C-style C++.

I would prefer the last one, if I knew the C code was clean enough to
survive as C++.

Try a newsgroup with OLE or ActiveX in its name for your next question. (And
stay away from MFC OLE!)
 
T

TBass

The C code should be clean enough. I can't see any reason why I
couldn't re-compile as C++. I hesitate because, when I designed the
product, I required C instead of C++ because update and debug time is a
big issue for us, and I have always found C to be more "obvious" when
looking at the code. Also, the performance always seems to be better.
Perhaps I am holding on to a decrepit language?
 
T

TBass

Futher thought on this has led to the decision to rule out compiling in
C++. We need to be able to port this to other systems, and while
FreeBSD is the main target of this, where I assume C++ would be
hunky-dory, we also will be using much of this on micro-controlers
where C++ just isn't supported.

Since OLE is Windows specific, I'm leaning towards the DLL option.
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top