C (P/호출)에 C 번호에서 다른 구조의 배열 구조를 통과 :I는 다음의 구조를 한
[StructLayout(LayoutKind.Sequential)]
public struct TCurve
{
public int fNumItems; /* Number of TRatePts in fArray */
public IntPtr fArray; /* Dates & rates */ // pointer to an array of TRatePt[]
public long fBaseDate; /* Discount date */
public double fBasis; //ZERO_CURVE_BASIS in capvoll.c which is #defined as ANNUAL_BASIS 1 /* Number compounding periods/year */
public long fDayCountConv; //ZERO_CURVE_DAY_COUNT_CONV in capvoll.c which is #defined as GTO_ACT_365F; = 2L /* How the year fraction is computed */
public IntPtr fClassHandle; /* C++ class handle implementation */
};
[StructLayout(LayoutKind.Sequential)]
public struct TRatePt
{
public long fDate;
public double fRate;
};
TRatePt 같이 정의는 다음과
[DllImport("alib.dll", EntryPoint = "GtoCapFloorAvgVol")]
public static extern int CapFloorAvgVol(
long capStartDate, /* (I) */
long capExpiryDate, /* (I) */
double[] strikeRates, /* (I) */
int numStrikeRates, /* (I) */
double[] principles, /* (I) */
int numPrinciples, /* (I) */
int moneymarketDen, /* (I) # days/year */
ref TDateInterval resetPeriod, /* (I) Time Between caplets */
int optionType, /* (I) Cap or Floor */
char stubPosition, /* (I) 2/16/94 GG 'F'ront or 'B'ack */
[In] IntPtr zeroCurve, /* (I) For discounting Pointer to TCurve*/
double price, /* (I) Price */
double avgVolGuess, /* (I) Average Volatility guess */
out double avgVol); /* (O) Average Volatility */
ㄴ 선언 is :
GTO_EXPORT(int) GtoCapFloorAvgVol(
TDate capStartDate, /* (I) */
TDate capExpiryDate, /* (I) */
double *strikeRates, /* (I) */
int numStrikeRates, /* (I) */
double *principles, /* (I) */
int numPrinciples, /* (I) */
int moneymarketDen, /* (I) # days/year */
TDateInterval *resetPeriod, /* (I) Time Between caplets */
int optionType, /* (I) Cap or Floor */
char stubPosition, /* (I) 2/16/94 GG 'F'ront or 'B'ack */
TCurve *zeroCurve, /* (I) For discounting */
double price, /* (I) Price */
double avgVolGuess, /* (I) Average Volatility guess */
double *avgVol) /* (O) Average Volatility */
미리 감사드립니다.
typedef struct _TCurve{
int fNumItems; /* Number of TRatePts in fArray */
TRatePt *fArray; /* Dates & rates */
TDate fBaseDate; /* Discount date */
double fBasis; /* Number compounding periods/year */
long fDayCountConv; /* How the year fraction is computed */
void *fClassHandle; /* C++ class handle implementation */ } TCurve;
과 :
좋아, 그래서 여기에 C 구조체이다 당신이 * 도움이 될 것 환영 공백을 처리하는 방법을 알고 있다면 ...
typedef struct{
TDate fDate;
double fRate;} TRatePt;
그런데
추신 : TDate는 typedef long int TDate;
입니다. 그것을 사용하십시오 :
TCurve _zeroCurve = new TCurve()
{
fBaseDate = _tempValueDate,
fNumItems = _ratePoints.Length,
fBasis = 2L,
fDayCountConv = 1
};
int _sizeOfTCurve = Marshal.SizeOf(typeof(TCurve));
IntPtr p_zeroCurve = Marshal.AllocHGlobal(_sizeOfTCurve);
Marshal.StructureToPtr(_zeroCurve, p_zeroCurve, false);
int _status;
_zeroCurve.fArray = Marshal.AllocHGlobal(_ratePoints.Length * Marshal.SizeOf(typeof(TRatePt)));
try
{
IntPtr _ratePt = _zeroCurve.fArray;
for (int _i = 0; _i < _ratePoints.Length; _i++)
{
Marshal.StructureToPtr(_ratePoints[_i], _ratePt, false);
//_ratePt = new IntPtr(_ratePt.ToInt64() + Marshal.SizeOf(typeof(TRatePt)));
IntPtr _nextRatePt = new IntPtr(_ratePt.ToInt64() + Marshal.SizeOf(typeof(TRatePt)));
_ratePt = _nextRatePt;
//_ratePt += Marshal.SizeOf(typeof(TRatePt));
}
_status = CapFloorAvgVol(_tempStartDate, _temPexpiryDate, strikeRates, strikeRates.Length, principles, principles.Length, moneymarketDen,
ref _resetPeriod, optionType, stubPosition, p_zeroCurve, price, avgVolGuess, out avgVol);
}
finally
{
Marshal.FreeHGlobal(_zeroCurve.fArray);
}
Marshal.FreeHGlobal(p_zeroCurve);
p_zeroCurve = IntPtr.Zero;
당신은 구조체에 대한 우리에게 C 선언을 줄 수 있습니까? –
또한 C에서'long'은 C#에서'int'를 의미합니다. C에서'long long'은 C#에서'long'입니다. –
위 구조체를 추가했습니다 – nche