469,356 Members | 2,626 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

error 2664 Conversion error

Hello
I am trying to convert the following???
The Code
std::string* ChkName;
GlobalInterfacePtr->MethodA(po*sition, bstr, ChkName);
error C2664: 'MethodA' : cannot convert parameter 3 from 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > ** ' to 'unsigned short ** '
Could anyone give me suggestions?
Thanks!
Karthik

Jul 23 '05 #1
7 10021

"Karthik" <ka*******@gmail.com> wrote in message
std::string* ChkName;
GlobalInterfacePtr->MethodA(po-sition, bstr, ChkName);

error C2664: 'MethodA' : cannot convert parameter 3 from 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > ** ' to 'unsigned short ** '

Could anyone give me suggestions?


What are you trying to do?

You're passing a std::string* to a function that's apparently expecting an
unsigned short**. Why are you doing that? What exactly are you trying to
accomplish?

(Also, what's "po-sition"? Are you subtracting "sition" from "po"?)

-Howard

Jul 23 '05 #2
Karthik wrote:
I am trying to convert the following???
The Code
std::string* ChkName;
GlobalInterfacePtr->MethodA(po*sition, bstr, ChkName);
error C2664: 'MethodA' : cannot convert parameter 3 from 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > ** ' to 'unsigned short ** '
Could anyone give me suggestions?


Not really. You are not even posting the real code, which probably
looks like

GlobalInterfacePtr->MethodA(position, bstr, &ChkName)

.. Now, apparently 'MethodA' has the third argument declared as
a pointer to a pointer to 'unsigned short', and you're sticking the
address of a pointer to 'std::string' there. WHY? Who knows... How
to fix it? Who knows... Post more code.

V
Jul 23 '05 #3
Me


Karthik wrote:
I am trying to convert the following???

std::string* ChkName;
Are you *really* sure you want a pointer to a string?
GlobalInterfacePtr->MethodA(po*sition, bstr, ChkName);
error C2664: 'MethodA' : cannot convert parameter 3 from 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > ** ' to 'unsigned short ** '
Could anyone give me suggestions?


It looks like you're using VC6 where wchar_t is a typedef for unsigned
short instead its own distinct type and the 3rd parameter for MethodA
is a wchar_t ** for some really stupid reason. Try this code instead:

std::wstring ChkName;
....
wchar_t *str = const_cast<wchar_t*>(ChkName.c_str());
GlobalInterfacePtr->MethodA(position, bstr, &ChkName);

Though this looks like a hack to work around a poorly defined member
function and evidence to consider something is wrong with the code
you're using.

Jul 23 '05 #4
Quoting ME <ant_sp...@Y....com>:

It looks like you're using VC6 where wchar_t is a typedef for unsigned
short instead its own distinct type and the 3rd parameter for MethodA
is a wchar_t ** for some really stupid reason.

Yes I am using VC++ 6.0. Please do see the code

Quoting ALL:

Alrt.. I am pasting the code of what I am doing... And Yes I need to
pass a BSTR value in the place of the third parameter

BEGIN_RULE_FUNCTION(rule_ONE_Schedule)
{

FIString batchName, lotStepName, lotName, stepName;

FIString remainingTaskName = "";

std::string* ChkName;

int position; //using it as an indexer....
char* StationName = new char[10];

// Copy text in the attribute
strcpy (StationName, theStation->name().data());

wchar_t wstr[256];

// Transform the text in the COM format
MultiByteToWideChar (CP_ACP, 0, StationName, -1, wstr, sizeof(wstr) /
sizeof (wchar_t));

// Format for the communication, and memory allocation
BSTR bstr = SysAllocString (wstr);

WCHAR ws[256];

MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, taskName->c_str, -1,
ws, sizeof(ws) / 2 - 1);

BSTR tName = SysAllocString (ws);

GlobalInterfacePtr->MethodA(position, bstr, &tName);

while ((tName != NULL))
{
batchName = tName->c_str();

rescueBatchName = tName->c_str();

//some other code.....

}
}

