|
jschell wrote: I wonder who the idiot was ... Probably someone who's IQ is smaller than his shoe size.
|
|
|
|
|
|
I am confused with RegQueryValueExW and RegQueryValueExA
DWORD sz = 0
LSTATUS status = RegQueryValueExW(key, L"", 0, 0, 0, &sz);
Result:
status : 0
sz : 20
But in
DWORD sz = 0
LSTATUS status = RegQueryValueExA(key, "", 0, 0, 0, &sz);
Result:
status : 0
sz : 10
Why status is ERROR_SUCCESS (0) and sz value is different.
|
|
|
|
|
Because sz is the size of the value in bytes, not characters.
If you retrieve a string from the registry using RegQueryValueExA you get a string with 1-byte ASCII characters, and if you use RegQueryValueExW you get a string with 2-byte Unicode characters.
|
|
|
|
|
Thanks for reply but I am aware about Ansi and Unicode difference.
Here question is little different:
sz value coming different for empty value name which is strange for me.
|
|
|
|
|
What's so strange? The call is telling you the number of bytes needed to hold the value string that would be returned.
For an ASCII string, you need 10 bytes. For the Unicode version, you need 20 bytes. Read the documentation on RegQueryValueExA (ow W):
Quote: A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
The lpcbData parameter can be NULL only if lpData is NULL.
If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes any terminating null character or characters unless the data was stored without them. For more information, see Remarks.
---> If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined. <---
If lpData is NULL, and lpcbData is non-NULL, the function returns ERROR_SUCCESS and stores the size of the data, in bytes, in the variable pointed to by lpcbData. This enables an application to determine the best way to allocate a buffer for the value's data.
If hKey specifies HKEY_PERFORMANCE_DATA and the lpData buffer is not large enough to contain all of the returned data, RegQueryValueEx returns ERROR_MORE_DATA and the value returned through the lpcbData parameter is undefined. This is because the size of the performance data can change from one call to the next. In this case, you must increase the buffer size and call RegQueryValueEx again passing the updated buffer size in the lpcbData parameter. Repeat this until the function succeeds. You need to maintain a separate variable to keep track of the buffer size, because the value returned by lpcbData is unpredictable.
If the lpValueName registry value does not exist, RegQueryValueEx returns ERROR_FILE_NOT_FOUND and the value returned through the lpcbData parameter is undefined.
|
|
|
|
|
Hello Experts,
I just question in mind related to mutex.
We have 2 processes P1 and P2 using some global mutex (m1), P1 is having ownership of mutex m1 and P2 is waiting to release mutex m1 by P1 but somehow P1 got died what will happen to P2 process. Please explain.
|
|
|
|
|
|
Noting from the design or even architecture perspective anytime code is going to be 'waiting' on something else (thread, process, Rest, message, etc) then one should at least consider what would happen if it never happens.
So for example that is why one should consider timeouts. Doesn't mean you should implement that but one needs to at least put some thought into the impact on the application/enterprise if nothing every happens.
|
|
|
|
|
Is there a way to add all the elements of a vector to an integer sequentially?
So...the vector has 1, 2, and 3
The integer is 10
The result should be 11, 12, and 13
As a side note, is there a way to add a repeating number to an integer to infinity?
Example...the integer is 10 and I want to add 4 to it. Then 4 again. And again. And again in a loop
|
|
|
|
|
puckettrobinson675 wrote: is there a way to add a repeating number to an integer to infinity?
Example...the integer is 10 and I want to add 4 to it. Then 4 again. And again. And again in a loop
Yes, just add 4 in the loop. however, not infinitely but until your integer exceeds the possible nax value for its type.
See C and C++ Integer Limits | Microsoft Learn
|
|
|
|
|
Something like:
int number = 10;
std::vector vec = { 1, 2, 3 };
for (int value : vec)
{
std::cout << number + value << std::endl;
}
In the second case you need to add a check that the sum does not overflow beyond the maximum range of the integer.
|
|
|
|
|
Quote: Is there a way to add all the elements of a vector to an integer sequentially? Yes, there are, at least, three different ways:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void dump (vector<int> v)
{
for (auto x :v )
cout << x << " ";
cout << "\n";
}
int main()
{
{ vector<int> v{1,2,3};
int c = 4;
for (size_t n = 0; n<v.size(); ++n)
{
v[n] += c;
}
cout << "method 1: ";
dump(v);
}
{ vector<int> v{1,2,3};
int c = 4;
for (auto & x : v)
{
x += c;
}
cout << "method 2: ";
dump(v);
}
{ vector<int> v{1,2,3};
int c = 4;
transform(v.begin(), v.end(), v.begin(), [=](int x){ return x+c; });
cout << "method 3: ";
dump(v);
}
}
Quote: As a side note, is there a way to add a repeating number to an integer to infinity? Yes, but this way the addition will overflow. Try:
#include <iostream>
using namespace std;
int main()
{
int i = 1;
int last_i;
int c = 4;
for (;;)
{
last_i = i;
i += c;
if ( i < last_i)
break;
}
cout << "unfortunately, (" << last_i << "+" << c << ") makes " << i;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
What is the difference between two images looking the same, if one uses compression and the other one doesn’t. For example we have images made of 12 pixels with all pixels having the same color, except the first three which are different then the rest. If we consider a color depth of 24 bit the bitmap version will have 12*24 bit, 288 bit total. In the compressed image the first 3 pixels will weight 24 bit and the other ones another 24 bit, 48 total. The start and end pixels marking a color sequence need to be considered too, that’s index 0, index 2, index 3 and index 11. Is that correct?
|
|
|
|
|
Probably not - it depends on the compression method.
There are two different types of image compression: lossless and lossy.
PNG for example is lossless - when it is decompressed to a bitmap for display, the bitmap is identical to the original input bitmap data.
JPG is lossy - when it is decompressed the resulting image is lower quality than the original.
You can prove this with any image editor: load a bitmap, save it as a JPG. Open the JPG, save it as a new JPG. Repeat a few times, and watch how the image size drops, the compare the original with the final result. It doesn't take many iterations before the result as very clear to see.
Do the same with a PNG file and the result will be identical to the original.
There is also the problem that any form of compression adds overhead to the resulting file to manage the compression - and small files or those containing a high degree of randomisation can end up bigger than the uncompressed original as a result!
If you really want to know about image compression, Google / Wiki is the place to start: but be warned that the math gets pretty hairy!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Com Automation latest library for working with ms excel in mfc vosual studio vc++, can anyone suggest from where i get this.
|
|
|
|
|
|
- In VS menu Project -> Add New Item ... ->
- In "Add New Item" dialog select MFC in the treeview left, and then choose the "MFC Class From Typelib" and press the Add button
- In the "Add Class From Typelib" dialog choose the source of interface (registry or file), type libraries and then all the needed interfaces.
- then press OK
|
|
|
|
|
Is there any way in Windows to throttle a process' CPU usage?
If so, what's the technique?
EDITED:
I'm asking if one can programmatically throttle a process' CPU usage. Meaning managing the CPU time that a process is allowed to consume.
The difficult we do right away...
...the impossible takes slightly longer.
modified 19-May-23 22:07pm.
|
|
|
|
|
Not that I've ever seen.
Thinking about it, you might be able to kind of simulate it by limiting the cores the process can run on by setting processor affinity for it.
|
|
|
|
|
|
|
A tiny virtual machine.
"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
|
|
|
|
|