Brief over my project: with Visual Studio 2019 I built a project with one file .cpp and another .def to EXPORT my functions.
Everything went right when I have to pass from VBA simple double arguments, but when I should pass a Range of Cells, I started to face seriuos annoing problem which block my project.
Actually, I read too many forums and also section of Dalton's books to handle my issues, but anything it's really clear to me.
I found something which talks about COM and API C, other about "ExportImport.cpp", SAFEARRAY and VARIANT type (the latter: I could figure out how to pass arguments from VBA to C++ dll, but still don't understand how to achive and use single element and specially return them).
If it's not too annoing for some of you, I would like a specific description of what to do in this case.
Thank you
Here my project which is called square and has two functions square and my _array:
.cpp file
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <cmath>
- #include <OAIdl.h>
- double __stdcall square(double& x)
- {
- return x * 2;
- }
- VARIANT __stdcall my_array(VARIANT *p)
- {
- //my statements and operation on the array (Range received from VBA)
- }
Expand|Select|Wrap|Line Numbers
- LIBRARY "square"
- EXPORTS
- square @1
- my_array @2
SPECIALLY, I WOULD UNDERSTAND HOW TO PASS A RANGE FROM VBA TO THE FUNCTION "my_array" AND HOW TO MANGE EVERY ELEMENT OF THE RANGE I PASSED