Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call C++ constructor from Visual Basic

Tags:

c++

vba

dll

com

I'm having trouble calling a C++ constructor in my Visual Basic code. The DLL has been imported correctly but this line in particular is giving me trouble:

Dim myobj As New MyObject("param1", "param2", "param3")

And the corresponding C++ constructor:

MyObject::MyObject(System::String ^ p1, System::String ^ p2, System::String ^ p3)

Any suggestions?

like image 204
Sam Youtsey Avatar asked Feb 16 '26 13:02

Sam Youtsey


2 Answers

You can't. It's simply not supported this way.

The easiest way of doing it is to just convert the constructor into a function (eg Initialize()).

like image 151
Mahmoud Al-Qudsi Avatar answered Feb 19 '26 02:02

Mahmoud Al-Qudsi


You can't - the class will be instantiated with a default constructor. If you need parameterized construction you have two options - either add an "initialize" parameterized method to the class or add a factory class with an "instantiate the first class with this parameters" method.

like image 35
sharptooth Avatar answered Feb 19 '26 01:02

sharptooth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!