C++/CLI -- what about NULL?

Posted on 2009-05-08
Medium Priority
Last Modified: 2012-05-06
Some of the code I'm upgrading to C++/CLI (.Net 2+) from Managed Extensions for C++ (.Net 1.1) compares an object to NULL or 0 to determine whether it's a null pointer.

But I'm getting a compile error on these lines.  
Cannot convert from 'int' to 'System::Drawing::Bitmap^'

Below is one of the functions in which I use the technique and get the error ... about 3 spots in this one.

What is the C++/CLI way to do this?

Bitmap ^ MyClass::LoadBMP(String ^fileName) {
		if(fileName == NULL || fileName == String::Empty) {                  // Make Sure A Filename Was Given
			return NULL;                                                    // If Not Return Null
		// Make Sure The File Exists In One Of The Usual Directories
		if(!File::Exists(fileName)) {
			return NULL;                                                    // If Not Return Null
		if(File::Exists(fileName)) {                                         // Does The File Exist Here?
			return gcnew Bitmap(fileName);                                    // Load The Bitmap

Open in new window

Question by:Daniel Wilson
  • 3
  • 2
LVL 40

Accepted Solution

evilrix earned 1600 total points
ID: 24341069
Isn't the managed code version of NULL nullptr (or maybe just null) in managed C++?

Assisted Solution

Gregdo earned 400 total points
ID: 24341103
Yes, the managed version of NULL is nullptr.
LVL 32

Author Comment

by:Daniel Wilson
ID: 24341111
nullptr did it.  Thanks!
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

LVL 40

Expert Comment

ID: 24341128
Thanks Gredo, I couldn't remember if it was null or nullptr. The problem is that microsoft have screwed up a bit here because as from C++0X nullptr will be the unmanaged C++ null pointer type :)

Expert Comment

ID: 24341161
Ah, yes, I recall reading that nullptr will be replacing NULL.  I wonder if this will force MS to make a change!
LVL 40

Expert Comment

ID: 24341190
>>  I wonder if this will force MS to make a change!
I hope so


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question