[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

cannot convert from 'char *' to 'char'

Posted on 2004-08-24
5
Medium Priority
?
633 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

830 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