Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

How to convert structure from managed to unmanaged type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alper AKCAYOZ - 19 May 2004 07:56 GMT
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
David Olsen - 20 May 2004 20:33 GMT
>   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.

Signature

David Olsen
qg4h9ykc5m@yahoo.com

Alper Akcayoz - 21 May 2004 08:01 GMT
 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
Alper Akcayoz - 21 May 2004 08:11 GMT
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));

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.