473,729 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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==nu ll) {..}

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 2761
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 ConsoleApplicat ion4
{
class Class2
{
[STAThread]
static void Main(string[] args)
{
Class1 c1 = new Class1();
Console.WriteLi ne(c1.GetObj() == null);
}
}
}

The output is :-

True

--
Regards,
Nish [VC++ MVP]

"Peter Hemmingsen" <ph*@softco.d k> wrote in message
news:Oz******** ******@TK2MSFTN GP12.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==nu ll) {..}

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.WriteLi ne ("We got a NULL");
else
Console.WriteLi ne ("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.d k>
!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.publi c.dotnet.langua ges.csharp,micr osoft.public.do tnet.languages. v
c
!NNTP-Posting-Host: heimdal.softco. dk 80.199.79.33
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28224
microsoft.publi c.dotnet.langua ges.csharp:1841 08
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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==nu ll) {..}
!
!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******** ******@cpmsftng xa06.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.WriteLi ne ("We got a NULL");
else
Console.WriteLi ne ("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.d k>
!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.publi c.dotnet.langua ges.csharp,micr osoft.public.do tnet.languages. v c
!NNTP-Posting-Host: heimdal.softco. dk 80.199.79.33
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28224
microsoft.publi c.dotnet.langua ges.csharp:1841 08
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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==nu ll) {..}
!
!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.d k>
!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.publi c.dotnet.langua ges.vc
!NNTP-Posting-Host: heimdal.softco. dk 80.199.79.33
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28247
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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******* *******@cpmsftn gxa06.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.WriteLi ne ("We got a NULL");
!> else
!> Console.WriteLi ne ("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.d k>
!> !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.publ ic.dotnet.langu ages.csharp,mic rosoft.public.d otnet.languages .
v
!> c
!> !NNTP-Posting-Host: heimdal.softco. dk 80.199.79.33
!> !Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!> !Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28224
!> microsoft.publi c.dotnet.langua ges.csharp:1841 08
!> !X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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==nu ll) {..}
!> !
!> !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
20371
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 , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference object. I suppose i could return a pointer instead, but i have some code written with references which...
13
3084
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 across "null" string. I know that I will get an "undefined" when I try to retrieve something from the DOM which doesn't exist. I have used null myself to initialize or reset variables. But in which
1
3180
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 anywhere or noted this tiny yet curious change in SP2.. so here it is: In IE6 SP2 rows must be inserted into a tBody instead of a Table directly, after that you may insert TDs into TRs any way you wish. insertRow() and insertCell() work the same as...
13
3108
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" automatically after programs do "delete p"?
2
1733
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 "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) {..}
14
3166
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 it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void SomeFunc() { MyClass c = new MyClass();
2
2892
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
1916
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 object with the following code: theSQL.Append(" , myvar = " & FormatValue(MyClass.DB_CHAR1, Me.MyVar))
2
3098
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 transactionStatement; import javax.xml.transform.TransformerFactory; import javax.servlet.*; import org.jdom.*; import java.io.ByteArrayOutputStream; import java.io.File;
0
8917
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.