Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Type mismatch error

Posted on 2006-06-26
9
356 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

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

Suggested Solutions

Title # Comments Views Activity
move a line in eclipse 3 107
Smart Camera scanning and reading information 3 113
has77  challenge 9 89
twoTwo  challenge 35 107
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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

856 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