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
Solved

cannot convert from 'char *' to 'char'

Posted on 2004-08-24
5
601 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.

808 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