Jump to content
  • Advertisement
Sign in to follow this  
magnanimousness

Need help with 2d array

This topic is 3210 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] [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

Share this post


Link to post
Share on other sites
Advertisement
Can you provide a code snippet of the relevant parts? It's hard to determine the cause with just that information.

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]
[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.

Share this post


Link to post
Share on other sites
Have you stepped through the code using the debugger to see what happens?

Share this post


Link to post
Share on other sites
Quote:
Original post by magnanimousness
Anybody got any ideas?

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

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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!