Re: Exporting classes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Good luck.

Paul T.

"Cri++" <Cri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9B87A6A0-46E6-408F-8081-299D93177C32@xxxxxxxxxxxxxxxx
I have read all the messages but maybe I had a misunderstanding.

Sorry and thanks anyway

--
Cri++


"Paul G. Tobey [eMVP]" wrote:

Have you *read* any of the messages (Chris previously told you 100%
clearly
that you can't export a class from C++ and use it from managed code; why
make us repeat ourselves)? I sent a whole example in my last message
showing the basic format. We know nothing about what this DLL is
supposed
to do? You want us to design an interface for it? You export "some
functions" that are appropriate from the DLL, as I showed you before, and
then you call them from managed code. You can't export a class and I
would
recommend that you not export data items. That's about as far as we can
help...

Paul T.

"Cri++" <Cri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:70A05359-F509-4CB3-900E-A5940E41CE31@xxxxxxxxxxxxxxxx
OK,
I understand,
but, how can I create a flat C API?

Thanks

--
Cri++


"Chris Tacke, MVP" wrote:

You can't. The marshaler cannot pass classes or class references -
you
have
to use a flat C API.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"Cri++" <Cri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DF13CFD9-220F-4533-A692-F8BA4E36F343@xxxxxxxxxxxxxxxx
Hi,
maybe I explained bad.
I'm already able to export a functions in C++ and use it in VB.NET.
My question is: how to export a whole class?

Thanks

--
Cri++


"Paul G. Tobey [eMVP]" wrote:

Yes, you can do that. You want to declare the functions (no
classes!),
as
extern "C", when the client of the DLL sees their declarations, so
you
need
to make sure to form the declarations correctly. Something like
this:

headerfile.h:

#ifdef __cplusplus
extern "C"
{
#endif

#ifdef BUILDING_THE_DLL_ITSELF
#define EXPORTMODIFICATION declspec(dllexport)
#else
#define EXPORTMODIFICATION declspec(dllimport)
#endif

EXPORTMODIFICATION int Function1(...);

EXPORTMODIFICATION int Function2(...);

#ifdef __cplusplus
}
#endif

This will pretty-much assure that you don't do anything 'bad', like
try
to
have two versions of the same function name with different
parameters
(overloading the name), which is a C++-only capability. The
EXPORTMODIFICATION symbol helps to assure that, when you're
actually
building the DLL, as opposed to some other module that just uses
it,
that
you're getting the right modifiers on the function to make it
exported
from
the DLL. When a client of the EXE is being built, you get a
suitable
'external' reference to the function which should be resolved when
you
link
the EXE by linking with the import library for the DLL. It's
easier
to
see,
when you do it, than it is to explain clearly in a newsgroup post
(obviously!)...

Paul T.

"Cri++" <Cri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1FFBDE2A-8A08-4E0D-8A0D-09DB6DEBE92A@xxxxxxxxxxxxxxxx
OK, thanks for answer.
If I want create an API with a stright C interface,
can I use embeddedVC++?
And if not, whitch compiler you advice to use?

Thanks very much

--
Cri++


"Chris Tacke, eMVP" wrote:

You can't. There is no interop way for managed code to directly
P/Invoke
a
class in a native library. Your only option is to create a
native
API
with
a straight C interface that in turn creates and calls the class.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


"Cri++" <Cri@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:69DA9F01-C457-425B-AFB5-8BEB824882EF@xxxxxxxxxxxxxxxx
Hi to all,
I made a class called "ClassAnalogInput" in a dll written in
embedded
C++.
Now I need to use the class in other application,
in particular the application is written in VB.NET.

Sombody know how can I use/import the class
("ClassAnalogInput") in the VB.NET application?

Thanks

--
Cri++












.



Relevant Pages

  • Re: Exporting classes
    ... how can I create a flat C API? ... Chris Tacke, Embedded MVP ... extern "C", when the client of the DLL sees their declarations, so you ... #define EXPORTMODIFICATION declspec ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Exporting classes
    ... We know nothing about what this DLL is supposed ... how can I create a flat C API? ... Chris Tacke, Embedded MVP ... #define EXPORTMODIFICATION declspec ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Exporting classes
    ... We know nothing about what this DLL is supposed ... how can I create a flat C API? ... Chris Tacke, Embedded MVP ... #define EXPORTMODIFICATION declspec ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Random file access -cont
    ... That helps, thanks Paul! ... > You can call anything in any DLL anywhere on the device, ... > Download the OpenNETCF SDF and look through the source code. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Exporting classes
    ... The marshaler cannot pass classes or class references - you have to use a flat C API. ... extern "C", when the client of the DLL sees their declarations, so you need ... #define EXPORTMODIFICATION declspec ... >> Chris Tacke, Embedded MVP ...
    (microsoft.public.windowsce.embedded.vc)