473,398 Members | 2,368 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,398 software developers and data experts.

The "/clr" flag (C++ compiler) corrupt my structures !!

I m trying to create a C++ managed class to use it in C#. I m new to MC++ and
interoperability and I try to find a bug since a long time without succes,
maybe you can help me ?

(I have a sample project if you want to debug it, you can contact me at
cd*****@hotmail.com too)

I describe the problem:

I have 2 MS VC2003 projects... they contains the same set of classes. I have
difference between both projetc, the first one is a MC++ project I have
create (C++ project that use the /clr flag to have a Managed DLL for .NET),
the second is the original C++ library (that works fine!)

1 - Here is my managed class :
----------------------------------------------
public __gc class UFOzSocket
{
private:
addrinfo _hints;
public:
UFOzSocket(AddressFamily addressFamily, SocketType socketType);
~UFOzSocket();
void Connect(EndPoint * remoteEP);
protected:
UFOzSocket();
private:
UDTSOCKET _internalSocket;
};

During debugging, when I see this structure, it is like this :

Structure in the first application, see by the debugger (BAD fields order):
-----------------------------------------------------------------------------
- _hints : addrinfo
+ ai_addr : 0x00000000 sockaddr*
+ ai_addrlen : 0 unsigned __int32
+ ai_canonname : 0x00000000 char*
+ ai_family :2 __int32
+ ai_flags :1 __int32
+ ai_next : 0x00000000 addrinfo*
+ ai_protocol : 0 __int32
+ ai_socktype : 1 __int32

Structure in the second application, see by the debugger (GOOD fields order):
----------------------------------------------------------------------------------
- hints {ai_flags=1 ai_family=2 ai_socktype=1 ...} addrinfo
+ ai_flags : 1 int
+ ai_family : 2 int
+ ai_socktype : 1 int
+ ai_protocol : 0 int
+ ai_addrlen : 0 unsigned int
+ ai_canonname : 0x00000000 <Bad Ptr> char *
+ ai_addr : 0x00000000 {sa_family=??? sa_data=0x00000002 <Bad
Ptr> } sockaddr *
+ ai_next : 0x00000000 {ai_flags=??? ai_family=???
ai_socktype=??? ...} addrinfo *

So, how can I change this to force the first application to have the same
behavior ?

When I debug the second program (original one) all is fine. My solution
crash due to the fact that the structure is not good !

Thanks for your help

Chris

Mar 29 '06 #1
3 1635
Try to make your structure explicitely unmanaged with
#pragma unmanaged
struct UDTSOCKET {
}
#pragma managed
public __gc class UFOzSocket{
....
}

"Chris" <Ch***@discussions.microsoft.com> schrieb im Newsbeitrag
news:66**********************************@microsof t.com...
I m trying to create a C++ managed class to use it in C#. I m new to MC++
and
interoperability and I try to find a bug since a long time without succes,
maybe you can help me ?

(I have a sample project if you want to debug it, you can contact me at
cd*****@hotmail.com too)

I describe the problem:

I have 2 MS VC2003 projects... they contains the same set of classes. I
have
difference between both projetc, the first one is a MC++ project I have
create (C++ project that use the /clr flag to have a Managed DLL for
.NET),
the second is the original C++ library (that works fine!)

1 - Here is my managed class :
----------------------------------------------
public __gc class UFOzSocket
{
private:
addrinfo _hints;
public:
UFOzSocket(AddressFamily addressFamily, SocketType socketType);
~UFOzSocket();
void Connect(EndPoint * remoteEP);
protected:
UFOzSocket();
private:
UDTSOCKET _internalSocket;
};

During debugging, when I see this structure, it is like this :

Structure in the first application, see by the debugger (BAD fields
order):
-----------------------------------------------------------------------------
- _hints : addrinfo
+ ai_addr : 0x00000000 sockaddr*
+ ai_addrlen : 0 unsigned __int32
+ ai_canonname : 0x00000000 char*
+ ai_family :2 __int32
+ ai_flags :1 __int32
+ ai_next : 0x00000000 addrinfo*
+ ai_protocol : 0 __int32
+ ai_socktype : 1 __int32

Structure in the second application, see by the debugger (GOOD fields
order):
----------------------------------------------------------------------------------
- hints {ai_flags=1 ai_family=2 ai_socktype=1 ...} addrinfo
+ ai_flags : 1 int
+ ai_family : 2 int
+ ai_socktype : 1 int
+ ai_protocol : 0 int
+ ai_addrlen : 0 unsigned int
+ ai_canonname : 0x00000000 <Bad Ptr> char *
+ ai_addr : 0x00000000 {sa_family=??? sa_data=0x00000002 <Bad
Ptr> } sockaddr *
+ ai_next : 0x00000000 {ai_flags=??? ai_family=???
ai_socktype=??? ...} addrinfo *

