|
Sorry, I can't diagnose what happens on your computer.
(And whatever you are doing elsewhere is pointless and bad practice. Errors in your code have been identified. Just check the windows version and end it there.
To clarify: DON'T check the versions of system DLLs. There are multiple versions of many DLLs and you have no idea which DLL is actually being used.)
modified 26-Jul-18 23:55pm.
|
|
|
|
|
But you can tell the studio whichone too look for or use, I think.
|
|
|
|
|
Thank you very much I got the idea now, 100000 of thanks.
|
|
|
|
|
wsprintf is not the issue, it is how you are extracting the numbers from the version structure. Check the version documentation again.
|
|
|
|
|
I have a class PackageSingleton and got a function getPackage whose return type is another class Package. This function iterates over a queue and retrieves a package and executes it. If a queue is empty i want to return nothing and keep looping the queue until a package is found. In C++ NULL cant be returned and returning a nullptr is giving an error
no viable conversion from returned value of type 'nullptr_t' to function return type 'Package . Any idea how should i handle this situation.
c++
modified 26-Jul-18 6:58am.
|
|
|
|
|
You can only return a nullptr if the defined return type is a pointer to something. If the return type is some sort of object then you must return an actual object of that type. You could solve this by changing the function to return a pointer to the relevant Package object.
|
|
|
|
|
If we didn't define the return type a pointer then how we will get nullptr. I have so far used char, int return type from Bitdefender Error 1020
what is the relevant package for returning pointer type?
modified 27-Jul-18 17:49pm.
|
|
|
|
|
I don't understand what you are saying. If the return type of your getPackage function is a Package object, then that is what you must return. If the function fails then you must find some other way to signal that failure, perhaps by throwing an exception. If you want the possibility of returning nullptr to indicate failure, then the function must return a pointer to a Package object, thus:
Package* getPackage()
{
Package* pPackage;
pPackage = new Package();
if (some problem with creating the object)
pPackage = nullptr;
return pPackage;
}
|
|
|
|
|
The common solution is to return an empty object. But this requires that the class supports such (usually by the default constructor without arguments creating such an empty object and providing a member function that checks for the object being empty).
An example is the std::string class:
std::string somefunc()
{
std::string str();
return str;
}
std::string str = somefunc();
if (!str.empty())
{
}
|
|
|
|
|
If you are using C++17, there is std::optional designed just for this situation. You could return a raw pointer (assuming the collection outlives the use of its objects), a unique_ptr (construct a new object) or shared_ptr (and store the Packages as shared_ptr objects).
Another option is to pass a non-const reference to a Package and have the method return a bool indicating success or failure.
As has been pointed out, you could also return an empty object. This is the only choice if your design is constrained to return just an instance.
|
|
|
|
|
I trying to get the Version of the ComCtl32.dll library, according to what I had read
the version number for the ony on System 32 is 5.82 for legacy.
This is the code I have created, and cant get any close to that, you will see extra
lines of code for testing purposes, I maybe not even doing right the creation of the
string for the dialog box, check it out please teach me /give some tips why I get wrong values.
The Code ( Noticed the return 1 or 0 in case of no or errors ) and 1000 of thanks in advance.
char NFILE[255]; DWORD dwSize, dwHandle = 0; VS_FIXEDFILEINFO * pvi;
// Set the Path and file name
strcpy(NFILE,"C:\\Windows\\System32\\ComCtl32.dll");
MessageBox(hWndMain,NFILE,"",MB_OK); // Testing
// Check if we can reach the library.
if(LoadLibrary(NFILE)==NULL) return 1; // If NULL there is an error
// Check if Version info can retrieve and returns the size, in bytes, of that information.
dwSize = GetFileVersionInfoSize( NFILE, NULL ); // Link the Version.lib Library first
if(dwSize==0) MessageBox(hwnd,"Error","",MB_OK); // 0 means an Error
// Get the file Information
char *FDBUF = new char[dwSize];
if ( !GetFileVersionInfo( NFILE, dwHandle, dwSize, &FDBUF[ 0 ] ) )
{ delete FDBUF; return 1; } // If not true, delete the buffer and return
// Get the information into the VS_FIXEDFILEINFO Structure
dwSize = sizeof(VS_FIXEDFILEINFO);
if ( !VerQueryValue( & FDBUF[ 0 ], "\\", (LPVOID*)&pvi, (unsigned int*)&dwSize ) )
{ delete FDBUF; return 1; } // Error processing the information structure.
// Original values according to windows File Version is 5.82 on System32 for legacy
// The 6.0 version lives in %SystemRoot%\winsxs.
wsprintf(BUFF, "Version is %d",LOBYTE(LOWORD(pvi->dwProductVersionLS)),HIBYTE(LOWORD(pvi->dwProductVersionMS)));
MessageBox(hwnd,BUFF,"The Value",MB_OK); // Display the value
delete FDBUF; return 0;
|
|
|
|
|
|
I had see many examples on getting the windows version, this is not the case.
Even Microsoft on on a web page show a funtion that does not work as it shows.
Thank
|
|
|
|
|
GESY wrote: I had see many examples on getting the windows version, this is not the case.
But you try at least some of them?
|
|
|
|
|
The examples that I had seen use a function that is just for the operating system.
I looking to read the version of any file. 10000 of thanks
|
|
|
|
|
GESY wrote: according to what I had read Where did you read this information?
GESY wrote: This is the code I have created, and cant get any close to that So what value do you actually get? And have you checked the details in the property page of the DLL?
I just ran your code on my Windows 10 system and get FileVersion of 5.82, and ProductVersion of 10.0, which I think is probably correct.
|
|
|
|
|
Most likely is the conversion or formatting string, I dont undertand much
the wsprintf funtion, I get big weir numbers, nothing like what you said.
If the code is correct, then have to be displaying on a message Box.
Can you help with this? Thanks 
|
|
|
|
|
GESY wrote: ...I get big weir numbers...
Such as?
GESY wrote:
If the code is correct, then have to be displaying on a message Box.
What exactly does this mean?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
GESY wrote: I get big weir numbers Yes, but you never tell us what the actual values are. Please don't think we can guess what results you see on your screen.
|
|
|
|
|
GESY wrote:
char *FDBUF = new char[dwSize]; If dwSize is 0 , this allocation is pointless. In other words, don't continue if GetFileVersionInfoSize() did not return anything useful.
GESY wrote:
wsprintf(BUFF, "Version is %d",LOBYTE(LOWORD(pvi->dwProductVersionLS)),HIBYTE(LOWORD(pvi->dwProductVersionMS))); To match the Details tab of the Properties dialog, I'd think you'd want something similar to:
wsprintf(BUFF, _T("File version is %u.%u.%u.%u"), HIWORD(pvi->dwFileVersionMS), LOWORD(pvi->dwFileVersionMS), HIWORD(pvi->dwFileVersionLS), LOWORD(pvi->dwFileVersionLS));
…
wsprintf(BUFF, _T("Product version is %u.%u.%u.%u"), HIWORD(pvi->dwProductVersionMS), LOWORD(pvi->dwProductVersionMS), HIWORD(pvi->dwProductVersionLS), LOWORD(pvi->dwProductVersionLS));
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 27-Jul-18 0:01am.
|
|
|
|
|
Auch!! Now I getting good help, someone here responded like you and to you too
10000 of thanks, for a good help and explanation !!
I will try that later when I have a chance and keep you posted.
|
|
|
|
|
I tested your lines of code, and was great, finally I can see what I was looking for !!!
I also thanks to the code you give me, I understand better that " wsprintf " function.
Now front the programmers point of view, if you testing for a particular dll
that you need to be some specific version, which one would you use?
Using dwFileVersionMS, The result was 5.82
Using dwProductVersionMS The result was 6.1
And 1000 of thanks again!!! 
|
|
|
|
|
GESY wrote: ...which one would you use?
That would depend on if I wanted to know the product's version or the file's version. They're two different things.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
You are using the wrong fields to get the values. The versions are stored in the following way:
dwProductVersionMS, contains the major fields, HIWORD, LOWORD e.g. 10, 0
dwProductVersionLS, contains the minor fields as above, e.g. 17134, 48
Also you are only printing one number, but passing two values in your wsprintf statement. So it should be:
wsprintf(BUFF, "Version is %d.%d",HIWORD(pvi->dwProductVersionMS), LOWORD(pvi->dwProductVersionMS));
|
|
|
|
|
Now that's what I call a good explanation!!!
1000 of thanks to you sr.
I will try that a will let you know....... 1000 of thanks again.!!!
|
|
|
|