Object reference not set ..Error

A

Aby

hi all,
i need to send a String array from C# to a managed c++ dll
function.
Managed dll mthd --

void Managed::printNames( String* a_arStrNames[])
{
}

C# app calling dll fun --

string[] arStrNames= { "MS", "HI", "HELLO" };
Managed m = new Managed();
m.printNames ( arStrNames );


This fails at runtime on the call to 'printNames' , saying
'Object reference not set to an instance of an object.'

What is the probelm here. Plz help .....

thanks,
abin
 
V

Vadym Stetsyak

Hello, Aby!

A> void Managed::printNames( String* a_arStrNames[])
A> {
A> }

A> C# app calling dll fun --

A> string[] arStrNames= { "MS", "HI", "HELLO" };
A> Managed m = new Managed();
A> m.printNames ( arStrNames );

A> This fails at runtime on the call to 'printNames' , saying
A> 'Object reference not set to an instance of an object.'

What code is in the printNames method?

IIRC, to be MC++ printNames has to look like
void Managed::printNames( String^ a_arStrNames[])
{
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
W

Willy Denoyette [MVP]

Hard to tell, unless you post a comple sample.
Are you sure it's M.printNames who fails? Hard to believe, arStrNames is a
valid reference and m should be valid too.

Willy.

| hi all,
| i need to send a String array from C# to a managed c++ dll
| function.
| Managed dll mthd --
|
| void Managed::printNames( String* a_arStrNames[])
| {
| }
|
| C# app calling dll fun --
|
| string[] arStrNames= { "MS", "HI", "HELLO" };
| Managed m = new Managed();
| m.printNames ( arStrNames );
|
|
| This fails at runtime on the call to 'printNames' , saying
| 'Object reference not set to an instance of an object.'
|
| What is the probelm here. Plz help .....
|
| thanks,
| abin
|
 
A

Aby

hi Stetsyak
i am not using C++/CLI. (still uses /clr:blush:ldSyntax). The code in
more detail
--> The managed assembly is as follows and beleive me there is nothing
other than a MessageBox in the printNames function.

#pragma once
using namespace System::Collections;

namespace FE_API
{
public __gc class Managed
{
void Managed::printNames( String* a_arStrNames[])
{
MessageBox(0, "Inside FE_API", "FE_API",0);
}
};
}

--> The calling C# program

using FE_API;

private void test_btn_Click(object sender, EventArgs e)
{
string[] arStrNames= { "MS", "HI", "HELLO" };
Managed m = new Managed();
m.printNames ( arStrNames );
}


thanks,
abin
 
A

Aby

sorry guys,
it was a mistake from me. Initialising 'm' was not done properly.
(it was done somewhere else ). Now everything is ok. very sorry for
wasting ur time.

regards,
abin
 

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