Solved

C++/CLI -- what about NULL?

Posted on 2009-05-08
6
1,161 Views
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?

Thanks!
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

0
Comment
Question by:Daniel Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

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

Assisted Solution

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

Author Comment

by:Daniel Wilson
ID: 24341111
nullptr did it.  Thanks!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:evilrix
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 :)
0
 
LVL 2

Expert Comment

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

Expert Comment

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

http://en.wikipedia.org/wiki/C%2B%2B0x#Null_pointer_constant
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unresolved External Symbols 3 129
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 251
Issues with C++ Class 19 107
show out valin of json for debugging in visaul c++ 1 47
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

749 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