S
shapper
Hello,
I am trying to use a C++ library in my C# code.
The C++ library is 32 bit. But I am using Windows Vista 64 Bit.
When I tried to access the library in Matlab I got an error because of
that.
Can the C# wrapper be used in 64 bits even if the C++ library is in 32
bits?
I am using the following:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace test.Inds {
[Serializable]
public class JBA : Ind {
protected double fSmh = 14;
protected double fPhe = 0;
protected int iSrsID = 0;
protected int iHhi = -1;
[DllImport("JBA32.dll")]
unsafe public static extern int BA(int iSize, [In] double* pdSg,
double dSmh, double dPhe, [Out] double* pdFilter); [DllImport
("JRS_32.dll")]
public static extern unsafe int BART(double dSrs, double dSmh,
double dPhe, [Out] double* pdOutput, int iDestroy, int* piSrsID);
[Category("Parameters"), Description("")]
[IndParameter(0)]
public double Smh { get { return fSmh; } set { fSmh = value; Init
(); } }
[Category("Parameters"), Description("")]
[IndParameter(1)]
public double Phe { get { return fPhe; } set { fPhe = value; Init
(); } }
protected override void Init() {fName = "JBA (" + fSmh + ", " +
fPhe + ")"; fTitle = "JBA";
Clear();
fCalculate = true;
iHhi = -1;
if (iSrsID != 0) {
unsafe {
fixed (int* ID = &iSrsID) {
BART(0, 0, 0, null, 1, ID);
}
}
iSrsID = 0;
}
}
public JBA() {
Init();
}
public JBA(TimeSrs input, double smooth, double phase) : base
(input) {
fSmh = smooth;
fPhe = phase;
Init();
}
protected override void Calculate(int index) {
double dBA = double.NaN;
if (index <= iHhi)
return;
while (iHhi < index) {
++iHhi;
if (iHhi < fInput.FirstIndex)
continue;
int iErr;
unsafe {
fixed (int* piSrsID = &iSrsID) {
iErr = BART(fInput[iHhi, fOption], Smh, Phe, &dBA, 0,
piSrsID);
}
}
if (iHhi < 30)
dBA = double.NaN;
ReportJError(iErr);
Add(fInput.GetDateTime(index), dBA);
}
}
private static void ReportJError(int iErr) {
switch (iErr) {
case 0:
break;
case -1:
Console.WriteLine("-1");
break;
case 10112:
Console.WriteLine("10112");
break;
case 10114:
Console.WriteLine("10114");
break;
case 10115:
Console.WriteLine("10115");
break;
default:
Console.WriteLine("default");
break;
}
}
~JBA() { // deallocate memory in the DLL when we are done
unsafe {
fixed (int* ID = &iSrsID) {
int iErr = BART(0, 0, 0, null, 1, ID);
ReportJError(iErr);
}
}
}
}
}
Thanks,
Miguel
I am trying to use a C++ library in my C# code.
The C++ library is 32 bit. But I am using Windows Vista 64 Bit.
When I tried to access the library in Matlab I got an error because of
that.
Can the C# wrapper be used in 64 bits even if the C++ library is in 32
bits?
I am using the following:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace test.Inds {
[Serializable]
public class JBA : Ind {
protected double fSmh = 14;
protected double fPhe = 0;
protected int iSrsID = 0;
protected int iHhi = -1;
[DllImport("JBA32.dll")]
unsafe public static extern int BA(int iSize, [In] double* pdSg,
double dSmh, double dPhe, [Out] double* pdFilter); [DllImport
("JRS_32.dll")]
public static extern unsafe int BART(double dSrs, double dSmh,
double dPhe, [Out] double* pdOutput, int iDestroy, int* piSrsID);
[Category("Parameters"), Description("")]
[IndParameter(0)]
public double Smh { get { return fSmh; } set { fSmh = value; Init
(); } }
[Category("Parameters"), Description("")]
[IndParameter(1)]
public double Phe { get { return fPhe; } set { fPhe = value; Init
(); } }
protected override void Init() {fName = "JBA (" + fSmh + ", " +
fPhe + ")"; fTitle = "JBA";
Clear();
fCalculate = true;
iHhi = -1;
if (iSrsID != 0) {
unsafe {
fixed (int* ID = &iSrsID) {
BART(0, 0, 0, null, 1, ID);
}
}
iSrsID = 0;
}
}
public JBA() {
Init();
}
public JBA(TimeSrs input, double smooth, double phase) : base
(input) {
fSmh = smooth;
fPhe = phase;
Init();
}
protected override void Calculate(int index) {
double dBA = double.NaN;
if (index <= iHhi)
return;
while (iHhi < index) {
++iHhi;
if (iHhi < fInput.FirstIndex)
continue;
int iErr;
unsafe {
fixed (int* piSrsID = &iSrsID) {
iErr = BART(fInput[iHhi, fOption], Smh, Phe, &dBA, 0,
piSrsID);
}
}
if (iHhi < 30)
dBA = double.NaN;
ReportJError(iErr);
Add(fInput.GetDateTime(index), dBA);
}
}
private static void ReportJError(int iErr) {
switch (iErr) {
case 0:
break;
case -1:
Console.WriteLine("-1");
break;
case 10112:
Console.WriteLine("10112");
break;
case 10114:
Console.WriteLine("10114");
break;
case 10115:
Console.WriteLine("10115");
break;
default:
Console.WriteLine("default");
break;
}
}
~JBA() { // deallocate memory in the DLL when we are done
unsafe {
fixed (int* ID = &iSrsID) {
int iErr = BART(0, 0, 0, null, 1, ID);
ReportJError(iErr);
}
}
}
}
}
Thanks,
Miguel