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
cdemez2@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
Tanja Krammer - 30 Mar 2006 12:04 GMT
Try to make your structure explicitely unmanaged with
#pragma unmanaged
struct UDTSOCKET {
}
#pragma managed
public __gc class UFOzSocket{
...
}
>I m trying to create a C++ managed class to use it in C#. I m new to MC++
>and
[quoted text clipped - 68 lines]
>
> Chris
Marcus Heege - 30 Mar 2006 13:54 GMT
Hi Chris,
>I m trying to create a C++ managed class to use it in C#. I m new to MC++
>and
[quoted text clipped - 68 lines]
>
> 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
Chris - 30 Mar 2006 17:48 GMT
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 ?