import and use class in dll

  • Thread starter Thread starter jacky
  • Start date Start date
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?
 
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.
 
Back
Top