Trying to TryParse in c++/clr but OUT is undefined - c++-cli

im trying to use
public: bool^ IsNumeric(Object^ Expression) {
double^ retNum;
bool^ isNum = Double::TryParse(Convert::ToString(Expression), System::Globalization::NumberStyles::Any, System::Globalization::NumberFormatInfo::InvariantInfo, out retNum);
return isNum;
}
but i get a error: identifer OUT is undefined
i have no idea how to use OUT in clr/c++
Thanks

Use "%" instead of out to take a tracking reference.
https://learn.microsoft.com/en-us/cpp/extensions/tracking-reference-operator-cpp-component-extensions?view=vs-2019

Related

When ever I try to compile the contract I keep getting a error on this line

In remix this line gives me a error "ParserError: Expected '(' but got identifier"
function setIsPublicMintEnabled(bool is PublicMintEnabled_) external onlyOwner {
isPublicMintEnabled=isPublicMintEnabled;
}
There is an syntax error around is keyword. Refactor your function in following way:
function setIsPublicMintEnabled(bool isPublicMintEnabled_) external onlyOwner {
isPublicMintEnabled = isPublicMintEnabled_;
}
is keyword is used when contract inheritance is being defined. Here is an detailed explanation how to use inheritance and the is keyword in practice.

How to resolve assert WINRT_ASSERT(!is_sta()) in winrt::impl::blocking_suspend

I have a Win32 DLL I am trying to convert to be usable from UWP. I need to replace file handling code (CreateFile, ReadFile, etc.) to the WinRT safe equivalents (Windows::Storage::StorageFile). I have the code converted and compiling, but when I run the app I get this exception calling get on the returned async operations and I am not sure how to resolve this.
Ok, took a bit to figure out what I was doing wrong but the correct way to handle this in my case is to wrap my code in a co_routine and then call it using PPL.
IAsyncOperation<int> DoWork()
{
co_await winrt::resume_background();
…
return someValue;
}
int Foo()
{
return create_task([]{
return DoWork().get();
}).get();
}

Function with return type and "use" keyword

How can you create a function that specifies both the return type and the external variables to use?
Are the examples below wrong or is it not supported (yet)?
<?php
$arr = ['test' => 'value'];
function test1() use ($arr) : string { // Line 5
return $arr['test'];
}
function test2() : string use ($arr) {
return $arr['test'];
}
The error is:
Parse error: syntax error, unexpected 'use' (T_USE), expecting '{' in [PATH]\index.php on line 5
You can run the code here.
As answered by Adam Cameron in the comments, the problem is that the use language construct only applies to closures, not to all functions. Thus, using it on normal functions makes no sense and is as such not understood by the parser.
When the function in the example code would have been a closure, everything would have worked.
$arr = ['test' => 'value'];
$fn = function() use ($arr) : string {
return $arr['test'];
};
echo($fn()); // outputs 'value'
You can run the code here.
Note that your first attempt is correct: first the use statement, then the return type declaration. Trying to reverse these two will result in a parse error.

aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined

I'm sure this must be something simple, but I can't quite work out what's up here...
I'm trying to create a QSqlQuery, and the compiler is giving me this:
error: aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined
This code is in my mainWindow class:
void MainWindow::on_toolButton_clicked()
{
QString filename;
filename = QFileDialog::getSaveFileName(this, tr("Save to SQL Database"),
"~/temp",
tr("Files (*.fdb)"));
QSqlDatabase testDatabase = QSqlDatabase::addDatabase("QSQLITE");
testDatabase.setDatabaseName(filename);
//this line won't compile:
QSqlQuery testQuery;
testDatabase.close();
QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName());
}
Can anyone see what I'm missing here?
The error message indicates that the type SqlQuery is not completely defined. QSqlQuery is defined in
#include <QSqlQuery>
Include that and things should compile ok.

Mapping IOKit IOReturn error code to String

When I get error 0x10, I want to be able to make sense of that error code. Looking up IOReturn.h and mach/error.h is not particularly convenient. I was lost when I got 0x22 error code. This is really silly question but is there a function like error2String which can map IOReturn error code to String that describes the error ?
You can use the mach_error_string standard foundation function to do this.
Eg. in Swift:
func krToString (_ kr: kern_return_t) -> String {
if let cStr = mach_error_string(kr) {
return String (cString: cStr)
} else {
return "Unknown kernel error \(kr)"
}
}
Code running in the kernel can use IOService::stringFromReturn(...)