Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
l h l h is offline
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
l h l h is offline
external usenet poster
 
Posts: 2
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type Mismatch error while checking range value illini_99[_2_] Excel Programming 3 August 21st 08 06:36 PM
Checking formula type (reference to other worksheet or not) topola Excel Discussion (Misc queries) 2 July 23rd 07 10:48 AM
Checking range of cells for entry then checking for total Barb Reinhardt Excel Programming 1 October 13th 06 02:47 PM
Provide a way to turn off auto-checking excel formulas as I type t ikarius_rb Excel Discussion (Misc queries) 6 March 23rd 05 12:33 PM
Code works 1st time then Type Mismatch when checking for not blank cells Colleyville Alan Excel Programming 3 February 6th 04 05:21 AM


All times are GMT +1. The time now is 10:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"