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);