What this code does is... Passes the parameters to the Function written
in C# and gets a string value in return, the parameter "tName"
mentioned in the GlobalInterfacePtr->MethodA(.......).. and checks the
value in side the tName and goes into the "While" loop...

Does this help to provide a lead?

The error I get is

error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from
'const char *(void) const' to 'const char *'
There is no context in which this conversion is possible

Any thoughts???

Thanks a much!

Karthik

Jul 23 '05 #5

"Karthik" <ka*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Quoting ME <ant_sp...@Y....com>:
Alrt.. I am pasting the code of what I am doing... And Yes I need to
pass a BSTR value in the place of the third parameter
I have no idea what a "BSTR" is. I assume your'e talking about some
Microsoft-defined type? It has nothing to do withe the error, though. (see
below)


MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, taskName->c_str, -1,
ws, sizeof(ws) / 2 - 1);
The error I get is

error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from
'const char *(void) const' to 'const char *'
There is no context in which this conversion is possible

Any thoughts???


This is different from what you posted before.

The error message says it can't convert from a function: "const char *(void)
const" to a pointer: "'const char *".

The problem is that you're passing taskName->c_str to the function. But
c_str is a function, not a variable. You're passing the address of that
function, when you need to pass the _results_ of that function call, by
adding the parentheses. It should be:

MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
taskName->c_str(), // note the parentheses!
-1, ws, sizeof(ws) / 2 - 1);

There may be other errors, but that's the one the compiler's complaining
about.

-Howard

Jul 23 '05 #6
Karthik wrote:
Quoting ME <ant_sp...@Y....com>:

It looks like you're using VC6 where wchar_t is a typedef for unsigned
short instead its own distinct type and the 3rd parameter for MethodA
is a wchar_t ** for some really stupid reason.

Yes I am using VC++ 6.0. Please do see the code

Quoting ALL:

Alrt.. I am pasting the code of what I am doing... And Yes I need to
pass a BSTR value in the place of the third parameter

BEGIN_RULE_FUNCTION(rule_ONE_Schedule)
{

FIString batchName, lotStepName, lotName, stepName;

FIString remainingTaskName = "";

std::string* ChkName;

int position; //using it as an indexer....
char* StationName = new char[10];

// Copy text in the attribute
strcpy (StationName, theStation->name().data());

wchar_t wstr[256];

// Transform the text in the COM format
MultiByteToWideChar (CP_ACP, 0, StationName, -1, wstr, sizeof(wstr) /
sizeof (wchar_t));

// Format for the communication, and memory allocation
BSTR bstr = SysAllocString (wstr);

WCHAR ws[256];

MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, taskName->c_str, -1,
ws, sizeof(ws) / 2 - 1);

BSTR tName = SysAllocString (ws);

GlobalInterfacePtr->MethodA(position, bstr, &tName);

while ((tName != NULL))
{
batchName = tName->c_str();

rescueBatchName = tName->c_str();

//some other code.....

}
}

What this code does is... Passes the parameters to the Function written
in C# and gets a string value in return, the parameter "tName"
mentioned in the GlobalInterfacePtr->MethodA(.......).. and checks the
value in side the tName and goes into the "While" loop...

Does this help to provide a lead?

The error I get is

error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from
'const char *(void) const' to 'const char *'
There is no context in which this conversion is possible

Any thoughts???

Thanks a much!

Karthik


You have this:

MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, taskName->c_str,
-1, ws, sizeof(ws) / 2 - 1);

Did you mean for it to be this?

MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, taskName->c_str(),
-1, ws, sizeof(ws) / 2 - 1);

i.e. change "parameter 3" from

taskName->c_str

to

taskName->c_str()

Regards,
Larry
Jul 23 '05 #7
Hey Larry and all...
Thanks a million... I was able to solve the bug.. yeah I missed the '(
)' in c_str...

Thanks a much!

Karthik

Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by c++newbie | last post: by
4 posts views Thread by yanyo | last post: by
6 posts views Thread by karthik.t | last post: by
2 posts views Thread by linq936 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.