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
0
l
2/25/2010 7:50:43 PM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
810 Views

Similar Articles

[PageSpeed] 13

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 <lhsofteng@gmail.com>
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
0
Chip
2/25/2010 9:05:12 PM
On Feb 25, 1:05=A0pm, Chip Pearson <c...@cpearson.com> 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. =A0DLL 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,
> =A0 =A0 =A0 =A0 Excel, 1998 - 2010
> Pearson Software Consulting, LLCwww.cpearson.com
>
> On Thu, 25 Feb 2010 11:50:43 -0800 (PST), l h <lhsoft...@gmail.com>
> 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
0
l
2/25/2010 9:26:05 PM
Reply:

Similar Artilces:

Pie of Pie Chart type with smaller pie showing slices of main slic
Hi How can I do the following: Lets say I have the following labels and data For the main pie I have A,B,C labels with A =5, B =10, and C =20. So my main pie would show 3 slices with C being the largest slice. To do this I highlight the 3 labels and their data and choose Insert, Pie, Pie in a Pie to show a main pie on the left with 3 slices and a smaller solid pie to the right with series lines connectiing them. I want to show the solid smaller pie on the right in several slices to show how the C slice of 20 is broken down. lets say the main slice C of 20 is made up ...

Typing in macros
I have made a few macros and use them in word and excel 2000. When I see typed out macros on the message boards I am not quite sure how to use them. Do I go into the editor, type them in and then link them with a button on the toolbar? What module do I put them in and is there one for the personal worksheet. I have been struggling with the syntax of Visual Basics for years. Just need a step by step explanation. Thank You Sue In general, the macros you see in the groups are likely to be ordinary macros that will go into a general module in the VBE, eg:- Hit ALT+F11 and this will...

Open File Dialog to fileter multiple file types at once...?
Hello, Here is another quick one for you all. The solution is probably simple, but I cannot find the answer anywhere. I have the following code: CFileDialog OpenDlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY, ""); // Later must set this to retrieve a value from the registry OpenDlg.m_ofn.lpstrInitialDir = "c:\\"; OpenDlg.m_ofn.lpstrFilter = "txt Files\0*.txt\0Doc Files\0*.doc\0"; OpenDlg.DoModal(); I am trying to get the box to filter out everything but the *.doc and the *.txt files ... I have seen some boxes that have something that...

Need MS query to check Current Directory
I need to know how to make MS QUERY queries look at the CURRENT workbook Directory instead of the creation directory which it imbeds. I am NOT talking about the default directory in tool -> options-> general -> default file location. Example of query MTHLYISSUE.DQY XLODBC 1 DSN=MS Access Database;DBQ=C:\PROJECTS\BKL200401JAN\BOOKLEND.MDB;DefaultD ir=C:\PROJECTS\BKL200401JAN;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin; SELECT MonthlyIssuances.IssuanceMo, Sum (MonthlyIssuances.BookCnt) FROM BookLend.MonthlyIssuances MonthlyIssuances GROUP BY MonthlyIss...

VBA
What are the commands / syntax to change the Startup settings from VBA, and where could I go besides here to get that info? Thank you. I really appreciate all your help.. Hello "Programmer - wannaB". "Programmer - wannaB" wrote: > What are the commands / syntax to change the Startup settings from > VBA, and where could I go besides here to get that info? This should work in Access 2003 as well: http://msdn2.microsoft.com/en-us/library/aa140020(office.10).aspx -- Regards, Wolfgang Hello Wolfgang, Thank you, that is just what I was looking for. "Wolfgan...

Rectification of wrong posting type
Hi There is one PL account say "Mic Expenses" has got wrong posting type "Balance sheet", when we closed the year 2005 ,System has brought forward the balance of that account into next year 2006, which otherwise should have been gone into the Retain Earning of 2006, is there any option to rectify this error, other then passing rectifying JV in 2005(coz in that case if I take last year TB then ending balance of this account would be Zero) or restoring the backup and doing closing procedure again. Thanks in Advance Shabnam There is a Article ID for this in partner s...

Some chart types cannot be combined with other chart types?
Hi, I am getting the above error message everytime I try to insert a chart or any type into a completely blank presentation using either the Insert, Chart command or the Insert Chart button in the Title and Content slide layout. I am using 2007. Any help or suggestions would be appreciated. TIA, Shane Devenshire Try running Office Diagnostics, Shane. Open PPT or Excel, hit the Office button, then <app> Options | Resources. I think that may resolve this issue. -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2007? http://www.echosvoice.com/2007...

