473,396 Members | 1,871 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,396 software developers and data experts.

How to convert structure from managed to unmanaged type

Esteemed Developers
I am trying to pin a structure, but compiler does not execute this statement. Can you kindly check where could be the problem is? (I use Visual C++ .NET Standard

Form1.
--------------------------------------------------------------------------------
public __gc class Form1 : public System::Windows::Forms::For
{
public
....
int retBindVal
SOCKET ServerSocket, ClientSocket
sockaddr_in ServerSockAddrIn, ClientSockAddrIn
.....

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

================================================== ===============
Form1.CP
-------------------------------------------------------------------
void Form1::Start_Server(

...
sockaddr_in __pin * pinned_ServerSockAddrIn; //This statement is nor executed. It jumps to next statement directl
pinned_ServerSockAddrIn = &ServerSockAddrIn
retBindVal = bind ( ServerSocket, (struct sockaddr*) &pinned_ServerSockAddrIn, sizeof(*pinned_ServerSockAddrIn) )
...

================================================== ======
I tried __pin at structure but it did not work,too. My code was as follows
sockaddr_in __pin * pinned_ServerSockAddrIn
pinned_ServerSockAddrIn = &__box(ServerSockAddrIn)

the compiler gave the following error message:
error C3627: Only a value type can be boxe
Nov 17 '05 #1
3 1601
Alper AKCAYOZ wrote:
sockaddr_in __pin * pinned_ServerSockAddrIn; //This statement is nor executed. It jumps to next statement directly
pinned_ServerSockAddrIn = &ServerSockAddrIn;


The first statement is skipped because it is just a declaration that
doesn't contain any code to execute. The variable isn't actually
initialized until the following statement. I would normally combine the
declaration and the initialization into a single statement:

sockaddr_in __pin * pinned_ServerSockAddrIn = &ServerSockAddrIn;

This won't change the behavior of your code at all, so if you are having
problems, the problems are somewhere else.

--
David Olsen
qg********@yahoo.com

Nov 17 '05 #2
Hello David
Thank You very much for your response.
I have tried your recommendation before. As you mentioned that the problem seems to be somewhere else. Problem is at the bind() and then, of course, at the listen() functions. When I use the following code, the bind() returns Error#10047 that is "Address family not supported by protocol family". The code is as follows

sockaddr_in __pin * pinned_ServerSockAddrIn = &ServerSockAddrIn
retBindVal = bind(ServerSocket, (struct sockaddr*)&pinned_ServerSockAddrIn, sizeof(*pinned_ServerSockAddrIn) )

I found a solution for the "struct" casting. At this code, there is not any __pin. Therefore the first line above is omitted. The working code is as follows

retBindVal = bind(ServerSocket, (struct sockaddr*)&pinned_ServerSockAddrIn, sizeof(*pinned_ServerSockAddrIn) )

I would like to thank your consideration, again.
Nov 17 '05 #3
Hello David
I notices that I wrote the wrong code to my previous response
Working code is as follows

retBindVal = bind(ServerSocket, (LPSOCKADDR)&ServerSockAddrIn, sizeof(ServerSockAddrIn));
Nov 17 '05 #4

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

Similar topics

2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
1
by: Jason Zhang | last post by:
Hi all, If I have a program wroten in C,and defined a struct like this: typedef struct data { int m_i; int m_j; }data; data myData;
1
by: Jonathan Amend | last post by:
I'm trying to port some C++ code to VB.NET but I have hit a snag. I need to add the pointer of a structure which includes an array to an array and then pass it to an API. Here are the two code...
5
by: Michael D. Reed | last post by:
I have legacy DLL code written in C++ that is essentially C code, an implementation of a set of formulas used in our industry. There are no DB or GUI interfaces, just exposed methods. I would...
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem") The...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
16
by: pkoniusz | last post by:
Hello everybody, Been just thinking how actually one could convert the following unmanaged code to the managed C++: struct JustAnExample { char value1; int value2; // etc ....
2
by: =?Utf-8?B?Y2pz?= | last post by:
Hi, I have CLI/C++ code to override WndProc(Message% m) in order to create NC area. I tried to marshal unmanaged ptr (m.LParam) to managed object by using Marshal::PtrToStructure like: if...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.