Calling MC++ methods from VB.NET

G

Guest

I've written a dll in managed C++ and created a reference to the FincadFunction
class from a VB.NET application. I'm calling the methods in my VB.NET app b
creating a reference to the dll and then an object variable for the FincadFunctions class

I'm unable to get the value for return_days or return_RtnStat_MC after th
function call. Is there a way to specify in MC++ that the argument shoul
be passed by reference? (ByRef? out? MarshalAs?

Any ideas on how to return the values to VB.NET thru the last argument
Below is the code from my MC++ dll

#using <mscorlib.dll
#include "fcvbdotnet.h
#include "vbdotnetut.h
#include "mt.h

public __gc class FincadFunction

public
int aaTest() { return(NORMAL); }

int aaAccrual_days (double d_e, double d_t, int acc, double return_days

int status = 0
LPXLOPER resultptr = NULL

// convert objects and optional values, if an

// call dl
resultptr = aaAcc_Days_dll(d_e, d_t, acc)

// extract the returning result
status = ExtractValue(resultptr, &return_days)
if (status != NORMAL)

aaGlobalFreeAllA()
GlobalFreeAllMem()
return(ABEND)


// free resources used by input object
aaGlobalFreeAllA()
GlobalFreeAllMem()

// return to caller as successfu
return(NORMAL)


int aaAver_strk_basket_fs_MC ( double ast_info __gc[,], double corr_matrix __gc[,],
double d_v, double d_exp, double d_aver, double rate_ann,
double sam_seq __gc[,], int option_type, double num_rnd,
int table_type, double return_RtnStat_MC __gc[,]

int status = 0
LPXLOPER resultptr = NULL
LPXLOPER ast_info_ptr = NULL
LPXLOPER corr_matrix_ptr = NULL
LPXLOPER sam_seq_ptr = NULL

// convert objects and optional values, if an
status = ConvertObjectDouble(ast_info, &ast_info_ptr)
if (status != NORMAL)

aaGlobalFreeAllA()
GlobalFreeAllMem()
return(ABEND)


status = ConvertObjectDouble(corr_matrix, &corr_matrix_ptr)
if (status != NORMAL)

aaGlobalFreeAllA()
GlobalFreeAllMem()
return(ABEND)


status = ConvertObjectDouble(sam_seq, &sam_seq_ptr)
if (status != NORMAL)

aaGlobalFreeAllA()
GlobalFreeAllMem()
return(ABEND)


// call dl
resultptr = aver_strk_basket_fs_MC_dll(ast_info_ptr, corr_matrix_ptr, d_v, d_exp, d_aver, rate_ann, sam_seq_ptr, option_type,
num_rnd, table_type)

// extract the returning result
status = ExtractObject(resultptr, return_RtnStat_MC)
if (status != NORMAL)

aaGlobalFreeAllA()
GlobalFreeAllMem()
return(ABEND)


// free resources used by input object
aaGlobalFreeAllA()
GlobalFreeAllMem()

// return to caller as successfu
return(NORMAL)

}
 
J

Jesse McGrew

Rob said:
I've written a dll in managed C++ and created a reference to the FincadFunctions
class from a VB.NET application. I'm calling the methods in my VB.NET app by
creating a reference to the dll and then an object variable for the FincadFunctions class.

I'm unable to get the value for return_days or return_RtnStat_MC after the
function call. Is there a way to specify in MC++ that the argument should
be passed by reference? (ByRef? out? MarshalAs?)

Declare it as a reference (double& return_days) and give it the
[System::Runtime::InteropServices::Out] attribute.

Jesse
 
G

Guest

Thanks for the tip Jesse

Where do I specify an attribute like that for a method in a MC++ class method (function)

With the C interface I could do this in the [DLLImport] function prototype inside VB.NET bu
with a traditional direct class interface I'm not sure where to put the attribute statement? (C++ side or VB.NET side?

Will this work for the array argument as well
 
J

Jesse McGrew

Rob said:
Thanks for the tip Jesse.

Where do I specify an attribute like that for a method in a MC++ class method (function)?

With the C interface I could do this in the [DLLImport] function prototype inside VB.NET but
with a traditional direct class interface I'm not sure where to put the attribute statement? (C++ side or VB.NET side?)

Put it in your MC++ class definition:

void Method([System::Runtime::InteropServices::Out] double& parameter);

The compiler will store it in your assembly's metadata, and VB.NET will
find it when it imports the assembly.
Will this work for the array argument as well?

Sure, I don't see why not.

Jesse
 

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