Type checking from VBA to C++?

L

l h

I'm new to VB/VBA and calling functions in external DLLs from VB/VBA.

If I declare a variable in VBA, assign a value and then call a C++
function in a DLL, is any type checking down between VBA and the C++
function? So if I declare a Long identifier in VBA and then call a
function that expects an enum type in C++, will the call be flagged
for type mismatch?

Thanks.

Les
 
C

Chip Pearson

No, there is no type checking, not even ByRef/ByVal checking. If you
pass a value to a C parameter that requires an address, you'll blow
up.

In your specific example of a VBA Long passed to a C++ enum, you're
probably alright (32-bit), but that is the exception to the rule,
since under the hood the enum is just a 32-bit integer. DLL functions
referenced via a Declare are completely outisde and independent of
VBA's internal type conversions, error hanldling, and other
hand-holding. Such functions are very unforgiiving. Screw it up and
Excel will crash.

Note, also, that in order to use a DLL function written in C++ from
VBA, that function must have been compiled with the __stdcall
directive.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 
L

l h

No, there is no type checking, not even ByRef/ByVal checking. If you
pass a value to a C parameter that requires an address, you'll blow
up.

In your specific example of a VBA Long passed to a C++ enum, you're
probably alright (32-bit), but that is the exception to the rule,
since under the hood the enum is just a 32-bit integer.  DLL functions
referenced via a Declare are completely outisde and independent of
VBA's internal type conversions, error hanldling, and other
hand-holding. Such functions are very unforgiiving. Screw it up and
Excel will crash.

Note, also, that in order to use a DLL function written in C++ from
VBA, that function must have been compiled with the __stdcall
directive.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
        Excel, 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com


Thanks for your help Chip.

Les
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top