So, how can I change this to force the first application to have the same
behavior ?

When I debug the second program (original one) all is fine. My solution
crash due to the fact that the structure is not good !

Thanks for your help

Chris

Mar 30 '06 #2
Hi Chris,

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
I m trying to create a C++ managed class to use it in C#. I m new to MC++
and
interoperability and I try to find a bug since a long time without succes,
maybe you can help me ?

(I have a sample project if you want to debug it, you can contact me at
cd*****@hotmail.com too)

I describe the problem:

I have 2 MS VC2003 projects... they contains the same set of classes. I
have
difference between both projetc, the first one is a MC++ project I have
create (C++ project that use the /clr flag to have a Managed DLL for
.NET),
the second is the original C++ library (that works fine!)

1 - Here is my managed class :
----------------------------------------------
public __gc class UFOzSocket
{
private:
addrinfo _hints;
public:
UFOzSocket(AddressFamily addressFamily, SocketType socketType);
~UFOzSocket();
void Connect(EndPoint * remoteEP);
protected:
UFOzSocket();
private:
UDTSOCKET _internalSocket;
};

During debugging, when I see this structure, it is like this :

Structure in the first application, see by the debugger (BAD fields
order):
-----------------------------------------------------------------------------
- _hints : addrinfo
+ ai_addr : 0x00000000 sockaddr*
+ ai_addrlen : 0 unsigned __int32
+ ai_canonname : 0x00000000 char*
+ ai_family :2 __int32
+ ai_flags :1 __int32
+ ai_next : 0x00000000 addrinfo*
+ ai_protocol : 0 __int32
+ ai_socktype : 1 __int32

Structure in the second application, see by the debugger (GOOD fields
order):
----------------------------------------------------------------------------------
- hints {ai_flags=1 ai_family=2 ai_socktype=1 ...} addrinfo
+ ai_flags : 1 int
+ ai_family : 2 int
+ ai_socktype : 1 int
+ ai_protocol : 0 int
+ ai_addrlen : 0 unsigned int
+ ai_canonname : 0x00000000 <Bad Ptr> char *
+ ai_addr : 0x00000000 {sa_family=??? sa_data=0x00000002 <Bad
Ptr> } sockaddr *
+ ai_next : 0x00000000 {ai_flags=??? ai_family=???
ai_socktype=??? ...} addrinfo *

So, how can I change this to force the first application to have the same
behavior ?

When I debug the second program (original one) all is fine. My solution
crash due to the fact that the structure is not good !

Thanks for your help

Chris


I can't tell you the precise source of your problem, but I am confident that
it is not related to C++/CLI interop. I assume you include different headers
in the different projects. Using #pragma unmanaged will not be useful here.

Marcus Heege
Mar 30 '06 #3
Yes,.... #pragma unmanaged do not help me !

The header that I include are :

#include <winsock2.h>
#include <Ws2tcpip.h>

Theses are standard headers file !! How can I include differents files ?!?!
I do not know how it is possible !

Have you another idea ?
Mar 30 '06 #4

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

Similar topics

0
by: Andrew | last post by:
I have a native c++ application that I built with the /clr compiler option. When the application is linked, I receive the following warnings: FaddClient.obj : warning LNK4227: metadata...
1
by: bonk | last post by:
I was told that it is possible to set the /clr compiler switch on a per file basis. I find this option in the project settings for the .cpp files. However that does not affect the header files. So...
12
by: Herby | last post by:
Iv compiled my current C++ project as \clr as i want to start putting in some specific C++\CLI code to serialize my MFC objects to .NET equivalents. The program crashes on startup, something to do...
2
by: bonk | last post by:
Hello, I am currently trying to wrap my head around what actually happens when I compile a normal (native) c++ class with the /CLR Flag in Visual C++ 2005 (C++/CLI). Suppose I have the...
1
by: RC | last post by:
Is there a built-in constant that I can use in a #if statement to conditonally compile a line of code based on the CLR/Compiler version e.g. something like: #if (CLRV2) string Foo =...
4
by: Duncan Smith | last post by:
I have a VS2005 C++ MFC project which #imports a type library. The goal is to introduce some managed code eventually, but for starters I just need to set the /clr compiler option and build the...
3
by: =?Utf-8?B?cm9iaW50dw==?= | last post by:
Hi, While debugging my application I have noticed that occasionally a message saying "Win32 Thread xxxx exited with code 0 (0x0)" appearing in the debug window. I investigated this some more and...
1
by: theunissen | last post by:
Hi, I have a Visual C++ project (pretty large) using MFC and ATL. It was converted from Visual C++6 to Visual C++2003, and last to Visual C+ +2005. Today I decided to turn on the CLR support...
4
by: dan | last post by:
I am trying to port a legacy MFC application to C++/CLI. I have managed to build the code under VS 2008 and I am in the process of enabling the /CLR compiler directive. My goal is to try and...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.