Use C++ library in C#

S

shapper

Hello,

I have a DLL and a C/C++ header as follows:

#include <stdio.h>
#include <windows.h>
#define FUNC_DLL __declspec(dllimport)
FUNC_DLL int WINAPI FA(int iSize, double *pdSignal, double dSmooth,
double dPhase, double *pdFilter);
FUNC_DLL int WINAPI FATR(double dSeries, double dSmooth, double
dPhase, double *pdOutput, int iDestroy, int *piSeriesID);

I would like to use these functions in a C# class library.
(A side note: would this be different on Net 2.0 or Net 3.0?)

How can I do this?

Thank You,
Miguel
 
A

Arne Vajhøj

shapper said:
I have a DLL and a C/C++ header as follows:

#include <stdio.h>
#include <windows.h>
#define FUNC_DLL __declspec(dllimport)
FUNC_DLL int WINAPI FA(int iSize, double *pdSignal, double dSmooth,
double dPhase, double *pdFilter);
FUNC_DLL int WINAPI FATR(double dSeries, double dSmooth, double
dPhase, double *pdOutput, int iDestroy, int *piSeriesID);

Untested:

[DllImport("foobar.dll")]
public static extern int FA(int iSize, ref double pdSignal, double
dSmooth, double dPhase, ref double pdFilter);
[DllImport("foobar.dll")]
public static extern int FATR(double dSeries, double dSmooth, double
dPhase, ref double pdOutput, int iDestroy, ref int piSeriesID);

If the pointer are to arrays instead of single values, then you will
need something slightly different.
I would like to use these functions in a C# class library.
(A side note: would this be different on Net 2.0 or Net 3.0?)

No.

Arne
 
S

shapper

If the pointer are to arrays instead of single values, then you will
need something slightly different.

Yes, they are.
1. int iSize = INTEGER
2. double *pdSignal = ARRAY OF DOUBLES
3. double dSmooth = DOUBLE
4. double dPhase = DOUBLE
5. double *pdFilter = ARRAY OF DOUBLES

2 and 5 are time series, i.e., an array with N*1 dimension.
1, 3 and 4 single values. They are the parameters.

I was reading the following:
http://msdn.microsoft.com/en-us/magazine/cc301501.aspx

But I wasn't sure if I could use that because of the arrays.

Do you know what changes do I need?

I haven't use C++ and I am not familiar with it.

Thank You,
Miguel
 
A

Arne Vajhøj

shapper said:
Yes, they are.
1. int iSize = INTEGER
2. double *pdSignal = ARRAY OF DOUBLES
3. double dSmooth = DOUBLE
4. double dPhase = DOUBLE
5. double *pdFilter = ARRAY OF DOUBLES

2 and 5 are time series, i.e., an array with N*1 dimension.
1, 3 and 4 single values. They are the parameters.

I was reading the following:
http://msdn.microsoft.com/en-us/magazine/cc301501.aspx

But I wasn't sure if I could use that because of the arrays.

Do you know what changes do I need?

I haven't use C++ and I am not familiar with it.

Then try as I showed just with:
double[]
instead of:
ref double

Arne
 

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