Type mismatch error

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.



jhav1594Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jkrConnect With a Mentor Commented:
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
 
jkrCommented:
Try the '_bstr_t' helper class, e.g.

#include <comdef.h>

_bstr_t bstr(cfgName);

BSTR bstrName = bstr;

_xptOcx->SetConfigurationSetName( &bstrName );

0
 
jhav1594Author Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jkrCommented:
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
 
jhav1594Author Commented:
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
 
jkrCommented:
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
 
jhav1594Author Commented:

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
 
jhav1594Author Commented:
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
 
jhav1594Author Commented:
Hi jrk,
i found out what the error was.
Thanks for all your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.