Using Managed C++ DLLs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

(If this is a repost, please ignore it, I have posted this already but it never showed up

Hi

I am writing a project in Managed C++. I have a couple classes that are quite isolated from the rest of the project and wanted to separate them so that they could be developed independently of the main executable and could be "upgraded" without recompiling the executable of the project. I am new to developing DLL's, but as I understand, this may be a good position to use them. Can I just move my class code to a DLL project, and have the main executable project just use them as though they were a source file (ie "#using <Utility.dll>")? I have created a DLL project and have done this, but the project doesn't recognize the classes that are in the DLL - am I missing something, or do I have this all wrong

Thank you
Tim
 
Hi, Tim,

There are mainly two types of DLL you can create : one is COM dll, which use
IDL to expose it's function, and the other one is non-COM dll (sorry, I
don't have a good name for that).

Which type of dll are you choosing? Based on your intention, I would assume
you are creating the second type of dll. So you need export those functions
in .DEF file. Can you tell us how you created the DLL project and how you
expose those functions?

J.W.


Tim said:
(If this is a repost, please ignore it, I have posted this already but it never showed up)

Hi,

I am writing a project in Managed C++. I have a couple classes that
are quite isolated from the rest of the project and wanted to separate them
so that they could be developed independently of the main executable and
could be "upgraded" without recompiling the executable of the project. I am
new to developing DLL's, but as I understand, this may be a good position to
use them. Can I just move my class code to a DLL project, and have the main
executable project just use them as though they were a source file (ie
"#using <Utility.dll>")? I have created a DLL project and have done this,
but the project doesn't recognize the classes that are in the DLL - am I
missing something, or do I have this all wrong?
 
This may not help at all but...
In Managed C++ can you not just export the entire C++ class using standard
export calls?
(I dont know as I have little to no experience of Managed C++, but I know
what you can do in C++ for the PPC.).

I have lots of classes which I export entirely without using .def files (and
not using COM.), using the syntax pretty much as defined below.

//////////////////////////////////////////////////
// EXPORT's
//////////////////////////////////////////////////
//To export Functions
#if defined(CEREGISTRY_EXPORTS)
#define CEREGISTRY_API_(type) extern "C" __declspec(dllexport) type
#define CEREGISTRY_CLASS __declspec(dllexport)
#else
//To import Functions
#define CEREGISTRY_API_(type) extern "C" __declspec(dllimport) type
#define CEREGISTRY_CLASS __declspec(dllimport)
#endif
#endif

And then create the class using the syntax:
class CEREGISTRY_CLASS CEOysterReg
{

};

As long as you have the right defines in your projects and include the
exported dll library files in your client application, all works like a
dream. Its probably a bit antiquated now what with COM and such like, but
its easy to maintain.

Justin.
 
Back
Top