Exposing a "null" dotnet object

P

Peter Hemmingsen

Hi,

I have a dotnet object (implemented in mc++ and used in c#) which have a
property called "Info". The Info property is also a dotnet object
(implemented in mc++). In the constructor of the "main" object I want to
initialize the property "Info" to null in a way that will make the c#
programmer (the user) able to write:

if (MyObj.Info==null) {..}

I've tried to initialize the Info property (in mc++) as follows:

this->Info=0; // Note Info is a __gc class pointer

but the above c# code always returns false.

Any suggestions?

Peter
 
N

Nishant S

Strange. I could not reproduce this problem.

MC++ class library :-

namespace mcpp_del
{
public __gc class Class1
{
public:
Object* GetObj()
{
Object* o = 0;
return o;
}
};
}

C# program :-

using System;
using mcpp_del;

namespace ConsoleApplication4
{
class Class2
{
[STAThread]
static void Main(string[] args)
{
Class1 c1 = new Class1();
Console.WriteLine(c1.GetObj() == null);
}
}
}

The output is :-

True
 
Y

Yan-Hong Huang[MSFT]

Hello Peter,

Thanks for posting in the group.

I did test also on my side and got the same result as Nish's. Here is my
code for your reference:

Managed C++ Object:

using namespace System;

namespace MCCL
{
public __gc class Info
{
};
public __gc class Class1
{
// TODO: Add your methods for this class here.
//public Info* i;
public:
Info* GetInfo()
{
Info * i = 0;
return i;
}

};
}

C# client:

static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
MCCL.Class1 test = new MCCL.Class1 ();
if ( test.GetInfo() == null)
Console.WriteLine ("We got a NULL");
else
Console.WriteLine ("We didn't get any NULL");
}

I could get "We got a NULL" output in the screen.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Peter Hemmingsen" <[email protected]>
!Subject: Exposing a "null" dotnet object
!Date: Thu, 11 Sep 2003 16:44:06 +0200
!Lines: 24
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups:
microsoft.public.dotnet.languages.csharp,microsoft.public.dotnet.languages.v
c
!NNTP-Posting-Host: heimdal.softco.dk 80.199.79.33
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28224
microsoft.public.dotnet.languages.csharp:184108
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Hi,
!
!I have a dotnet object (implemented in mc++ and used in c#) which have a
!property called "Info". The Info property is also a dotnet object
!(implemented in mc++). In the constructor of the "main" object I want to
!initialize the property "Info" to null in a way that will make the c#
!programmer (the user) able to write:
!
!if (MyObj.Info==null) {..}
!
!I've tried to initialize the Info property (in mc++) as follows:
!
!this->Info=0; // Note Info is a __gc class pointer
!
!but the above c# code always returns false.
!
!Any suggestions?
!
!Peter
!
!
!
!
!
!
 
P

Peter Hemmingsen

Hi,

Thanks a lot for your reply. To be honest I'm VERY confused. I did exactly
as you,- and it didn't work. Then I closed Studio and rebooted - and then it
worked. Pure magic. I know it sounds stupid,- but that's what happened.

Thanks.

Peter
 
Y

Yan-Hong Huang[MSFT]

Hello Peter,

It is also the first time for me to see such behavior. It seems strange to
me also. Perhaps there is some chaos in the system at that time. There is
no way to reset .NET framework. So rebooting machine makes it work.

Any way, it is not related to coding and I am glad to see all are working
fine now. Please post here if you have follow up questions.

Thanks for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Peter Hemmingsen" <[email protected]>
!References: <[email protected]>
<[email protected]>
!Subject: Re: Exposing a "null" dotnet object
!Date: Fri, 12 Sep 2003 09:57:22 +0200
!Lines: 116
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups: microsoft.public.dotnet.languages.vc
!NNTP-Posting-Host: heimdal.softco.dk 80.199.79.33
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28247
!X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!
!Hi,
!
!Thanks a lot for your reply. To be honest I'm VERY confused. I did exactly
!as you,- and it didn't work. Then I closed Studio and rebooted - and then
it
!worked. Pure magic. I know it sounds stupid,- but that's what happened.
!
!Thanks.
!
!Peter
!
!!> Hello Peter,
!>
!> Thanks for posting in the group.
!>
!> I did test also on my side and got the same result as Nish's. Here is my
!> code for your reference:
!>
!> Managed C++ Object:
!>
!> using namespace System;
!>
!> namespace MCCL
!> {
!> public __gc class Info
!> {
!> };
!> public __gc class Class1
!> {
!> // TODO: Add your methods for this class here.
!> //public Info* i;
!> public:
!> Info* GetInfo()
!> {
!> Info * i = 0;
!> return i;
!> }
!>
!> };
!> }
!>
!> C# client:
!>
!> static void Main(string[] args)
!> {
!> //
!> // TODO: Add code to start application here
!> //
!> MCCL.Class1 test = new MCCL.Class1 ();
!> if ( test.GetInfo() == null)
!> Console.WriteLine ("We got a NULL");
!> else
!> Console.WriteLine ("We didn't get any NULL");
!> }
!>
!> I could get "We got a NULL" output in the screen.
!>
!> Hope that helps.
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!>
!> --------------------
!> !From: "Peter Hemmingsen" <[email protected]>
!> !Subject: Exposing a "null" dotnet object
!> !Date: Thu, 11 Sep 2003 16:44:06 +0200
!> !Lines: 24
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!> !Message-ID: <[email protected]>
!> !Newsgroups:
!>
!microsoft.public.dotnet.languages.csharp,microsoft.public.dotnet.languages.
v
!> c
!> !NNTP-Posting-Host: heimdal.softco.dk 80.199.79.33
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:28224
!> microsoft.public.dotnet.languages.csharp:184108
!> !X-Tomcat-NG: microsoft.public.dotnet.languages.vc
!> !
!> !Hi,
!> !
!> !I have a dotnet object (implemented in mc++ and used in c#) which have a
!> !property called "Info". The Info property is also a dotnet object
!> !(implemented in mc++). In the constructor of the "main" object I want to
!> !initialize the property "Info" to null in a way that will make the c#
!> !programmer (the user) able to write:
!> !
!> !if (MyObj.Info==null) {..}
!> !
!> !I've tried to initialize the Info property (in mc++) as follows:
!> !
!> !this->Info=0; // Note Info is a __gc class pointer
!> !
!> !but the above c# code always returns false.
!> !
!> !Any suggestions?
!> !
!> !Peter
!> !
!> !
!> !
!> !
!> !
!> !
!>
!
!
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top