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

G

Guest

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
 
M

Marc Gravell

At a guess, IntPtr.Zero

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

Marc
 

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