import and use class in dll

J

jacky

Hi
I've got a dll written in c++ with header like this:

class __declspec (dllexport) CPrnDrv
{
private:

static int licz_wywolan;
HANDLE hPort;

BOOL PrintPortOpen (LPTSTR lpszPortName);
BOOL PrintPortClose ();
bool WritePort(prnstr str);
public:


DWORD dwError;


CPrnDrv();
~CPrnDrv();

bool InitPrinter(LPTSTR lpszPortName, int PageLength);
void ExitPrinter();

bool WritePort(BYTE *Byte, DWORD Size, LPDWORD wNumBytesWritten);
bool ReadPort (BYTE *Byte, DWORD Size, LPDWORD dwNumBytesRead);
};

How can I import this dll (VS2005 C#) and use functions InitPrinter and
WritePort?
 
B

Ben Voigt [C++ MVP]

jacky said:
Hi
I've got a dll written in c++ with header like this:

class __declspec (dllexport) CPrnDrv
{
private:

static int licz_wywolan;
HANDLE hPort;

BOOL PrintPortOpen (LPTSTR lpszPortName);
BOOL PrintPortClose ();
bool WritePort(prnstr str); public:


DWORD dwError;


CPrnDrv();
~CPrnDrv();

bool InitPrinter(LPTSTR lpszPortName, int PageLength);
void ExitPrinter();

bool WritePort(BYTE *Byte, DWORD Size, LPDWORD wNumBytesWritten);
bool ReadPort (BYTE *Byte, DWORD Size, LPDWORD dwNumBytesRead);
};

How can I import this dll (VS2005 C#) and use functions InitPrinter and
WritePort?

You can't. C++ classes are not compatible with any other language.

Your only hope is to write a C++/CLI wrapper function which exposes .NET
types which C# can use. However, to do so you must use the exact same
compiler version as the original DLL, as dllexport-ed classes are not at all
portable.

In summary -- it's not likely to work unless you can get the original source
code and fix the mistake of using dllexport on a class.
 

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