Hi,
I've build a Class Library in C# and would like to port it to C++. Easy...
But when I've try to buil a dll, the problems arose...
In C++, I started a Win32 empty project. I choosed Dynamic Library (DLL) and code my classes from C# to C++.
In C#, to use the resulting DLL in my projects, I click "add ressource" and that's it, I can use the dll classes as if they were in my projet.
But in C++, I think I must use "LoadLibrary" but then ... I can just export a single function!!! Not my whole class. To use as objects
I want it unmanaged for my game engin (I'll add plugin capabilities)
Is there something i'm missing? How to do a Dll, unmanaged, that can expose classes from a namespace?
thx
Comments
:
: I've build a Class Library in C# and would like to port it to C++.
: Easy...
:
: But when I've try to buil a dll, the problems arose...
:
: In C++, I started a Win32 empty project. I choosed Dynamic Library
: (DLL) and code my classes from C# to C++.
:
: In C#, to use the resulting DLL in my projects, I click "add
: ressource" and that's it, I can use the dll classes as if they were
: in my projet.
:
: But in C++, I think I must use "LoadLibrary" but then ... I can just
: export a single function!!! Not my whole class. To use as objects
:
: I want it unmanaged for my game engin (I'll add plugin capabilities)
:
: Is there something i'm missing? How to do a Dll, unmanaged, that can
: expose classes from a namespace?
:
: thx
Export a class in the header file like like this , then use the same header file in the application program except use __dllimport instead of __dllexport. Most programmers use a macro for this
[code]
#if defined _DLL
#define MYAPI __dllexport
#else
#define MYAPI _dllimport
#endif
MYAPI class MyClass
{
// blabla
};
[/code]
=============================================
never lie -- the government doesn't like the competition. (Author unknown)
I don't know if there is a way to do a dll without forcing the user to find the header file? Just a dll? when we load the library, why do we still have to show our class declaration? It's compiled in the dll?
:
: I don't know if there is a way to do a dll without forcing the user
: to find the header file? Just a dll? when we load the library, why
: do we still have to show our class declaration? It's compiled in the
: dll?
:
:
how else is the compiler supposed to know what the class looks like? yes the class implementation may be in the dll but the application program needs to know the class just as in any other c++ program.
=============================================
never lie -- the government doesn't like the competition. (Author unknown)
: :
: : I don't know if there is a way to do a dll without forcing the user
: : to find the header file? Just a dll? when we load the library, why
: : do we still have to show our class declaration? It's compiled in the
: : dll?
: :
: :
:
: how else is the compiler supposed to know what the class looks like?
: yes the class implementation may be in the dll but the application
: program needs to know the class just as in any other c++ program.
: =============================================
: never lie -- the government doesn't like the competition. (Author
: unknown)
Ok, I understand. Perhaps, I've programed too much in c# where there is no need of .h files to tell the compiler. But again, if I buil a dll in C# and use it in C++... I won't have any .h; How will the compiler know what the class looks like? .NET take care of it and it must be managed?
thank you very much
: Ok, I understand. Perhaps, I've programed too much in c# where there
: is no need of .h files to tell the compiler. But again, if I buil a
: dll in C# and use it in C++... I won't have any .h; How will the
: compiler know what the class looks like? .NET take care of it and it
: must be managed?
:
: thank you very much
:
The compiler does not generate the .h file -- you do. So if you create a dll with C# I doubt it will contain a c++ class that's useable in a c++ program but I could be wrong because I know very little about C#.
=============================================
never lie -- the government doesn't like the competition. (Author unknown)