Hi, I'm trying to call a c++ dll from vb.net. My problem is in trying to figure out how to rewrite the parameters from c++ to vb. The original function in the dll is:
void WINAPI FindCBondPrice(int& issueDays, int& settleDays, int& exerciseDays, int& convProt,
int& couponchoice, int& couponfrequency,
int& exercisechoice, int& methodchoice, int& yieldchoice,
int& spreadchoice, int& volatilitychoice,
int& dividendchoice, int& divfrequency, int& schedulechoice,
int& divprotchoice, double& dptrigger, double& underlying, double *volatility,
double& divYield, int& dLen, int *dDays, double *dPrice, double& redemption,
double *riskFree, double& couponrate, double& conversionRatio,
double* convertibleSpread, double& equitySpread, double& stockRecovery,
double& bondRecovery, int& cLen, int *cDays, double *cPrice, double *cTrig,
int& pLen, int *pDays, double *pPrice, double *Results, char *errors,
double *time, bool printresults)
I tried rewriting this as:
Private Declare Sub FindCBondPrice _
Lib "ConvEngine.dll" _
(ByVal issueDays As Integer, ByVal settleDays As Integer, ByVal exerciseDays As Integer, _
ByVal convProt As Integer, ByVal couponchoice As Integer, ByVal couponfrequency As Integer, _
ByVal exercisechoice As Integer, ByVal methodchoice As Integer, ByVal yieldchoice As Integer, _
ByVal spreadchoice As Integer, ByVal volatilitychoice As Integer, ByVal dividendchoice As Integer, _
ByVal divfrequency As Integer, ByVal schedulechoice As Integer, ByVal divprotchoice As Integer, _
ByVal dptrigger As Double, ByVal underlying As Double, ByRef volatility() As Double, _
ByVal divYield As Double, ByVal dLen As Integer, ByRef dDays() As Integer, ByRef dPrice() As Double, _
ByVal redemption As Double, ByRef riskFree() As Double, ByVal couponrate As Double, _
ByVal conversionRatio As Double, ByRef convertibleSpread() As Double, ByVal equitySpread As Double, _
ByVal stockRecovery As Double, ByVal bondRecovery As Double, ByVal cLen As Integer, _
ByRef cDays() As Integer, ByRef cPrice() As Double, ByRef cTrig() As Double, ByVal pLen As Integer, _
ByRef pDays() As Integer, ByRef pPrice() As Double, ByRef myresults() As Double, ByVal errors As String, _
ByVal time As Double, ByRef printresults As Boolean)
The error message I get is:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Convert_Database.ModelForm.FindCBondPrice(Int32 issueDays, Int32 settleDays, Int32 exerciseDays, Int32 convProt, Int32 couponchoice, Int32 couponfrequency, Int32 exercisechoice, Int32 methodchoice, Int32 yieldchoice, Int32 spreadchoice, Int32 volatilitychoice, Int32 dividendchoice, Int32 divfrequency, Int32 schedulechoice, Int32 divprotchoice, Double dptrigger, Double underlying, Double[]& volatility, Double divYield, Int32 dLen, Int32[]& dDays, Double[]& dPrice, Double redemption, Double[]& riskFree, Double couponrate, Double conversionRatio, Double[]& convertibleSpread, Double equitySpread, Double stockRecovery, Double bondRecovery, Int32 cLen, Int32[]& cDays, Double[]& cPrice, Double[]& cTrig, Int32 pLen, Int32[]& pDays, Double[]& pPrice, Double[]& myresults, String& errors, Double time, Boolean& printresults)
at Convert_Database.ModelForm.RunModel_Click(Object sender, EventArgs e) in C:\Development\Convert Database\Convert Database\ModelForm.vb:line 982
What am I doing wrong? Thanks in advance.
John