Including a dll file

J

Jack

Hi guys,
So I have created a DLL file called myLib.dll. This dll is nothing but
a simple class with a constructor that upon constructor
initialization, it writes a message to the console. The class is
wrapped in a namespace called myLibNameSpace.

Using VS2008, I created a new project and added myLib.dll as a
reference to the project. What I want to do is to access my DLL and
initialize the class. Here is what I have

#include "stdafx.h"
#using <myLib.dll>

using namespace System;
using namespace myLibNameSpace;

int main(array< System::String ^ > ^args)
{

myLibClass ^myClass = gcnew myLibClass(10);

Console::Write("Press any key to continue...");
Console::ReadKey();

return 0;
}

When I compile this new project, I get tons of error messages saying
everything from: myLibNameSpace does not exists to myLibClass is an
undeclared identifier. (I have copied the DLL to the local directory
where the source file/debug file for my current project is located.)

Any ideas?

Thanks
 
C

Carl Daniel [VC++ MVP]

Jack said:
Hi guys,
So I have created a DLL file called myLib.dll. This dll is nothing but
a simple class with a constructor that upon constructor
initialization, it writes a message to the console. The class is
wrapped in a namespace called myLibNameSpace.

Using VS2008, I created a new project and added myLib.dll as a
reference to the project. What I want to do is to access my DLL and
initialize the class. Here is what I have

#include "stdafx.h"
#using <myLib.dll>

using namespace System;
using namespace myLibNameSpace;

int main(array< System::String ^ > ^args)
{

myLibClass ^myClass = gcnew myLibClass(10);

Console::Write("Press any key to continue...");
Console::ReadKey();

return 0;
}

When I compile this new project, I get tons of error messages saying
everything from: myLibNameSpace does not exists to myLibClass is an
undeclared identifier. (I have copied the DLL to the local directory
where the source file/debug file for my current project is located.)

Any ideas?

Is your DLL managed (compiled with /clr)? If it's not, #using is unusable.
Is your class public? If not, it's not visible outside the DLL.

-cd
 
J

Jack

Is your DLL managed (compiled with /clr)? If it's not, #using is unusable.
Is your class public? If not, it's not visible outside the DLL.

-cd

The DLL is managed and it was compiled with /clr. It also is public.
Here is the code from the DLL.


namespace myLibNameSpace{
template <class T>
public ref class myLibClass {
public:
myLibClass ();
..
..

The DLL compiles fine. I just can't use it. :)

Thanks
 
B

Ben Voigt [C++ MVP]

Jack said:
The DLL is managed and it was compiled with /clr. It also is public.
Here is the code from the DLL.


namespace myLibNameSpace{
template <class T>
public ref class myLibClass {

There is no class named myLibClass.... there is only myLibClass<T> for some
values of T instantiated inside the C++/CLI assembly (and using those
instances from C# would be a royal pain due to the weird name). Unused
templates will be stripped by the C++/CLI compiler.
 

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

Top