ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type checking from VBA to C++? (https://www.excelbanter.com/excel-programming/439991-type-checking-vba-c.html)

l h

Type checking from VBA to C++?
 
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

Chip Pearson

Type checking from VBA to C++?
 
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




On Thu, 25 Feb 2010 11:50:43 -0800 (PST), l h
wrote:

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


l h

Type checking from VBA to C++?
 
On Feb 25, 1:05*pm, Chip Pearson wrote:
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

On Thu, 25 Feb 2010 11:50:43 -0800 (PST), l h
wrote:

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



Thanks for your help Chip.

Les


All times are GMT +1. The time now is 01:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com