Please post relevant parts of your code, it's hard to guess what's
wrong without it.
Sometimes you do, but usually you don't have to. The CLR takes care of
pinning arguments for the duration of the call if needed.
Mattias
Hi,
Here is my code.. I would be grateful if you could spot anything...
thanks
Note, some of these values (e.g. billRates is actually an array of
Double values). In my code I pass in the first element of the array
and I believe the C++ code can then use the pointer to get the rest of
the array. Is this OK?
Also, if I add a "ref" keyword to the two StringBuilder parameters the
DLL throws an exception. This seems strange seeing that the parameter
is declared as a pointer....
// C++ DLL Function
int WINAPI constructYC(long referenceDate,
char * currency,
double * billRates,
long * billEndDates,
bool * useBills,
double * billBumpAmounts,
long billSpotLag,
long billMaturityDatesLength,
long billsConvention,
double * billFuturesRates,
long * billFuturesStartDates,
long * billFuturesEndDates,
bool * useBillFutures,
double * billFuturesBumpAmounts,
long billFuturesStartDatesLength,
long billFuturesConvention,
double * specialDatesRates,
long * specialDatesStartDates,
long * specialDatesEndDates,
bool * useSpecialDates,
double * specialDatesBumpAmounts,
long specialStartDatesLength,
long specialDatesConvention,
double * bondCoupons,
double * swapRatesOrBondYields,
double * swapTenorsOrMaturities,
long * bondMaturityDates,
long * swapOrBondFrequencies,
bool * useSwapsBonds,
double * swapBondBumpAmounts,
long swapBondSpotLag,
long swapTenorsOrBondMaturityDatesLength,
long swapsOrBondsConvention,
bool enforceLinInterp,
long buildMethod,
bool billsOverrideFRAsAtStart,
bool billsOverrideFRAsAfterStart,
char * ycName,
long *holidayDates)
// C# P/Invoke method
[System.Runtime.InteropServices.DllImport(@"TheDLL.dll", EntryPoint =
"constructYCDll", CharSet = CharSet.Ansi)]
private static extern Int32 constructYCDll(
Int32 referenceDate,
StringBuilder currency,
ref Double billRates,
ref Int32 billEndDates,
ref Boolean useBills,
ref Double BillBumps,
Int32 billSpotLag,
Int32 billMaturityDatesLength,
Int32 billsConvention,
ref Double billFuturesRates,
ref Int32 billFuturesStartDates,
ref Int32 billFuturesEndDates,
ref Boolean useBillFutures,
ref Double BillFuturesBumps,
Int32 billFuturesStartDatesLength,
Int32 billFuturesConvention,
ref Double specialDatesRates,
ref Int32 specialDatesStartDates,
ref Int32 specialDatesEndDates,
ref Boolean useSpecialDates,
ref Double SpecialDatesBumps,
Int32 specialStartDatesLength,
Int32 specialDatesConvention,
ref Double bondCoupons,
ref Double swapRates,
ref Double swapTenors,
ref Int32 bondMaturityDates,
ref Int32 swapFrequencies,
ref Boolean useSwaps,
ref Double SwapBumps,
Int32 swapSpotLag,
Int32 swapTenorsLength,
Int32 swapsOrBondsConvention,
Boolean enforceLinInterp,
Int32 buildMethod,
Boolean billsOverrideFRAsAtStart,
Boolean billsOverrideFRAsAfterStart,
StringBuilder ycName,
ref Int32 holidayDates
);
// C# code to call the array
i = constructYCDll(refdate,
ccyCstring,
ref billRates[0],
ref billEndDates[0],
ref useBills[0],
ref billBumps[0],
billSpotLag,
billMaturityDatesLength,
shortConvention,
ref
billFuturesRates[0],
ref
billFuturesStartDates[0],
ref
billFuturesEndDates[0],
ref
useBillFutures[0],
ref
billFuturesBumps[0],
billFuturesStartDatesLength,
shortSpotLag,
ref
specialDatesRates[0],
ref
specialDatesStartDates[0],
ref
specialDatesEndDates[0],
ref
useSpecialDates[0],
ref
specialDatesBumps[0],
specialStartDatesLength,
shortSpotLag,
ref bondCoupons[0],
ref swapRates[0],
ref swapTenors[0],
ref
bondMaturityDates[0],
ref
swapFrequencies[0],
ref useSwaps[0],
ref swapBumps[0],
swapSpotLag,
swapTenorsLength,
longConvention,
enforceLinInterp,
buildMethod,
billsOverrideFRAsAtStart,
billsOverrideFRAsAfterStart,
ycName,
ref holidays[0]);