PC Review


Reply
Thread Tools Rate Thread

C++ -> C#, checking if object created

 
 
=?Utf-8?B?Sm9uIEU=?=
Guest
Posts: n/a
 
      16th Nov 2007
In C++ I'd have something like :-

-------[C++]-----------
DECLARE_HANDLE(MYHANDLE)

class Fred
{
MYHANDLE m_hHandle ;
etc...
}

Fred::Fred()
{
m_hHandle = NULL ;
}

BOOL Create( void )
{
if( m_hHandle != NULL )
{
ASSERT(false)
}
else
{
m_hHandle = SomeFunction() ;
}
}

-------[C++]-------


I now want to do the equivalent in C# (which I'm relatively new to) but cant
see how to do it. So far I've got

-------[C#]-------
namespace
{
using MYHANDLE IntPtr ;

MYHANDLE MyHandle = [What do I put here? null dont work] ;

bool Create()
{
if( MyHandle != null ) <--- Dont work
{ etc
-------[C#]----------

So how do I do the translation to achieve the same functionality ? (other
than adding a bodgybool to say whether MyHandle has been created or not)

TTFN,
Jon

 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      16th Nov 2007
At a guess, IntPtr.Zero

Of course, it should initialize to zero anyway, but the above may be
handy to *compare* to zero

Marc


 
Reply With Quote
 
=?Utf-8?B?Sm9uIEU=?=
Guest
Posts: n/a
 
      16th Nov 2007


"Marc Gravell" wrote:

> At a guess, IntPtr.Zero


Ah ha, thanks ! Still a .NET newbie ... just clicked that even simple
variables are objects.

TTFN,
Jon
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Object Events for Object you Created Graham Mandeno Microsoft Access Form Coding 3 30th Nov 2009 11:05 PM
Object cannot be created at this URL because an object named by thisURL already exists Dhananjay Microsoft Dot NET 0 11th Jan 2008 01:42 PM
Spell Checking Documents created by custom Templates =?Utf-8?B?R3JlbWxpbiBTdGV2ZQ==?= Microsoft Word Document Management 3 11th Apr 2006 09:25 AM
'Object reference not set to an instance of an object.' when checking string length? darrel Microsoft ASP .NET 7 22nd Mar 2006 11:13 PM
how can i execute a delegate on the thread that created the object ? (object that is not control ) Gaurav Vaish Microsoft C# .NET 3 12th Jun 2005 10:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 AM.