error 2664 Conversion error

K

Karthik

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
 
H

Howard

Karthik said:
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
 
V

Victor Bazarov

Karthik said:
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
 
M

Me

Karthik said:
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.
 
K

Karthik

Quoting ME <[email protected]>:

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
 
H

Howard

Karthik said:
Quoting ME <[email protected]>:


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
 
L

Larry I Smith

Karthik said:
Quoting ME <[email protected]>:

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
 
K

Karthik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top