472,988 Members | 3,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

Exposing a "null" dotnet object

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

Nov 16 '05 #1
4 2700
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

--
Regards,
Nish [VC++ MVP]

"Peter Hemmingsen" <ph*@softco.dk> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
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


Nov 16 '05 #2
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" <ph*@softco.dk>
!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: <Oz**************@TK2MSFTNGP12.phx.gbl>
!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!TK2MSFTN GP12.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
!
!
!
!
!
!

Nov 16 '05 #3
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

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> wrote in message
news:Fh**************@cpmsftngxa06.phx.gbl...
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" <ph*@softco.dk>
!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: <Oz**************@TK2MSFTNGP12.phx.gbl>
!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!TK2MSFTN GP12.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
!
!
!
!
!
!

Nov 16 '05 #4
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" <ph*@softco.dk>
!References: <Oz**************@TK2MSFTNGP12.phx.gbl>
<Fh**************@cpmsftngxa06.phx.gbl>
!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: <e3**************@TK2MSFTNGP09.phx.gbl>
!Newsgroups: microsoft.public.dotnet.languages.vc
!NNTP-Posting-Host: heimdal.softco.dk 80.199.79.33
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
!
!"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> wrote in message
!news:Fh**************@cpmsftngxa06.phx.gbl...
!> 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" <ph*@softco.dk>
!> !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: <Oz**************@TK2MSFTNGP12.phx.gbl>
!> !Newsgroups:
!>
!microsoft.public.dotnet.languages.csharp,microsof t.public.dotnet.languages.
v
!> c
!> !NNTP-Posting-Host: heimdal.softco.dk 80.199.79.33
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
!> !
!> !
!> !
!> !
!> !
!> !
!>
!
!
!

Nov 16 '05 #5

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

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
1
by: putty | last post by:
I found a few posts of people asking about insertCell()/insertRow() not working in IE6 SP2, and a few others about getting "null is null or not an object" errors, but no one posted a solution...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
2
by: Peter Hemmingsen | last post by:
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...
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
2
by: Anastasios Papadopoulos | last post by:
Hello all, I have statements like the following in my Property Get: Public Property AccountNumber() As String Get Return MyClass.AccountNumber.ToString End Get blah blah End Property
5
by: rengeek33 | last post by:
I am building a SQL statement for Oracle and need one part of it to read: , myvar = null, myvar2 = "1", myvar3 = "0", myvar4 = null, etc. I am constructing this string using the String...
2
by: crabsdf | last post by:
My project is a single method class which takes a xml object and, using Apache FOP, transforms it into a PDF which is returned as an output stream. Here is full code package...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.