By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

C++ DLL (callable from VBA and receiving Range data)

P: 1
I am getting sick to figure out how to build a .dll to call in VBA and make possible my customized formulae. I want to make a .dll because of performance timing and so I started to study C++. As every project I've begun face issues after issues specially with the Range object to pass from VBA to my .dll.

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
  1. #include <iostream>
  2. #include <cmath>
  3. #include <OAIdl.h>
  4.  
  5. double __stdcall square(double& x)
  6. {
  7.     return x * 2;
  8. }
  9.  
  10. VARIANT __stdcall my_array(VARIANT *p)
  11. {
  12.     //my statements and operation on the array (Range received from VBA)
  13. }
  14.  
.def file

Expand|Select|Wrap|Line Numbers
  1. LIBRARY "square"
  2. EXPORTS 
  3. square @1
  4. my_array @2
  5.  

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
1 Week Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.