I have a program written in VB2012 and I'm trying to do the heavy number crunching in a c++ DLL. There are lots of variables that the c++ program needs access to. What I would like to do it pass a Class object into the DLL (lets call it Class_fred) and the variables through the class.
VB code
class class_fred
public var_1 = 10
public var_2 = 20
heavyLifter (&class_fred)
end class
C++ code
void heavyLifter (object* cf) {
int a, b;
a = cf->var_1 + cf->var_2;
}
In your VB.NET project, you'll want to add a reference to your C++ DLL. This can be done from the Solution Explorer in your project. Then, in your code, you can access it by passing it to your Fred objects. This code is a general example on how it can be done, using
HeavyDotNetClassas yourFredclass andHeavyLiftingas the name of the COM assembly:In your C++ DLL (imported as
HeavyLiftinghere) you should define an Interface (HeavyLifting.IHeavyObject) that ClassFredwill implement. In this example, theIHeavyObjectinterface has two properties,Var1andVar2.You would then create an instance of your C++ object and pass it to an instance of
HeavyDotNetClass:In this example, the C++ object would have a method called
Processwith a parameter of typeIHeavyObject.