Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
End Users
Pocket PCActiveSyncMultimediaEBooksWirelessSmartPhones
Developers
Windows MobileSmartPhonesWinCE ProgrammingVB for WinCEVC++ for WinCEPlatform BuilderTest Tools
PocketPC DirectoryFree SoftwareWeb Resources
Related Topics
PalmMobile PhonesMore Topics ...

Pocket PC Forum / Developers / VC++ for WinCE / October 2008

Tip: Looking for answers? Try searching our database.

Exporting classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cri++ - 02 Oct 2008 10:26 GMT
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

Signature

Cri++

Chris Tacke, eMVP - 02 Oct 2008 14:40 GMT
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.

Signature

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

> Hi to all,
> I made a class called "ClassAnalogInput" in a dll written in embedded C++.
[quoted text clipped - 5 lines]
>
> Thanks
Cri++ - 03 Oct 2008 10:34 GMT
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

Signature

Cri++

> 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
[quoted text clipped - 9 lines]
> >
> > Thanks
Paul G. Tobey [eMVP] - 06 Oct 2008 18:04 GMT
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.

> OK, thanks for answer.
> If I want create an API with a stright C interface,
[quoted text clipped - 19 lines]
>> >
>> > Thanks
Cri++ - 07 Oct 2008 07:56 GMT
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

Signature

Cri++

> 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
[quoted text clipped - 58 lines]
> >> >
> >> > Thanks
Chris Tacke, MVP - 07 Oct 2008 12:41 GMT
You can't.  The marshaler cannot pass classes or class references - you have
to use a flat C API.

Signature

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

> Hi,
> maybe I explained bad.
[quoted text clipped - 73 lines]
>> >> >
>> >> > Thanks
Cri++ - 07 Oct 2008 12:55 GMT
OK,
I understand,
but, how can I create a flat C API?

Thanks

Signature

Cri++

> You can't.  The marshaler cannot pass classes or class references - you have
> to use a flat C API.
[quoted text clipped - 76 lines]
> >> >> >
> >> >> > Thanks
Paul G. Tobey [eMVP] - 07 Oct 2008 16:06 GMT
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.

> OK,
> I understand,
[quoted text clipped - 88 lines]
>> >> >> >
>> >> >> > Thanks
Cri++ - 08 Oct 2008 13:15 GMT
I have read all the messages but maybe I had a misunderstanding.

Sorry and thanks anyway

Signature

Cri++

> 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
[quoted text clipped - 100 lines]
> >> >> >> >
> >> >> >> > Thanks
Paul G. Tobey [eMVP] - 08 Oct 2008 16:03 GMT
Good luck.

Paul T.

>I have read all the messages but maybe I had a misunderstanding.
>
[quoted text clipped - 118 lines]
>> >> >> >> >
>> >> >> >> > Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.