need help to declard type=IntType instead type="xsd:int" with xml schema
Hi, I am writing C# code to produce xml schema. //Create attribute XmlSchemaAttribute att2 = new XmlSchemaAttribute(); att2.Name = "CustomerID"; att2.SchemaTypeName = new XmlQualifiedName("int",schemaNS); att2.Use = XmlSchemaUse.Required; ct.Attributes.Add(att2); I need to produce schema with custom data type instead of the xsd:string or xsd:int The code above will produce the following schema <?xml version="1.0" encoding="utf-8"?> <xsd:schema attributeFormDefault="unqualified" version="1.0" xmlns:xsd=...

Excel VBA
hi people, is there a way to setup a macro that records a time (like a stopwatc and the record this in a cell??? cheers stev -- Message posted from http://www.ExcelForum.com Is it a specific time you want or a counter that rises as time passes To just get a specific time and record it in a cell you can use th NOW() function. Dunca -- Message posted from http://www.ExcelForum.com Hi there, Just like a stopwatch, so i click a button to start and one to stop Hope that helps thanks stev -- Message posted from http://www.ExcelForum.com If you want something that counts visually on ...

Scatterplots with different colors based on Type of Data
Is it possible to plot a scatterplot with different colors for 2 sets of data? E.g Type of Agreement MRP Discount% Limited 10 5% UnLimited 20 10% I want to show different colors for Limited & Unlimited. Is it possible to plot scatterplots on both axis(Primary & Secondary) Please let me know. Thanks, Satish If I use this range to make a chart Limited 10 5% Unlimited ...

outlook type interface
I have an SDI application and want to change it so I have a split window, on the left I want a TreeControl above a 'PropertyGrid' control. Then my exisiting SDI Client in the space on the right Can anyone point in the right direction to achieve this Any help will be much appreciated Thanks Phil You need to use two CSplitterWnds (as members of your CMainFrame). Override CMainFrame::OnCreateClient and create a vertical splitter as the main child (i.e. 1 row, 2 cols). Then you want to create a horz splitter as a child of the left-hand pane of the main splitter (which has 2 rows, 1 c...

VSTO Excel 2003 to VB 6.0 Type mismatch
Hi, I have an Addin 2003 Application. In this Application I'm calling an VB 6.0 Dll and I send Excel Application Object as Parameter. In VB Project I'm using Workbook_Open event with WithEvents. I have a messagebox there. Unfortunately when i call VB dll , I get this Error Message -- > Type mismatch. Is there any Idea? Code in VS2008 : private Project1.Class1 vbapp; private void ThisAddIn_Startup(object sender, System.EventArgs e) { #region VSTO generated code this.Application = (Excel.Application)Microsoft....

predictive typing of addressee
I am frequently sending sensitive email to a person who has a very common name. More than once I have almost sent the email to the wrong party because of the Outlook feature that predicts the addressee name. Does anyone know how to eliminate names from the dropdown list that appears as you type tha addressee name? Or is there a way to stop addressee names from appearing automatically as you type in the "To" field. Any help will be appreciated. joanne Use arrow keys to highlight error address, then hit Delete Btn Do you use Contacts?, hitting the 'To' Btn will bri...

"Can't change data type" error
I'm trying to reduce the field size of text fields in my database. They defaulted to 255 characters when I created my database but in many cases I only need a size of around 20. When I enter the reduced size for one field in the table design view and try to save the change to that field I get the following errors: "Microsoft Access can't change the data type. There isn't enough diskspace or memory." When I click OK to the above I then get the following message: "Errors were encountered durnig the save operation. Data types were not changed. Properties w...

How to convert CString type to LPCSTR type
Hi, I have a CString type variable, and I need to convert it's to LPCSTR type ,what I can do! example: CString m_strExecFile(_T("C:\\\\aa.exe")); next I want to call WinExec Command to execute this file LPCSTR lpcstr ; lpcstr = m_strExecFile.GetBuffer(); WinExec(lpcstr,SW_SHOW); BUT the compilier tells me it can not convert w_char * to LPCSTR type! Why? ps. I use vs2005 program in UNICODE mode. Any helpful ideas would be highly appreciated! -joseph Why use a CString in this case at all, if all you are doing is using it in WinExec. Something ...

Aggregate data types mismatch
Using reporting services 2008. Getting a really weird error when calculating a variance between a budget and actual amount in the report. Both the underlying fields are of data type 'money', but when performing the calc in the report writer, i am getting the following error: [rsAggregateOfMixedDataTypes] The Value expression for the textrun 'Variance_MTD_ActualvsBudget1.Paragraphs[0].TextRuns[0]' uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a si...

Check Box Question
I have a user form with several Check Boxes that are for controlling worksheets in a workbook. Each check box is for hiding or unhiding the different worksheets in a workbook from the user form2. Workbook name = Installer Forms Worksheet name = Sheet 1 Checkbox names = Office_Package_Preparations_101 I want when the Box is checked for the worksheet to be shown and when the box is not checked for the worksheet to be hidden. Hi Brian, Important consideration is that you cannot hide all sheets so must test for at least 2 visible sheets before hiding a sheet. If...

VBA
I am very new to VBA and access and have a question regarding a SELECT statement. I am going to run a select (recordset - so I can loop through and process each record) but on my SELECT I want to make sure I return at least 20 rows, otherwise I am going to change my WHERE clause to include more rows. Is there an easy way to do this or do I need to just do an inital SELECT COUNT(*) and then decide which WHERE clause to use?? Do you have an example I can look at? Thank you in advance! AJ On Fri, 14 Dec 2007 17:14:00 -0800, AJ <AJ@discussions.microsoft.com> wrote: I would not first ...

Determining address of value type variables
How to get the address of(memory location) value type variables? GetHashCode() returns only value and not its address Thank you Regards Raj "Raj" wrote: > How to get the address of(memory location) value type variables? > > GetHashCode() returns only value and not its address > > Thank you > > Regards > Raj An address in memory and a hashcode have nothing to do with each other. You should rarely, if ever, need to get an address of any .net object. To get an address in memory, you need to use unsafe code and the "&a...

Change types
I hav got a letter with types that i cannot understand. When i mark some of the words, tells me that this type is sansserif. I think that this is a joke but i cannot find out how to change to arial or times new roman ...

Spell check not working 2007, 2010
All the appropiate check boxes etc are turned on. I can type a spelling mistake, hit proof and spell check and it says all ok.. no as you type functionality working either. help please ! ...

Advice for type of chart
I'm comparing the sugar content of different beverages. However the values vary for example cocktails may have between 90-130 grams per liter and vegetable juices perhaps 40-100 grams. Which type of graph should I use to represent the various drinks and show the single variations rather then their averages? Thanks, Rob Hi you could try using a "high low close" format, with the "close" value set equal to the high or low to make it effectively a "high low chart. Or, a stacked bar with the first series set to colour none, line colou none, has a similar effec...

Possible reasons for a C++ exception being thrown for line three?
std::string MatchedSTRING; String2MATCH[1000]; if (MatchedSTRING != String2MATCH) { My first guess was an index out of bounds error. should have said: char String2MATCH[1000]; "Peter Olcott" <NoSpam@SeeScreen.com> wrote in message news:g76Yh.18159$2Q1.749@newsfe16.lga... > std::string MatchedSTRING; > String2MATCH[1000]; > if (MatchedSTRING != String2MATCH) { > > My first guess was an index out of bounds error. > It would be alot easier to diagnose if we had some idea how long the strings were, or what kind of exception was thrown, and by whom, an...

CRM API: Converting an Object Type value -> ObjectType
I've setup post callouts in CRM which notify me when a CRM object has been modified. CRM sends me the ObjectType value so I know what type of object has been modified. For example 1 for an Account, 132 for an Activity... I can't figure out however how to convert the number back into an ObjectType. In theory it should be very simple, but from what I can tell the ObjectType class is NOT an Enum, oddly enough. I've tried the following: int objectTypeValue = 2; // which is a Contact // returns otActivity test = (ObjectType) Enum.ToObject(typeof(ObjectType), objectTypeValue); // r...

PA Check Links for #861428 (Clarification)
In Article 861428 "Historical or invalid notes are defaulting in on the Project Accounting billing invoice", it mentions as the last step running "PA Check Links". What logical tables need to be selected? All? History tables? ------=_NextPart_0001_28E96535 Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi David, Thanks for the post to the Microsoft Dynamics Newsgroups! In this case, you will want to run the PA Checklinks on ALL tables. Diana Van Raden Microsoft Online Support Engineer Get Secure! - www.microsoft.com/security =========================...