A
a_unique_name
Guest
Hi Folks:
Developing on Windows 10 Pro, Visual Studio 2017 Community, Win32 no MFC.
TL;DR How do I retrieve the text associated with a string table's element directly from the string resource, by passing LoadString() a max buffer size of 0?
As I interpret the LoadString() documentation, passing LoadString() a maximum buffer length of zero offers me a pointer to the string class, which includes the text. This will free my code from the task of copying the string into memory, then freeing that memory when the text is no longer needed.
I've been passing buffers and buffer lengths to LoadString() and then freeing the buffers when no longer needed.
Passing a buffer size of zero to LoadString() returns a pointer to a string resource, and buried in that resource is the text through a pointer to the string resource.
What I'm not finding is documentation describing what that resource looks like, so I can access that text.
I'm using UTF8, rather than UTF16.
The following code fragment results in test_text_ptr pointing to the text associated with the string resource.
1 char test_buffer[DEFAULT_STRING_RESOURCE_TO_UNICODE_BUFFER_SIZE];
2 char *read_only_text_ptrx = NULL;
3 char read_only_text_ptr[8];
4 memset(read_only_text_ptr, 0x00, sizeof read_only_text_ptr);
5
6 int test_loadstring_return =
7 LoadString(hInstance, resource_id, test_buffer, <===== Unrelated call to LoadString()
8 DEFAULT_STRING_RESOURCE_TO_UNICODE_BUFFER_SIZE); This call is successfull
9
10 int test_loadstring_return_3 =
11 LoadString(hInstance, resource_id, read_only_text_ptr, 0);
12
13 int text_length = strlen(read_only_text_ptr);
14
15 const char *test_text_ptr = read_only_text_ptr + 28; <=========== Text is retrieved here.
However, test_loadstring_return_3 is -1, text_length is 0 and an exception is thrown when the function exits with the following error:
Run-Time Check Failure #2 - Stack around the variable 'read_only_text_ptr' was corrupted.
If I comment out the first call to LoadString(), which makes no reference to the text buffer in the second LoadString() call, test_text_ptr no longer references the text in the specified string resource.
How do I make this happen?
What am I missing?
Thanks
Larry
Continue reading...
Developing on Windows 10 Pro, Visual Studio 2017 Community, Win32 no MFC.
TL;DR How do I retrieve the text associated with a string table's element directly from the string resource, by passing LoadString() a max buffer size of 0?
As I interpret the LoadString() documentation, passing LoadString() a maximum buffer length of zero offers me a pointer to the string class, which includes the text. This will free my code from the task of copying the string into memory, then freeing that memory when the text is no longer needed.
I've been passing buffers and buffer lengths to LoadString() and then freeing the buffers when no longer needed.
Passing a buffer size of zero to LoadString() returns a pointer to a string resource, and buried in that resource is the text through a pointer to the string resource.
What I'm not finding is documentation describing what that resource looks like, so I can access that text.
I'm using UTF8, rather than UTF16.
The following code fragment results in test_text_ptr pointing to the text associated with the string resource.
1 char test_buffer[DEFAULT_STRING_RESOURCE_TO_UNICODE_BUFFER_SIZE];
2 char *read_only_text_ptrx = NULL;
3 char read_only_text_ptr[8];
4 memset(read_only_text_ptr, 0x00, sizeof read_only_text_ptr);
5
6 int test_loadstring_return =
7 LoadString(hInstance, resource_id, test_buffer, <===== Unrelated call to LoadString()
8 DEFAULT_STRING_RESOURCE_TO_UNICODE_BUFFER_SIZE); This call is successfull
9
10 int test_loadstring_return_3 =
11 LoadString(hInstance, resource_id, read_only_text_ptr, 0);
12
13 int text_length = strlen(read_only_text_ptr);
14
15 const char *test_text_ptr = read_only_text_ptr + 28; <=========== Text is retrieved here.
However, test_loadstring_return_3 is -1, text_length is 0 and an exception is thrown when the function exits with the following error:
Run-Time Check Failure #2 - Stack around the variable 'read_only_text_ptr' was corrupted.
If I comment out the first call to LoadString(), which makes no reference to the text buffer in the second LoadString() call, test_text_ptr no longer references the text in the specified string resource.
How do I make this happen?
What am I missing?
Thanks
Larry
Continue reading...