473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to convert managed class to unmanaged char* in vc++.net

i'm new to vc++.net...I'm doing a project to send a packet to another machine like ping command...in this i'm using sendto() function..i have to convert all the class parametes to char*...
my code is ..
Expand|Select|Wrap|Line Numbers
  1.  
  2. int    SendEchoRequest(SOCKET s, LPSOCKADDR_IN lpstToAddr)
  3.        {
  4.            ECHOREQUEST &echoreq=*new ECHOREQUEST;
  5.            static nID=1;
  6.            static nSeq=1;
  7.            int nRet;
  8.            echoreq.IcmpHDR->Type=ICMP_ECHOREQ;  
  9.            Console::WriteLine(S"Type :{0}",echoreq.IcmpHDR->Type.ToString());    
  10.            echoreq.IcmpHDR->Code=0; 
  11.            echoreq.IcmpHDR->Checksum=0;  
  12.            echoreq.IcmpHDR->ID=nID++;
  13.            echoreq.IcmpHDR->Seq_no=nSeq++;
  14.            for(nRet=0;nRet<REQ_DATASIZE;nRet++)
  15.            {
  16.                echoreq.Cdata[nRet]=' '+nRet;
  17.            }
  18.            echoreq.dwTime=GetTickCount();
  19.            const char *buffer;
  20.            int length;
  21.            System::Runtime::InteropServices::Marshal::Copy(echoreq,0,buffer,length);    
  22.            //echoreq->IcmpHDR->Checksum =in_cksum((unsigned short *)&echoreq,echoreq->ToString()->get_Length());
  23.            nRet=sendto(s,buffer,length,0,(LPSOCKADDR)lpstToAddr,sizeof(SOCKADDR_IN));
  24.            if (nRet == SOCKET_ERROR) 
  25.                ReportError("sendto()");
  26.             return (nRet);
  27.        }
  28.  
i tried using marshall copy function but it wont work....what i'll do to correct this problem....
Jun 10 '08 #1
2 1319
Plater
7,872 Expert 4TB
What do you need a char* for now? I didn't see any unamanaged code in there?
Jun 10 '08 #2
Plater
7,872 Expert 4TB
What do you need a char* for now? I didn't see any unamanaged code in there?
Was it that sendto() function? Why not just use .NET sockets?
Jun 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
2
by: Weston Fryatt | last post by:
(Sorry for spamming multiple groups, But I need a solution to this problem) I think this should be a simple question on Memory Allocation in a managed DLL and passing a memory pointer over to an...
1
by: Jeremy Cowles | last post by:
Is it possible to pass an instance of a standard C++ class into managed memory and use it (MC++/C#/VB/J#)? I guess I am still foggy on the whole concept of Managed C++. TIA, Jeremy
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
0
by: DotNetJunkies User | last post by:
Background: I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below: Range r = new Range( 2, 2 ); r = new Cell( “Hello Mum” ); Range is a...
5
by: joye | last post by:
Dear All, Many old C standard library is useful for string operation such as strcpy. But I meet some problem, a managed char array which declared in a structure and this structure has a instance...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.