I'm using Gecko SDK 32.0.2 for win32.
I have this snippet of code, that should work:
nsCOMPtr<nsIDOMDocument> doc;
dwi->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
But, the compiler says:
no instance of overloaded function 'do_QueryInterface' matches argument list nsCOMPtr<nsIDOMDocument>
Available overloads are:
do_QueryInterface(nsISupports* rawPointer)
and
do_QueryInterface(already_AddRefed<T>&)
How to properly make the function call in this case?
I will self-answer it...
As I've written in the comment, I got no answer on ask.m.o., but I found out the cause.
It was not related to the message directly, it was due to VSC++ project properties:
Treat WChar_t as Built in Type should be set to "Yes (/Zc:wchar_t)"
Related
I developed some ANTLR + LLVM parser code in spring. Since it is only a recreational project, I did not touch the code or see whether it compiles in the meantime. During that time, several system updates took place, which I assume caused my current problems:
When trying to compile the code today (with clang++), I suddenly got several error messages. Initially the std::any class was not found at all. I then played with "std=c++17" and "std=c++20" options. Now the main error (as I understand it) seems to be
error: no member named 'as' in 'std::any'
The error occurs whenever i do something like for instance
args.push_back(visit(*it).as<sarg>());
or, more stripped-down:
antlrcpp::Any myvar;
//...
myvar.as<some_type>();
I picked this up from Antlr tutorial codes where this seems to be the standard idiom to cast an antlrcpp::Any object to the type desired by the calling function.
I noticed that antlrcpp::Any apparently is merely a wrapper for std::any, which apparently really does not support this "as" method.
What can i do to make my code work again?
THE ANSWER ACCEPTED GAVE ME THE CORRECT EXPLANATION OF THE PROBLEM. I ALSO EDITED THE QUESTION PUTTING THE ANSWER POINT BY POINT IN CAPITAL LETTERS TO MAKE IT CLEARER
I have a c++ code in MacOSX, that use a bit of CoreFoundation.
I use the following function CFPropertyListCreateWithData in my code that takes a CFErrorRef *error as one of its parameters. Well, I create CFErrorRef myError and pass it as &myError
First problem: I think there is a bug in the Documentation, because it gives me some good data as result, but the error is NOT NULL. If I have an error, the data should be NULL, shouldn't it? Or did I misunderstand the documentation?
FIRST SOLUTION: THE ERROR IS UNDEFINED IF THERE IS NO ERROR, SO I HAD TO CHECK THE ERROR ONLY IF THE DATA WERE NULL. MOREOVER I WAS RELEASING USING CFRelease A UNDEFINED OBJECT, THE ERROR, THAT CAUSED MY PROGRAM TO CRASH WITH A SEGMENTATION FAULT
Second problem: I want to check which is the error.
Well I get into this function CFErrorCopyFailureReason, doc here,
but it takes a CFError and not a CFErrorRef, and gives me a CFString. Then, how can I transform my CFErrorRef to CFError?
SECOND SOLUTION: NOSENSE QUESTION, I WAS READING THE DOCUMENTATION OF SWIFT AND NOT OF OBJECTIVE-C
Third problem: the function CFErrorCopyFailureReason gives me a CFString, but I do not know where the CFString is defined! it is not in CoreFoundation/CoreFoundation.h and neither in CoreFoundation/CFString.h, and I have a undefined type error when I try to compile.
Then: In which file is CFString defined? Can I convert it to CFStringRef, and how can I do it?
THIRD SOLUTION: NOSENSE QUESTION, I WAS READING DOCUMENTATION OF SWIFT AND NOT OF OBJECTIVE-C
Fourth problem: with the code I have, if I use CFStringRef and CFErrorRef instead of CFString and CFError, it compiles, but then I have a NSInvalidArgumentException. Shouldn't I have an error at compilation time? I would not like a RunTimeException...
FOURTH SOLUTION: AS THE ANSWER MADE ME UNDERSTAND, I HAD TO CHECK THE ERROR ONLY IF THE DATA WAS NULL. IN THAT CASE I WAS CHECKING A ERROR WITH UNDEFINED DATA THAT GAVE ME THE INVALID ARGUMENT EXCEPTION. OBVIOUSLY, SINCE THE PROBLEM WAS UNDEFINED VALUE IN THE ERROR, THIS IS A RUNTIME EXCEPTION
Well, to conclude, I just want to read and write a Info.plist file in my c++ application. I take inspiration from this, Saving and Restoring Property Lists, sample code and modified it quite a bit. If you have a working sample how to read and modify a Info.plist file, please tell me :) but without using PlistBuddy or other tools please, only c++ API.
TO CONCLUDE: THE SAMPLE CODE WORKS WELL, I JUST MISUNDERSTOOD THE DOCUMENTATION
Thanks to everybody
I think you are misunderstanding the documentation for CFPropertyListCreateWithData(): if it succeeds, the return value is non-NULL, and what error points to is not defined. Don't worry about error unless CFPropertyListCreateWithData() returns NULL.
CFErrorCopyFailureReason() does take a CFErrorRef and return a CFStringRef. You might be looking at the Swift documentation for it, change the language to Objective-C on the top of the documentation page.
Which call is throwing the exception, CFPropertyListCreateWithData()?
I am trying to check if a DLL is signed based on the file path. I see that there are pre-existing solutions for this type of problem using WinVerifyTrust, however, when I tried checking it against "C:\Windows\System32\kernel32.dll" it said: "The file "C:\Windows\System32\kernel32.dll" is not signed." although kernel32 should be a signed dll. I am on Windows 7 fyi.
This is the source code to the function I called: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382384(v=vs.85).aspx
How can I fix the function?
Yes WinVerifyTrust is the correct function to use but you have to be prepared to call it twice.
First you call it with WTD_CHOICE_FILE, if that succeeds then you are done. If not, you must call it again with WTD_CHOICE_CATALOG (CryptCATAdminCalcHashFromFileHandle + CryptCATAdminEnumCatalogFromHash + CryptCATCatalogInfoFromContext) because some Windows files do not embed the certificate information (especially non-PE files). (You can also try to find the catalog info first to avoid calling it twice but I assume this is slower)
There are various threads (this and this) on the Sysinternals forum is perhaps the best resource for questions related to this.
I am building a 3D Game Engine. I have build many in other languages, but finally decided to reap the speed benefits of C++ (despite not knowing it particularly well).
I have a class called EngineOptions that I use to store information about how the engine is to be initialized. The engine's main class, Monolith, then takes a const reference to the options instance like so:
monolith::EngineOptions options();
monolith::Monolith engine(options);
Monolith has a correct header file and a constructor like this:
Monolith::Monolith(const EngineOptions& options) : m_options(options)
{
m_window(m_options.windowWidth, m_options.windowHeight, m_options.windowTitle);
}
While I think this is correct, the compiler is complaining that there is:
no matching function for call to 'monolith::Monolith::Monolith(monolith::EngineOptions (&)())'
Excuse me if I'm being stupid, but I think this code is correct, am I wrong?
I am using the Code::Blocks IDE with the standard GCC toolchain provided on my system.
Remove the parentheses from this line:
monolith::EngineOptions options();
The compiler thinks you're declaring a function returning an EngineOptions instance.
I'm updating a c++ routine to move files that was written in visual studio express 2008/2010. I'm now running VS Express 2012
Obviously there are changes to the compiler because string functions have to be upgraded to strcpy_s etc. No problem. This is a console app. I never extended my C++ knowledge past C++ to C# etc. as I need little more than to be able to write small utils to do things on the command line. Still I'm able to write somewhat complex utilities.
My issue is movefile() function always fails to move with either error 2 or 123. I'm working in C:\users\alan\downloads folder so I know I have permission. I know the file is there. Small snippet of code is:
char source=".\\test.txt"; // edited for clarity.
char dest=".\\test.txt1";
printf("\nMove\n %s\n to %s\n",source,dest); // just to see what is going on
MoveFile((LPCWSTR) source, (LPCWSTR) dest);
printf("Error %u\n",GetLastError());
output is :
Move
.\test.txt
to .\test.txt1
Error 2
All of my strings are simple char strings and I'm not exactly sure, even after reading, what LPCWSTR was type def'd for and if this is the culprit. So to get this to compile I simply typedef'd my strings. And it compiles. But still it won't move the files.
The code is more complex in developing the source & dest variables but I've reduce it to a simple "just append a 1 to the file name" situation to see if I can just simply rename it. I thought C:\xxx\yyy\zzz\test.txt was maybe wrong in some fashion but that idea fell though with the above test. I've done it with and without the .\ same issue. I'm running out of ideas other than making my own fileopen read/write binary function to replace movefile(). I'm really against that but if I have to I will.
EDIT: I pasted the printf from original code that used FullPathName, I've corrected the snippet.
The fact that you are casting your arguments to LPCWSTR suggests that you are compiling your program with UNICODE defined, which means you are calling MoveFileW and the compiler warned about an argument type mismatch.
Inserting a cast does not fix that. You are telling the compiler to stop complaining, but you haven't actually fixed the problem (the underlying data is still wrong).
Actual solutions:
Use WCHAR as MoveFileW expects (or TCHAR/LPTSTR and the _T macro).
Explicitly call MoveFileA
Compile without UNICODE defined.
Thanks Andrew Medico. I used MoveFileA and the program seems to work now.
I'm not sure I turned off unicode, but I did change one item in the properties.
I'll need to read up on the compiler about unicode/ansi settings. But for now the issue is fixed and I'm sure I've got the idea of what I need to do. "research"!!!!