Boolean parameter in ActiveX method: wrong ole conversion?

I'm using Visual Studio 2005 and unmanaged C++ to write an MFC ActiveX
I want to add a method that takes a boolean parameter.
Through the wizard I add this parameter as VARIANT_BOOL and so the
wizard adds the following line in my idl file:
    [id(1), helpstring("method Test")] void Test(VARIANT_BOOL bParam);
Moreover, it adds the following line in my control header file:
    void Test(VARIANT_BOOL bParam);

I write the following simple code for the new method:
    void MyCtrl::Test(VARIANT_BOOL bParam)
        if (bParam==VARIANT_TRUE) MessageBox(L"True");
        else if (bParam==VARIANT_FALSE) MessageBox(L"False");
        else MessageBox(L"Unknown!");

I test it using VB 6, and when I call:
    MyCtrl1.Test False
I get a message box saying "False" (that's correct), but when I call:
    MyCtrl1.Test True
I get a message box saying "Unknown!"
I've put a breakpoint in my C++ code and I see that when the Test
method is invoked passing 'True', the bParam value is "1" instead of

I thought that VARIANT_BOOL was the correct type for the VB type
'Boolean', but it seems that the VARIANT_BOOL type is converted to a
BOOL type even if the class method takes a VARIANT_BOOL parameter.

Does anyone know which is the correct way to make this works?

Thanks in advance,

2/21/2006 4:33:27 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 35

"sdca" <> schrieb im Newsbeitrag
> I write the following simple code for the new method:
>    void MyCtrl::Test(VARIANT_BOOL bParam)
>    {
>        AFX_MANAGE_STATE(AfxGetStaticModuleState());
>        if (bParam==VARIANT_TRUE) MessageBox(L"True");
>        else if (bParam==VARIANT_FALSE) MessageBox(L"False");
>        else MessageBox(L"Unknown!");
>    }
> I test it using VB 6, and when I call:
>    MyCtrl1.Test False
> I get a message box saying "False" (that's correct), but when I call:
>    MyCtrl1.Test True
> I get a message box saying "Unknown!"

Never compare against true, TRUE, VARAINT_TRUE or any other representation 
of it. Anything that evaluates to 0 is false, and anything non-zero is true, 
but that does nt mean that it also is equal to true. Yes, a VARIANT_BOOL 
should always be VARIANT_FALSE (0) or VARIANT_TRUE (-1), but you shouldn't 
depend on that. Microsoft has not been very strict in the proper use of 
boolean types. There are even functions in MFC, which are declared to return 
a BOOL with three distinct values 0, 1 and 2.

If you want to test an expression against true, use "if (expression) ..." 
and to test against false use "if (!expression) ..." or, if you prefere it 
more verbose, use "if (expression != false) ..." and "if (expression == 
false) ..." (or whatever variaty of false, FALSE, VARIANT_FALSE or whatever 
is appropriate).


hozwirk.SPAM (112)
2/21/2006 5:35:26 PM

Similar Artilces:

VC++ 2008: "MFC class from ActiveX control" wizard doesn't expose any properties
Recently I was forced to switch from VC++ 6 to VC++ 2008. Many projects to convert, many errors to fix, many days to -- well -- spend. One day I recompiled and registered a MFC ActiveX control. That went fine. I had a few projects that use that control, so I removed the old H/CPP wrapper files from one of them and imported the control using Project -> Add Class -> MFC Class From ActiveX Control. The wizard re-generated H/CPP files, containing wrapper class for the control. When I recompiled the project I got many errors saying dozens and dozens of Get/Set methods are not members of my co...

How to track where a parameter is being called for?
I'm having a recurring problem. As I'm working on a form is based on a query, with subforms also based on queries, every once in a while it will start asking me for some obscure parameter. Generally it's been from removed or renamed fields, but that aren't applicable anymore to the form. Recently I had the problem, and I check and rechecked all the SQL for the queries feeding the form and subforms. Finally, I realized that it was in the Master Field property of a subform control. My question then, is this... When opening a form asks for a parameter, is there a clear wa...

boolean search
Hi can msoutlook 2003 search through all email folders for emails containing text word1 +word2 instead of finding all emails with either word1 or word2 in them. I guess a boolean search is what i'm looking for. If not is there an alternative solution. thanks Blue <> wrote: > can msoutlook 2003 search through all email folders for emails > containing text word1 +word2 instead of finding all emails with > either word1 or word2 in them. I guess a boolean search is what i'm > looking for. Here's how:

Strange: wrong language resource loaded in Vista
Hi Experts: I have an MFC application which has a resource file storing strings in multiple languages. The string for a particular language is loaded through CString::LoadString. It has been working well on Windows XP. But after re-build the application under Windows Vista, a strange thing happened: in release mode, incorrect language string is loaded, for example, the expected string is English but instead, German string is loaded; this does not happen in debug mode. Since the problem is happening only in release mode, I have tried using many globals for debugging but could not find ...

Need to keep record of telephone conversions as in sales
I work from home and in sales i need to keep a record of my telephone conversations, i have outlook which i use but want a excell spreadsheet which i can see all my calls at once. In Excel, create a list of calls. In row 1, enter the headings, e.g. Data, Start, End, Name, etc. To enter the date, type: Ctrl + ; In another column, enter the Start time, by typing: Ctrl + : When the call ends, enter the end time in a third column, by typing: Ctrl + : In additional columns, enter other data about the call, e.g. Person called, purpose, outcome. tracy wrote: > I work from home and...

Boolean expressions in the where statement
Im trying to build a form with multiple check boxes that each apply a filter to the records displayed. I need for the user to be able to select any combination of the checkboxes and have the resulting records filtered accordingly. I was thinking something along the lines of a "select" or statement or an if...else loop, but unfortunately im fairly new with sql am having trouble with the syntax, assuming its even possible. Something along the linse of: Select * from Table Where If (chkA = true) then chkA Else (chkB = true) then chkB else (chkA = true) and (ch...

Create a Activex Dll in VC++6.0
Hi, I had create a ocx to view some images in vc++ 6.0 when used that ocx in Internet explorer it takes time to display the image. I came to know that Activex dll will be faster that the Activex ocx ,any one can say how to create a Activex dll in vc++ 6.0 Thanks in advance Hi No differance between .ocx & .dll. For ActiveX controls the name 'dll' is turned into 'ocx', but they are...

Postmessage and default parameters
Hi, I have a weird problem with the PostMessage() function. I call PostMessage(MY_MESSAGE, 0, 0) from a thread created with _beginThread(). I have a handler function in a class that is called when this message is sent from the thread. The function is declared like this: LRESULT CMyDlg::OnMessage(WPARAM wParam, LPARAM lParam); The problem is that the parameters (wParam and lParam) aren't 0 as the PostMessage() call specifies. They are actually set to 2. However, if I call PostMessage(MY_MESSAGE, 3,4) I get 3 and 4 for the parameters. It seems like whenever I use the default parameter I g...

ActiveX vs Forms
Hello- I am trying to embed some option buttons on a worksheet. I want to have two sets of buttons which are mutually exclusive, say A-D and then 1-3. I want to start with 1-3 hidden and if the user chooses option D from the first set then 1-3 will be revealed. I did this fine with the activex option buttons and VBA, however, it is not recognizing A-D and 1-3 as separate groups. Therefore, as soon as the user select 1,2 or 3, it will uncheck D and therefore rehide the remaining numbered boxes. I grouped and named each set of buttons together, but that did not work. If I try to use a group...

Deserializing a boolean value
Hello, I have an xml that I can deserialize into a class, everything works OK. The thing is, the xml that I receive may contain 'False' instead of 'false'. This choke XmlSerializer. Just as an example, this is my class [XmlRoot(ElementName="Test")] public class Test { [XmlElement(ElementName="TestBool")] public bool TestBool { get; set;} } if I have an xml that has 'False' instead of 'false', I will get an exception. I do understand that the correct values are 'false' 'true', 1, and 0, but I may not have control o...

Array formula
I am trying to calculate the total number of successful installations by application name. This consists of one column (K7:K200) with the application name and another column with completion status (N7:N200). The completion status can be one of the following 'Successful', 'Anomolies', 'Rejected', 'Backed Out' or blank if it is yet to be installed. Only 'Succesful' or 'Anomolies' are classed as successful installations. So, I want to calculate the number of incidences of each Application type where the completion status is either 'Succes...

More on Boolean
I read the following and have a couple of questions. >> A Boolean logical input or output always takes one of two logic = levels. These logic levels can go by many names including: on / off, = high (H) / low (L), one (1) / zero (0), true (T) / false (F), positive / = negative, positive / ground, open circuit / close circuit, potential = difference / no difference, yes / no. In computer science, the Boolean datatype, sometimes called the logical = datatype, is a primitive datatype having two values: one and zero = (sometimes called true and false). It is the special case of a binary = n...

Boolean in Query
I have a query counting the number (sum) of ticks in a column i.e. yes/no data type. For each column, it is returning the numbers with a minus in front of it (obviously summing the -1's boolean). Is there a way around it cheers John Switch the query to SQL view. Copy what you see in SQL view and paste into a reply and post back here, so we can see why you are getting numbers with -1. Jeanette Cunningham "Khartoum" <> wrote in message >I have a query counting the number (s...

Multiple date parameters
I have three queries: MonthlyAll, MonthlyShows, and MonthlySpots. My main form is built off of MonthlyAll. It's main purpose is to provide a list of cities in a single form view, so that I can scroll through the cities and view the corresponding data. The main form contains two subforms: MonthlyShows and MonthlySpots. The subforms are linked to the main form by city and display the respective shows and spots by date. My question seems simple enough: Upon opening the form, I would like to type in a single date range ("Between [] And []"); and view only those shows and ...

XslCompiledTransform.Transform() method question
VS2005; .NET 2.0 I want to use the XslCompiledTransform.Transform() method for its stated purposes. However, I have an XmlDocument object already in memory and I can't figure out how to use that without first saving it to disk and then referencing that file in the Transform() method. xslt.Load("MyXSLfile.xslt"); XMLdoc.Save("XSLTtransform.xml"); xslt.Transform("XSLTtransform.xml", "XSLTtransform.htm"); String XMLtransform = File.ReadAllText("XSLTtransform.htm"); Now I have my transformed XML into HTML string and can put it in my ...

Embedded OLE Powerpoint slides in Access
Hi all, I've got some embedded Powerpoint slides in an Access database. How would I go about inserting the slides using VB into a powerpoint presentation? Is there also any filepath which I can use to manipulate them from a VB Module? As in, for me to read the text from the OLE Powerpoint slide object. Thanks KoldKay I suggest that you either build the slides from data in an Access table, or you store the slides externally, and use Access to maintain the paths, then reassemble the slides into a slide show. Several of the PowerPoint MVPs have done this and should have the code y...

Boolean AND
I've created a field in two different tables called "GroupCode". It's defined as a number, field length byte. In my Labor DB, I set the field to a value of 1. In my Inventory DB, I set the field to a value of 2. If it's used in both DBs, I set the field a value of 3 (1+2). It's a binary "dip switch". Now, when I start up my Labor DB, I set up a global variable called glbModuleID with a 1 or a 2. That variable is defined as a "byte" type, and it's global. I want the RowSource of a selection box to include only rows where the GroupCode ...

Method 'Add' of object 'CommandBarControls' failed
I have encountered a problem with an Commercial Addin program by J-Wal and Associates "PUP2000". I have used this Addin for years and hav never had a problem with it, ever. I also have a fine addin by Ron d Bruin "Google 6.0" which is great. The reason I mention both of thes addins is because Ron's Google 6.0 is working fine, but John's (Joh Walkenbach) PUP2000 menu does not load at all when I start Excel. Ron' Google 6.0 does get added but perhaps it's because Ron's product onl adds an item to the existing Help menu. The actual error message tha shows ...

Pass Parameters in Hyperlink
Is there a method to create a hyperlink in a cell where the hyperlink i to a batch file that requires a %1 parameter passed to it? I'd like to simply add a hyperlink like the following: "\\servername\sharename\file.bat parameter" But that does not work. Any ideas would be appreciated. Thanks -- Message posted from ...

How to select a boolean from a XpathNavigator
Hi. I have ax xpath expression which returns a true or false. I don't know which method to use from the XPathNavigator object to get the result. There's not a ".SelectValue("xpath expression") method. Typically, I may use ..Select or .SelectSingleNode but I'm not returning a node or set of nodes? Maybe I shouldn't be using a XPathNavigator? Please let me know if you have any ideas. Thanks! -- Steve Hi Steve, Use the XpathNavigator.Evaluate("XpathExpression") method. It will return an Object variable, that you can convert to Boolean usin...

Passing Parameters to a Pivot Table
Hi, We use parameters and Excel formulas (Start Date=Now()+1 year, End Date=Now(), etc.) to pull sales detail from an IBM system and it works fine. I want to use a piivot table to summarize 14,000+ lines of details into about 800 parts. Works great but I need to change the date range daily to capture 1 year of history. This is one of 12 different queries in the same file we want to do this with. Is there a way to use parameters in a Pivot Table like we are now doing with an MS Query? On Mar 11, 6:37=A0pm, Keith <> wrote: >...

Pass optional parameters to a method in a Dictionary (C#2.0) ?
Hi, We have some test code where we would want to invoke a method with optional parameters. In C# 4.0, I believe we could use named parameters, but we're using C# 2.0 I found a Dictionary solved my problem, but I'm not sure it's the best pattern for C# 2.0?. Could anyone please comment on whether or not there's a more appropriate pattern? Cheers artie EXAMPLE: public void AddToDatabase(Dictionary<string,object> fields) { string _surname = ""; string _city = ""; int _employeeId; if (fields.ContainsKey("...

Button on Form to Run Report based on Query with Parameters
Hi Guys. I am busy working on a stock control database (and job control). When I have a Form Open, it shows several fields, including JobID (Which is the PK for that job) (frm_Invoicing) I also have a Query that when Run, it prompts for the JobIDNo. (qry_CustJobsInvStock) I have a report based on that query. (rpt_CustJobsInvStock) I have added a button onto the form (onclick -> DoCmd.OpenReport) to open and automatically print the report, But I just cannot figure out how to get it to get my JobID from the form, and to Automatically add it as a Parameter for the que...

Role of baseAddress Parameter in UriTemplate.Match Method
I have been writing some samples with the UriTemplate class. I have noticed that the baseAddress parameter does not have to match the URI scheme in the candidate parameter in order to obtain a non-null UriTemplateMatch on return. If this is the case, what is the role of the baseAddress parameter? Thank you, EagleRed ...

Wrong Date on Calendar Tracking Tab In Outlook XP
I sent a meeting request from outlook XP on 12/16 and people responded to the meeeting. When I went into the tracking tab if I look under the "read" column it says that someone read it on 9/4/2003 and someone else on 8/20/2003. All the other ones are correct but those two. ...