Solved

Type mismatch error

Posted on 2006-06-26
9
353 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

705 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

20 Experts available now in Live!

Get 1:1 Help Now