?
Solved

cannot convert from 'char *' to 'char'

Posted on 2004-08-24
5
Medium Priority
?
623 Views
Last Modified: 2010-04-01
With code below, i got error C2440: '=' : cannot convert from 'char *' to 'char'.
What do i did wrong?

char *StreamClient(char *streamServer, short portNumber, long UserId, char Type[3])
{
      ...
      return response;      //response is a char[10]
}

STDMETHODIMP CCom::Add(LONG UserId, char *Result)
{
      AFX_MANAGE_STATE(AfxGetStaticModuleState());

      OpenConn();
      *Result=StreamClient(SERVERNAME, SERVERPORT, UserId, "ADD");
      WSACleanup();
      CloseConn();

      return S_OK;
}
0
Comment
Question by:mammouth
[X]
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
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 11886919
Shouldn't that be

STDMETHODIMP CCom::Add(LONG UserId, char **Result) // <---- !
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    OpenConn();
    *Result=StreamClient(SERVERNAME, SERVERPORT, UserId, "ADD");
    WSACleanup();
    CloseConn();

    return S_OK;
}

?
0
 
LVL 15

Expert Comment

by:efn
ID: 11886946
StreamClient returns a pointer to char.  Result is a pointer to char, so *Result is a char.  The compiler should be happy if you assign the value returned from StreamClient to Result instead of *Result.

But jkr's solution is more likely to be useful.

--efn
0
 
LVL 86

Expert Comment

by:jkr
ID: 11886949
Or

STDMETHODIMP CCom::Add(LONG UserId, char *Result)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    char* tmp;
    OpenConn();
    tmp=StreamClient(SERVERNAME, SERVERPORT, UserId, "ADD");
    strcpy(Result,tmp);
    WSACleanup();
    CloseConn();

    return S_OK;
}
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 11886983
StreamClient returns a char*  (Pointer to a character)

and Result is declared as char* (Pointer to a character)

The dereferenced thing *Result is just a character.

So when you assign the character to the result of StreamClient (which is a pointer to a character):
the types are incompatible

The result parameter would need to be of type char**  instead

(or StreamClient needs to return a char type instead of a char*)
0
 
LVL 1

Author Comment

by:mammouth
ID: 11891732
When i do any of jkr solution, i got error.

f:\VSDotNet\Vc7\atlmfc\include\atlcom.h(1759): error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class
        with
        [
            Base=CCom
        ]


//com.cpp file
STDMETHODIMP CCom::Add(LONG UserId, char **Result) // <---- !
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    OpenConn();
    *Result=StreamClient(SERVERNAME, SERVERPORT, UserId, "ADD");
    WSACleanup();
    CloseConn();

    return S_OK;
}

//.idl file
[id(1), helpstring("method Add")] HRESULT Add([in] LONG UserId, [out,retval] char **Result);

//.h file
STDMETHOD(Add)(LONG UserId, char **Result);


What's wrong?
note: Before i used Result as a CHAR, it were a LONG.

Thankx
0

Featured Post

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.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

741 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