views:

47

answers:

1
public value struct ListOfWindows
{
 HWND hWindow;
 int winID;
 String^ capName;
};

thats my structure now i have created an array of them:

array<ListOfWindows ^> ^ MyArray =  gcnew array<ListOfWindows ^>(5);

now to test if that works i made a simple function:

void AddStruct( )
{
  HWND temp = ::FindWindow( NULL, "Test" );
  if( temp == NULL ) return;
  MyArray[0]->hWindow = temp; // debug time error..

  return;
}

ERROR: An unhandled exception of type 'System.NullReferenceException' occurred in Window.exe

Additional information: Object reference not set to an instance of an object.

dont know what to do.. kinda new to CLI so if you can help please do.. Thanks.

A: 

Well, you have an array of references to objects but I don't see any code that actually puts an object into any of them. Before accessing MyArray[0] you might want to put an object into the array at position 0.

I would change ListOfWindows to be a ref class - in your context it doesn't make much sense to use it as a value class - and then you can add an object to the array like this:

MyArray[0] = gcnew ListOfWindows;

(Untested but that's more or less how it should work). Once you've actually added that object you can then interact with it.

Timo Geusch
what do you mean by puting an objent into the array like this?MyArray[0] = gcnew ListOfWindows^;??
Nitroglycerin
@Nitroglycerin - see above expanded answer.
Timo Geusch