Sign in to follow this  

Need help with 2d array

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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][I] [1][m] [2][a] [3][g] [4][e] [5][.] [6][b] [7][m] [8][p] 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

Share this post


Link to post
Share on other sites
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][I]
[1][m]
[2][a]
[3][g]
[4][e]
[5][.]
[6][b]
[7][m]
[8][p]

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.

Share this post


Link to post
Share on other sites
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]);

}

}




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 array
nNumFiles = 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 up
AddStringsToList(DlghWnd, wcStringList, IDC_NORTHLIST, nNumFiles);




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

cheers

Share this post


Link to post
Share on other sites

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this