how to use 'null' keyword when calling c# dlls in c++ projects?

  • Thread starter Thread starter Vivienne
  • Start date Start date
V

Vivienne

hi,

I am using visual studio for my c++ project, and have to call a c#
dll. now I met a problem when a methed in c# dll returns null, I
don't know how to use 'null' in c++.

To make it simple, I write a simple example to make my problem clear.
Below is a class A(implemented in c#), the method will return null in
some conditions.

class A{
bool flag;
System::String s;
public System::String getNext(){
if(flag == true)
return s;
else return null;
}
}

in the c++ project , I just want to use the class,like this
A^ a = gcnew A();
if((a->getNext()) != null) //here is the problem, the 'null'
keyword is not defined in c++,
// if I try to use NULL instead
of null, an conversion error will occur.

so, what should I do here?

Thanks!
 
Vivienne said:
hi,

I am using visual studio for my c++ project, and have to call a c#
dll. now I met a problem when a methed in c# dll returns null, I
don't know how to use 'null' in c++.

Try "nullptr" instead.
 

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

Back
Top