Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

How to import function from C++ dll and use them in c# code ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MichalSody - 17 Jul 2007 13:14 GMT
How cann I import & use these function from an old C++ dll ?

Only this, I've got are these two signatures of function I wannt use in
my C# app.

DllExport int DLLAPI drawImage( char *chemBuffer, char *queryBuffer,
char *chemFormat,
int showMapps, int showRkz,
int showSter, int showNumb,
int showInvRet, int queryDisplay,
int showResidue,
int canvasWidth,int canvasHeight,
HANDLE &imageHandle, int &imageBufferSize,
char *imageFormat) ;

DllExport int DLLAPI drawImageFile( char *chemBuffer, char *queryBuffer,
char *chemFormat,
int showMapps, int showRkz,
int showSter, int showNumb,
int showInvRet, int queryDisplay,
int showResidue,
int canvasWidth,int canvasHeight,
char *fileName,
char *imageFormat);
Ignacio Machin ( .NET/ C# MVP ) - 17 Jul 2007 15:23 GMT
Hi,

You have to use a feature named P/invoke, you can find a lot of examples in
pinvoke.net

> How cann I import & use these function from an old C++ dll ?
>
[quoted text clipped - 20 lines]
> char *fileName,
> char *imageFormat);
Nicholas Paldino [.NET/C# MVP] - 17 Jul 2007 15:39 GMT
MichalSody,

   You won't be able to use the first function, as you can not access
referenced parameters (&) in .NET through the P/Invoke layer.  You have to
create another version of the function (or a wrapper in unmanaged code if
you cant change the original) which uses pointers.

   Assuming you have made the changes to the first function, your
declarations would be

[DllImport("<dllname>")]
static extern int drawImage(
   [MarshalAs(UnmanagedType.LPStr)]
   string chemBuffer,
   [MarshalAs(UnmanagedType.LPStr)]
   string queryBuffer,
   [MarshalAs(UnmanagedType.LPStr)]
   string chemFormat,
   int showMapps,
   int showRkz,
   int showSter,
   int showNumb,
   int showInvRet,
   int queryDisplay
   int showResidue,
   int canvasWidth,
   int canvasHeight,
   IntPtr imageHandle,
   ref int imageBufferSize,
   [MarshalAs(UnmanagedType.LPStr)]
   string imageFormat);

[DllImport("<dllname>")]
static extern int drawImageFile(
   [MarshalAs(UnmanagedType.LPStr)]
   string chemBuffer,
   [MarshalAs(UnmanagedType.LPStr)]
   string queryBuffer,
   [MarshalAs(UnmanagedType.LPStr)]
   string chemFormat,
   int showMapps,
   int showRkz,
   int showSter,
   int showNumb,
   int showInvRet,
   int queryDisplay
   int showResidue,
   int canvasWidth,
   int canvasHeight,
   [MarshalAs(UnmanagedType.LPStr)]
   string fileName,
   [MarshalAs(UnmanagedType.LPStr)]
   string imageFormat);

   These declarations assume that you are not modifying the contents of the
string parameters at all.  If you are, then you need to change the
declarations to a StringBuilder instance and make sure to initialize it to
have enough capacity to be written to by the unmanaged function.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> DllExport int DLLAPI drawImage( char *chemBuffer, char *queryBuffer, char
> *chemFormat,
[quoted text clipped - 15 lines]
> char *fileName,
> char *imageFormat);

> How cann I import & use these function from an old C++ dll ?
>
[quoted text clipped - 20 lines]
> char *fileName,
> char *imageFormat);
R. K. Wijayaratne - 18 Jul 2007 06:38 GMT
Hi,

This article today may help: "Call Unmanaged DLLs from C#, Killing
Processes Cleanly":

http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/

RKW.

> How cann I import & use these function from an old C++ dll ?
>
[quoted text clipped - 20 lines]
> char *fileName,
> char *imageFormat);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.