473,748 Members | 2,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle 'error C2440'

Hello Esteemed Developers
I am trying to develop basic TCP/IP Server-Client programs at the Visual C++ .NET, using Windows Forms Application(.NE T) template. I coded the following code snippets

FORM1.
--------------------------------------------------------------------------------------------------------------------
public __gc class Form1 : public System::Windows ::Forms::For

..
public
#define PORT 2222
#define IP_Addr "127.0.0.1
SOCKET ServerSocket, ClientSocket
sockaddr_in ServerSockAddrI n, ClientSockAddrI n
WSADATA wsaData
WORD wVersionRequest ed
int retBindVal, retListenVal, retSendVal, retRecvVal, ClientSockAddrI nLen
..
public: void Start_Server()
..

--------------------------------------------------------------------------------------------------------------------

FORM1.cp
--------------------------------------------------------------------------------------------------------------------
void Form1::Start_Se rver(

...
retBindVal = bind(ServerSock et,(sockaddr*) &ServerSockAddr In, sizeof(ServerSo ckAddrIn)); //Error Msg #
..
ClientSocket = accept(ServerSo cket, (struct sockaddr*) &ClientSockAddr In, &ClientSockAddr InLen); //Error Msg #
..

--------------------------------------------------------------------------------------------------------------------

When I build the application it gives me the following error
Error Msg #1: errorC2440: 'type cast' : cannot convert from 'sockaddr_in __gc*' to 'sockaddr*
Error Msg #2: errorC2440: 'type cast' : cannot convert from 'sockaddr_in __gc*' to 'sockaddr*

I guess that I should type cast unmanaged code to managed code. Please kindly guide me to solve this problem. I downloaded VC.NET Samples from microsoft.com. There are Socket samples in it, but they are not clear for me
I am requesting your kind helps
Thank you very much
Nov 17 '05 #1
2 2281

I'm also interested in fixing this error. Does anyone know how t
convert from 'unsigned short [19]' to 'char' .

Nat
-
auburnat
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message675662.htm

Nov 17 '05 #2
auburnate wrote:
I'm also interested in fixing this error. Does anyone know how to
convert from 'unsigned short [19]' to 'char' .


There is no meaningful conversion from 'unsigned short [19]' to 'char'.
To be of any help, we need to know what kind of object you have, and why
the compiler thinks it needs to convert it to 'char'.

--
David Olsen
qg********@yaho o.com

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6134
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
2
11528
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' : cannot convert from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2
5742
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project in debug mode, the following errors happened: d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xdebug(29): error C2365: 'new' : redefinition; previous definition was a 'member function' d:\Program Files\Microsoft Visual Studio...
17
2267
by: Fred Hebert | last post by:
I am trying to use a 3rd party DLL that requires the main window handle as a parameter. e.g. MyFunc(WHND MyHandle); The example looks something like this: Result = MyFunc(Handle); Where "Handle" is the Win32 handle.
12
10088
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display it. here is the 4 errors. c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from 'char ' to 'char '
0
968
by: Allen Maki | last post by:
/* I am trying to practice multidimensional array in a managed class using dynamical allocation. If I tried to compile the following codes, I would get the under mentioned c2440 error message. It is only practice. You may notice that I am not using "private"
5
5043
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
3
3151
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++ articles submited by someone in this forum. Unfortunately, my compilation is failed. Below is my code : // Main.cpp
2
20464
by: slizorn | last post by:
error is as stated in the topic above: error C2440: '=' : cannot convert from 'char *' to 'char' code is below void handleOneLine(string string1) { char * cstr, *p; int counter; string str (string1);
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.