Array size question

Started by
1 comment, last by CoolTomK 22 years, 7 months ago
I have an array of chars that I filled when I loaded a resource in my executable by using lockresource. In order for my program to work correctly I must find out the size of that array. But when I use sizeof() I dont get the full size of my array but rather a much smaller number. I think this is because my array contains NULL characters and sizeof() thinks that this is the end of the array because sizeof says the array is 4 bytes long which is exactly where the first NULL character is. If I am right about whats causing my problem can somebody tell me how to find the size of an array with NULL chars in it? Heres the code to clear things up (pResData is a pointer to a BYTE):
    
	hResource = LoadResource(NULL, FindResource(NULL, ResourceName, ResourceType));

	pResData = (BYTE *)LockResource(hResource);
	UnlockResource(hResource);

	if(pResData == NULL)
	{
		bError = true;
		return ERR_RESLOAD;
	}
	int sizearr = sizeof(pResData);
    
Edited by - cooltomk on September 14, 2001 8:37:04 PM
Advertisement
Unfortunately, sizeof() is giving you the size of a pointer (which is 4 bytes in Windows) and not the size of your array. You can''t get the size of an array with sizeof unless the array has been statically allocated. (ie. you said array[50] instead of using ''new'' or something similar)

Is there some sort of resource function you can use to get more data about the resource? Because sizeof() won''t work for you here.
sizeof only returns the amount of memory that a variable occupies. For pResData this is 4 bytes, because on the x86 architecture, 4 bytes are allocated for a pointer.

To get the size of the resource, you need to use the SizeofResource function. See the documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/resource_38yt.asp on how to use it.

HTH

This topic is closed to new replies.

Advertisement