Need help with 2d array

Started by
5 comments, last by magnanimousness 14 years, 1 month ago
Hey Guys, I have this function that takes in a 2d array of wchar_t's and places the strings within into a listbox. The function is basically AddStringsToList(HWND hWnd, wchar_t wcStringList[][MAXPATH], int ListBox, int nCount). Now up until about 3 hours ago it worked fine and I dont remember changing anything, but now it no longer works. Normally I would send in a 2d array of wchar_ts which looked pretty much like this: [0][Image1.bmp] [1][Image2.bmp] [2][Image3.bmp] [3][Image4.bmp] [4][Image5.bmp] everything would be a okay and it would add those strings to the list. Now however, when I send the array into the function it becomes [0] [1][m] [2][a] [3][g] [4][e] [5][.] [6] [7][m] [8]

So instead of the function working on the array I showed you first, it now works on an array like the one directly above. And this is with no intervening code, this transformation occurs as the array is sent into the function. I am at a complete loss as to why its doing this, because, I dont remember changing anything. It goes in normal, but comes out the other side all messed up. Anybody got any ideas? Your help is appreciated. Thanks

Advertisement
Can you provide a code snippet of the relevant parts? It's hard to determine the cause with just that information.
So I'm clear, you create the array you have:

[0][Image1.bmp]
[1][Image2.bmp]
[2][Image3.bmp]
[3][Image4.bmp]
[4][Image5.bmp]

Did you print and verify that it is initialized correctly before you passed it in?

Then you pass it to the method, and before anything happens in the method you get:

[0]
[1][m]
[2][a]
[3][g]
[4][e]
[5][.]
[6]
[7][m]
[8]



and did you print and verify that this is the output before you do anything with it in the method?

Outside of that code snippets are probably needed.

Have you stepped through the code using the debugger to see what happens?
Quote:Original post by magnanimousness
Anybody got any ideas?

Somewhere you've got a * that doesn't belong there.
Hey,

Yeah I've used the debugger and the string array I send into the function is fine,

When the debugger steps into the function however, its messed up:

Okay, heres the actual function:

void AddStringsToList(HWND hWnd, wchar_t wcStrings[][MAX_PATH] , int iList, int nStringCount){		HWND c_hWnd = GetDlgItem(hWnd, iList); //get the handle for the list we're gonna update	//iterate through each string and add it to the list	for(int i = 0; i < nStringCount; i++)	{		SendMessage(c_hWnd, LB_ADDSTRING, 0, (LPARAM)wcStrings);	}		}


I would then send in this array:

wchar_t wcStringList[64][MAX_PATH];


which first went through a function that goes through a FILEOPENNAME struct and retrieves the list of files opened.

I then call the function and pass it in as the string:

//Gets the list of files opened and places it into the 2d arraynNumFiles = GetFileNamesFromDlg(FileDialog, wcStringList); //this works fine, I've checked with the debugger, it comes out as an array of strings//heres where the problem lies, the wcStringList goes in okay, but arrives into the function all messed upAddStringsToList(DlghWnd, wcStringList, IDC_NORTHLIST, nNumFiles);


I hope this gives some clarity, thanks for the responses.

cheers
Anybody? Anybody got any ideas? Its like its got a mind of its own... :(

This topic is closed to new replies.

Advertisement