473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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

Nov 16 '07 #1
2 1403
At a guess, IntPtr.Zero

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

Marc
Nov 16 '07 #2


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

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

Similar topics

1
by: aurora | last post by:
Sometimes I find it useful to create an instance of some dummy class so that I can bind abitrary attributes to it. I sometimes prefer this to mapping object. >>> class A: pass .... >>> a =...
0
by: Wolfgang Schwanke | last post by:
Dear usenet, I'm having the following small problem. I've been ask to add some Quicktime panoramas to a website. The author of the panoramas has made two versions of each: One in MOV format,...
5
by: Hongzheng Wang | last post by:
Hi, If I have such codes: class fred { //user defined constructors/destructor here }; int main() {
6
by: Daniel Bass | last post by:
The scenario: ------------- I've created a simple COM object according to a tutorial I found: http://www.csharphelp.com/archives/archive281.html It automatically creates a Type Library...
7
by: John Ruiz | last post by:
the constructor definition in my Global.asax.cs file contains (among other things) the following line: System.Diagnostics.Debug.WriteLine( "Global Constructor ran." ); when I run my web...
6
by: andrea | last post by:
I want to setup properties value to an object created by reference. I do the following. T t = Activator.CreateInstance<T>(); Type newItem = typeof(T);...
6
by: Pablo | last post by:
Hello, I am writing a windows application using C++ and BorlandBuilder 6 compiler. It is an event driven program and I need to create objects of some classes written by me. One of the classes...
4
by: msnews.microsoft.com | last post by:
hello every one i am using media player in internet explorer but i cannot access it directly in code behind, so do you know a way to access it? <object id="video123"...
3
by: thulaseeram | last post by:
Hi, How to find out, the number of objects created to a particular class. Thanks, Ram
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.