tags:

views:

70

answers:

2

This code was written in Visual Studio 2003, but now I compile it in 2008.

int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0);

if(iiRecd == SOCKET_ERROR || iiRecd == 0) {
  iErr = ::GetLastError();
  AfxMessageBox(CString(iErr));
  goto PreReturnCleanup;
}

In 2003, it works fine, but in 2008, it shows me an error:

Error 50 error C2440: '<function-style-cast>' : cannot convert from 'int' to 'CString'

What does this error mean?

+1  A: 

This is obviously because you used an expression of type int where an expression of type CString was expected. No more can be said without further code.

Armen Tsirunyan
+2  A: 

It's a bit hard to help without any information, like the erroneous code and what you want to do there.

Here's a guess: You want to convert an int to a CString, somehow like this:

int i = 42;
CString str = (CString)i;

If you're using the MFC/ATL CString you could try the following

int i = 42;
CString str;
str.Format("%d", i);

CString::Format takes a format string like printf and stores the result in the CString.

Edit

I'm interpreting your comment below as the code that causes the error. A bit surrounding text and explanation would be nice, though.

if(iiRecd == SOCKET_ERROR || iiRecd == 0) { 
  iErr = ::GetLastError();
  AfxMessageBox(CString(iErr));
  goto PreReturnCleanup; 
}

Try to change it to

if(iiRecd == SOCKET_ERROR || iiRecd == 0) { 
  iErr = ::GetLastError();
  CString msg;
  msg.Format("%d", iErr);
  AfxMessageBox(msg);
  goto PreReturnCleanup; 
}

One general comment on the goto PreReturnCleanup;: You may want to take a look at the RAII-Idiom as a (imho) better way to do such cleanup.

DerKuchen
check this line of code.....actually these code written in Visual studio 2003 and now i compile it in 2008...in 2003 it work fine but in 2008 it showing me errorint AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0); if(iiRecd == SOCKET_ERROR || iiRecd == 0) { iErr = ::GetLastError(); AfxMessageBox(CString(iErr)); goto PreReturnCleanup; }
tirupati
int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0);
tirupati
@tirupati: Please add your code to the original question. And make sure it's formatted (there's a `110110` button to format selected text)
MSalters