Solved

cannot convert from 'char *' to 'char'

Posted on 2004-08-24
5
595 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
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prototype for MessageDlg in Embacadero XE 2 2 39
c++ getting the first 10 characters of a char* string 11 94
Which Linux flavors will this run on? 6 88
What is sub-make ? 2 60
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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