user2394753
user2394753

Reputation: 1

VBA to C++ dll function call, how to have missing argoument

I have function that I compiled with C++ as dll. I access it via vba no problem everything works great.

I want to have one of the arguments to be set to a specific value if the user does not specify its value. I dont know how to do it ,

I tried double __stdcall h2e_q_DLL (double & t, double & qi, double & d1, double & n, double & df, double & qa, double & up =1.0 )

last value "up" to be set to 1.0 but...

i get this: 1>c:\users\alex\documents\c++\h2e_project\v2\test\main.cpp(8) : error C2440: 'default argument' : cannot convert from 'double' to 'double &'

i tried searching for a solution but could not find anything, anyone has any suggestions?

Thank you!

Upvotes: 0

Views: 296

Answers (1)

Bathsheba
Bathsheba

Reputation: 234655

It's not easy I'm afraid. The optional argument has to be a VARIANT. See Microsoft docs for details on this structure.

On the C / C++ side, you check the vt field of the variant structure which will be set to the missing type if a value has not been passed. At this point you can do your defaulting logic.

On the Vba side you declare the argument as optional byref variant.

You might be able to supply a default value here ; I'm on the train so can't check.

You'll have fun extracting the data out of the variant; use the vt flag to check th type before extracting the data.

Upvotes: 2

Related Questions