Solved

cannot convert from 'char *' to 'char'

Posted on 2004-08-24
5
573 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now