TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 15-12-2007, 02:27 AM   #1
Ben Voigt [C++ MVP]
Guest
 
Posts: n/a
Re: import and use class in dll


"jacky" <jfrieskeNoSPam@poczta.onet.pl> wrote in message
news:fjtfdk$gmp$1@news.onet.pl...
> 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.

  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 05:55 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional