Solved

Type mismatch error

Posted on 2006-06-26
9
354 Views
Last Modified: 2013-11-20
Hi,
I am trying to emulate a OCX control.
One of the method calls into the OCX control is

void CWiseIPTransport::SetConfigurationSetName(LPCTSTR lpszNewValue)
{
      static BYTE parms[] =
            VTS_BSTR;
      InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
             lpszNewValue);
}

I am trying to write the corresponding method in the OCX control using the class wizard and the above method is the only peice of code that i have for reference.
I am currently getting a "type mismatch" error for the data type used to represent lpszNewValue.

The following data type paramters have been used by me on a trial and error basis but every time i get the same " type mismatch " error.

LPCTSTR and BSTR*

The function call is used to access the OCX control is defined like this

_xptOcx->SetConfigurationSetName( cfgName );

where cfgName is of type CString.

Can anyone tell me the data type that i should use to represent the lpszNewValue.



0
Comment
Question by:jhav1594
  • 5
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16989215
Try the '_bstr_t' helper class, e.g.

#include <comdef.h>

_bstr_t bstr(cfgName);

BSTR bstrName = bstr;

_xptOcx->SetConfigurationSetName( &bstrName );

0
 

Author Comment

by:jhav1594
ID: 16994876
I cannot change the way that i call the method

i.e        _xptOcx->SetConfigurationSetName( &bstrName ); cannot be changed.

the only thing which can be adjusted is how the method is implemented in the OCX control.

Any ideas on that !!!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 16995288
Then do it the other way rounnd - in your control, use

_bstr_t bstr(bstrCfgName);

LPCTSTR cfgName = (char*) bstr;

BTW, what you have posted in code and explanation about the problem and what you want to do (plus an incomplete error message) is *less* than helpful. Nobody here has a crystal ball.
0
 

Author Comment

by:jhav1594
ID: 16995923
Hi jkr,
sorry abt the poor explaination.

Let me see if i can explain this better.

void CWiseIPTransport::SetConfigurationSetName(LPCTSTR lpszNewValue)
{
     static BYTE parms[] =
          VTS_BSTR;
     InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
           lpszNewValue);
}

The above code is used to access an OCX method in an OCX control. I dont have the code for the corresponding OCX control.
Hence, i am supposed to write an OCX control and incorporate a "SetConfigurationSetName" method inside of it based on the DISPID "0x8" provided to me .

I am using the ClassWizard to write the SetCOnfigurationSetName method and using LPCTSTR as the parameter type.

Now when the external program tries to access my OCX control i.e tries to access the "SetConfigurationSetName"
method, i get the following error :-   "2147614725" when i look it up in the error lookup i get a "type mismatch".

My Problem is that i dont know which parameter type to use for the above mentioned method. when i try to use LPCTSTR or BSTR*, i get the same type mismatch error.

Hope this explaination is better.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 16996027
So, what does your implementation in the OCX look like and what is the IDL/ODL interface definition? The 'InvokeHelper()' call is usually generated from that description.
0
 

Author Comment

by:jhav1594
ID: 16996115

The invokeHelper() is generated from that description

My implementation is defined as follows.

ODl File

                  [id(8)] void SetConfigurationSetName(BSTR CfgName);
ctrl.h file

      dispidSetConfigurationSetName = 8L,
      afx_msg void SetConfigurationSetName(LPCTSTR CfgName);

ctrl.cpp file

            DISP_FUNCTION_ID(CWiseIPTransportCtrl,            "SetConfigurationSetName",  8, SetConfigurationSetName,
                                              VT_EMPTY, VTS_BSTR)

and the actual function implementation is

void CWiseIPTransportCtrl::SetConfigurationSetName(LPCTSTR CfgName)
{
       // Logging into file  to ensure that the function is called.
      m_pTools->LogMsg("Function SetConfigurationSetName Function Invoked");
}

All the above were automatically generated by the Class Wizard. I had to manually change the DISPID to "0x8"
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 16996459
Well, the implementation usually sin't generated, and IMHO should be

void CWiseIPTransportCtrl::SetConfigurationSetName(BSTR* CfgName)
{
       // Logging into file  to ensure that the function is called.
     m_pTools->LogMsg("Function SetConfigurationSetName Function Invoked");
}
0
 

Author Comment

by:jhav1594
ID: 16997924
Hi jkr,

i did try and implement BSTR* as the parameter type in the ctrl.h and ctrl.cpp file but  it did not work.

Could it be anything else.
0
 

Author Comment

by:jhav1594
ID: 16998474
Hi jrk,
i found out what the error was.
Thanks for all your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now