[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Type mismatch error

Posted on 2006-06-26
9
Medium Priority
?
381 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

829 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