|
|
Hi,
The current Microsoft version of the Win32 documentation says that LoadString, LoadStringW, and LoadStringA will pass back a pointer to a read-only copy of a string resource, if the buffer size passed to the routine is 0. In which universe does this happen? This is what I see:
LoadString(hModule, valid_string_id, buf, buflen) returns length of string
LoadString(hModule, invalid_string_id, buf, buflen) returns 0
LoadString(hModule, valid_string_id, buf, 0) returns -1
LoadString(hModule, valid_string_id, NULL, buflen) throws an exception
LoadString(hModule, valid_string_id, NULL, 0) throws an exception
I always look at the source code of Wine when I encounter stuff like this, as a first approximation of what might actually be going on internally, and it would appear that Wine would do the same, except for the last case where it would return -1.
I can work around this, no problem. The question is more about the mismatch between the documentation and the behavior. Does anyone have any insight on this?
sample code below. You need to attach a resource file with a valid string defined
#include <windows.h>
#include <stdio.h>
#include "test.h"
#define ARRAYLENGTH(a) (sizeof(a)/sizeof((a)[0]))
int main (int argc, char **argv)
{
char buf[300];
int len;
HMODULE hModule = GetModuleHandle(NULL);
#define TEST_FUNC_CALL(expression) \
buf[0] = '?'; \
buf[1] = 0; \
printf("%s\n", #expression); \
__try { \
len = expression; \
printf("... returned %d; buf: %s\n\n", len, buf); \
} \
__except(EXCEPTION_EXECUTE_HANDLER) { \
printf("... threw an exception\n\n"); \
}
TEST_FUNC_CALL( LoadString(hModule, IDS_STRING1, buf, ARRAYLENGTH(buf)) )
TEST_FUNC_CALL( LoadString(hModule, 9999, buf, ARRAYLENGTH(buf)) )
TEST_FUNC_CALL( LoadString(hModule, IDS_STRING1, buf, 0) )
TEST_FUNC_CALL( LoadString(hModule, IDS_STRING1, NULL, ARRAYLENGTH(buf)) )
TEST_FUNC_CALL( LoadString(hModule, IDS_STRING1, NULL, 0) )
return 0;
}
|
|
|
|
|
I just tried that and it does indeed return the length of the string, and set the buffer address to point to the string itself. In your call with a buffer length of zero, you need to pass the address of a pointer, where Windows will store the address of the string. Something like:
char* pString;
TEST_FUNC_CALL( LoadString(hModule, IDS_STRING1, (char*)&pString, 0) )
|
|
|
|
|
So the documentation is wrong. For example it doesn't document '-1' at all.
You might get some more information by doing what it says....
"To get extended error information, call GetLastError."
|
|
|
|
|
Solved: receiving a pointer to the string when cchBufferMax == 0 happens in the Unicode universe (LoadStringW), not the MBCS universe (LoadStringA). Duh! Of course. String resource data is Unicode. If I'd looked at Wine's LoadStringW instead of LoadStringA I'd have seen that yesterday.
(And in case anyone stumbles on this discussion for info about this feature, note that the string in the resource is likely not null terminated.).
I'll post feedback for the documentation. It was an error that the same copy got pasted into both LoadString descriptions. LoadStringA needs to have the part about cchBufferMax == 0 deleted. The -1 return value should also be documented. (Also, LoadStringW does not throw exceptions with a NULL buffer pointer, it returns 0, but that doesn't need to be documented.)
|
|
|
|
|
Every time I need to change or correct something in my old Web.net site, Visual Studio has been updated without looking back. Code that ran in 2017, 2019 worked, bud now i 2022 it does not work.
What is wrong with Microsoft? Thinking it is all AI and new programme languages. Just stick to VB and C# and forget the rest.
|
|
|
|
|
This forum is for problems with this website. If you have a programming problem then use one of the actual code forums or https://www.codeproject.com/Questions/ask.aspx[^]. If you just want to rant about Microsoft then try the Lounge.
modified 21-Feb-23 8:59am.
|
|
|
|
|
Not sure this is the right section to ask but none seemed perfect. I've been having an issue for several months that no one in IT can explain so maybe a software devs take could shed some light. We have a VPN tunnel that we use to access file shares located on the network of the software vendor who's accounting software we use. I use and have ben using for several years IDM Comp's UltraEdit Studio as my text editor. Starting a few months back when I go to FILE//OPEN, select the File Share that's on the other side of teh VPN Tunnel within a few seconds I get locked out from accessing not only from within the text editor but also with Windows Explorer. If I use window explorer to locate a file and then open it I'm fine it's only when starting from the text editor I get locked out after trying to browse to a file. Once the lockout happens I can't use Windows Explorer either to access any of teh files on teh share until the lock is released. The software vendor's people say it's nothing they've done and yet this was not an issue until a few months ago. Initially there was like a 1 in 10 chance I'd get locked out trying to browse to and open a file and then it got worse and worse until now it's %100. Initially I thought maybe it was something with Ultra Edit Studio but I switched to using regular old Notepad and the same thing happened so it's not a problem just with Ultra Edit Studio.
I feel like something must be happening in the back ground any time I'm using an apps FILE>>OPEN feature to browse to and select a file, something that the security on teh other side of teh VPN is detecting as a malicious attack and thus temporarily locking out the account.
Have any of you ever run into something like this or have any thoughts?
|
|
|
|
|
Never heard of the problem.
I think this is going to be a call to Microsoft Support. There may have been a patch that did it or the VPN was updated and something in there is screwing with the network connection.
|
|
|
|
|
We've discussed possibly having to do just that. I was hoping that if it was something MS did that one or more of you devs out there would have run into it by now as well and have some insight on what it is.
Thanks
|
|
|
|
|
Sounds like you're trying to open "vendor files" (for WRITE?) on THEIR network. As a vendor, I would only allow downloads ... which doesn't include trying to open them with Notepad, etc.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Yes for read write but I can do that fine now as long as I don't go to FILE>>OPEN from within the app (any text editor) but instead browse to the file and select it in Windows Explorer and double-click (or right click and select open).
Thanks for the reply
|
|
|
|
|
That doesn't really make sense. When you double-click a file in Explorer, it looks up the file extension in its handler table and just launches the command line associated with the extension.
So, by default, for .TXT file you double-click, Explorer will launch Notepad.exe %1, and replace the %1 with the full path to the file you double-clicked. The app then has to open the file itself and will do it exactly like it would if you went to File/Open in the application and selected it.
|
|
|
|
|
I know. Very bizarre. Initially I thought it was something the text editor (UE Studio) was doing in teh background like perhaps some kind of scanning to spepd up file access but once I tried in Notepad I realized it wasn't the app.
|
|
|
|
|
Last I checked, Notepad only opened files for Shared Read access. It only opened for Write when saving.
|
|
|
|
|
I agree; but what is actually happening from the VPN's point of view? I'm not sure of what's being run from where; or if the "host" has changed access rules.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
How do I get a list of all the libraries, include files, etc. that make up the build of a C program in Visual Studio 2022 or earlier? i.e. the components need to compile and link a C program for execution.
"A little time, a little trouble, your better day"
Badfinger
modified 10-Dec-22 0:47am.
|
|
|
|
|
|
Wouldn't the vs project file tell you that? (Unload it, then "Edit project file")
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Unload what? edit what? Not options in VS I can find.
Visual Studio is not my IDE of choice. I use CodeBlocks with C. It's much more traditional and straight forward. VS is a nightmare made by too many cooks. Trying to satisfy with too many options. They have taken their eye off the ball. For example, there is not one single command to run a program other than the less than obvious F5. Instead it's select debug, select start debugging. Using VS is trying to solve a problem of writing code with a extra problem of wrestling with VS to write code. Guess I am getting too old. Thanx for the advice. I asked for it.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
You right-click the Project in Solution Explorer and click "Unload Project". That will allow you to open the .proj file in Visual Studio and take a look inside.
Funny how I don't have a problem with "wrestling with Visual Studio" when I write code. To each their own I guess.
modified 11-Dec-22 14:03pm.
|
|
|
|
|
truly said. Got it. Thanx
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
You mean the vxc.proj file? VS has too many working file types. there is
vxc.proj
.vcproj.user
.ncb
.snl
why not just program_name.main
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
jmaida wrote: why not just Because all these files have specific roles to play, and rather than one enormous text file which would be a nightmare to mange, each one can be individually managed easily. And yes, I agree it is difficult to understand when you first start, but like all things in life, you need to learn and practice. If you have a system that you prefer to work with that is fine, we all have our own favourites.
|
|
|
|
|
Hi,
I want to point the double-click handler for .dll files to my program instead of the default handler. There arise some questions:
1. can it do any harm? dll’s being system files.
2. How do I keep the option of calling the default handler from my program?
3. I tried the Microsoft docs but the documentation is very long and confused. I’ll be grateful for a pointer to a concise documentation of registry file associations, maybe some examples.
Many thanks.
alex
'Architecture is music frozen in space.'
|
|
|
|
|