|
Thanks. Do you want me to send to you a copy of the old form of my 'dragclip' program?, so that you can investigate why "One-way upgrade. Visual Studio ..." repeatedly asked to upgrade it?
|
|
|
|
|
No thanks. You should report it to Microsoft though.
|
|
|
|
|
I am using VS 2015. When I opened its help just now, a top panel recommended using VS 2017; will that cause a quick replacement of my VS 2015 by VS 2017, or will there be a long complicated process?
|
|
|
|
|
I have VS 2015. Its help recommends upgrading to VS 2017.
|
|
|
|
|
I have now upgraded to VS 2017. I have used it to remake my project 'dragclip_vc'. In it, the top menu has entries for "File, Edit, View, Project, Team, Tools, Windows, Help", but none of then seem to lead to an option letting me compile or run the source file. What should I do?
|
|
|
|
|
I have been using Visual C++ for many years to develop programs, without trouble.
Today, a new automatic upgrade system shows up whenever I call one of my Visual C++ projects.
In one of them, the automatic upgrade showed and operated, asking me to click on things, OK, and I had to re-open the component files that it displays, and I saved the run, and exited, and after that, it comes up OK when called.
In another of them, however often I open it and exit from it, every time I open it, the automatic upgrade shows, and I must run it, and it wipes the display of the program's files that I had opened. What causes that?
|
|
|
|
|
[See below the original question for the solution.]
I have been struggling with this for a while now, and I can't seem to figure it out.
Here's my declaration:
std::unique_ptr<BYTE*, std::function<void(BYTE**)>> _VersionData{};
And here's where I attempt to instantiate it:
_VersionData = std::make_unique<BYTE*>(new BYTE[_VersionDataLength], [](BYTE** ptr) {delete *ptr; });
The errors I receive are:
error C2440: 'initializing': cannot convert from 'initializer list' to 'unsigned char *'
note: The initializer contains too many elements
I'm probably way off in my interpretation of the documentation. Can someone show me how this is supposed to work?
[SOLUTION]
Turns out I was really way off with the attempt shown above.
Here's the working code.
The declaration in the class header file:
std::unique_ptr<BYTE, void(*)(BYTE*)> _VersionData;
The instantiation in the source file:
auto CustomDeleter = [](BYTE* ptr) {delete[] ptr; };
_VersionData = std::unique_ptr<BYTE, decltype(CustomDeleter)>(new BYTE[_VersionDataLength], CustomDeleter);
And the most important part, the constructor initializer list:
CFileVersionInfo::CFileVersionInfo()
: _VersionData(nullptr, [](BYTE* ptr) {delete[] ptr; })
{
}
The difficult we do right away...
...the impossible takes slightly longer.
modified 28-Jul-18 11:42am.
|
|
|
|
|
Now that you understand it, how about writing an article for the rest of us?
|
|
|
|
|
Thanks for the vote of confidence, Richard!
I can't say that I completely understand it. Getting it to work was partly just trying different things until I hit upon the magic combination!
I do understand some parts of it better now, but hardly well enough to write an article.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Where I can learn about using wsprintf? I using Visual Studio 12 with plain C Code Lines.
For examples, this lines give me 2 different results depending on the
formatting I believe but I can't find any practical info about it.
For example what the " >>6" or " >>12" do?
Thanks, check the code below and you see what I mean
DWORD DVALE=19542016;
wsprintf(BUFF, "Version is %d \n Good Night",DVALE >>6 & 0xff);
MessageBox(hWndMain,BUFF,"The Value",MB_OK); // Display 192
wsprintf(BUFF, "Version is %d \n Good Night",DVALE >> 12 & 0xff);
MessageBox(hWndMain,BUFF,"The Value",MB_OK); // Display 163
|
|
|
|
|
|
|
Auch, you think I can remember those days?
That's a lot of math, if I start experimenting I may get it back.
But for now, that page got me hungry!!!
But I did catch the idea of shifting, all this because
a code that I posted here, that some one tested and said works correctly
and got the right values, however I don't, I do not see how may code
works correctly on his computer, but on mine I get big numbers, far for what
I am looking for. Go ahead and check it, and tell me what you think if you please....
Thanks
Look for "No-Errors-but-wrong-values-on-return"
|
|
|
|
|
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;
|
|
|
|
|
|