Why I am getting C3646 on an IAsyncAction declaration? - winrt-xaml

Probably a dumb question (WinRT noob), but, here is goes...
The code from "App.xaml.h" is:
namespace winrt::Precog::implementation
{
struct App : AppT<App>
{
App();
void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);
private:
std::wstring cfgDatabase = L"";
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
IAsyncAction loadSettings();
};
}
When I try to compile, Visual Studio gives me a C3646 (unknown override specifier) at the IAsyncAction declaration?
The loadSettings implementation is:
IAsyncAction App::loadSettings()
{
PHKEY regKey = NULL;
LSTATUS regResult;
regResult = RegCreateKey(HKEY_CURRENT_USER, L"Precog", regKey);
if (regResult != ERROR_SUCCESS)
{
ContentDialog errorDialog = ContentDialog();
errorDialog.Title(box_value(L"Erro"));
errorDialog.Content(box_value(L"Pateta"));
errorDialog.CloseButtonText(L"Ok");
errorDialog.XamlRoot(window.Content().XamlRoot());
auto result = co_await errorDialog.ShowAsync();
}
else
{
co_return;
}
}
EDIT: Full compiler output:
Build started...
1>------ Build started: Project: Precog, Configuration: Debug x64 ------
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2304,5): warning MSB3106: Assembly strong name "C:\Code\Precog\packages\Microsoft.WindowsAppSDK.1.0.0\build\native\..\..\lib\uap10.0\Microsoft.Windows.System.winmd" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2304,5): warning MSB3106: Assembly strong name "C:\Code\Precog\packages\Microsoft.WindowsAppSDK.1.0.0\build\native\..\..\lib\uap10.0\Microsoft.Windows.PushNotifications.winmd" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
1>App.xaml.cpp
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,22): error C3646: 'loadSettings': unknown override specifier
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,34): error C2059: syntax error: '('
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,36): error C2238: unexpected token(s) preceding ';'
1>C:\Code\Precog\Precog\Precog\App.xaml.cpp(35,19): error C2039: 'loadSettings': is not a member of 'winrt::Precog::implementation::App'
1>C:\Code\Precog\Precog\Precog\App.xaml.h(7): message : see declaration of 'winrt::Precog::implementation::App'
1>C:\Code\Precog\Precog\Precog\App.xaml.cpp(48,30): error C2065: 'window': undeclared identifier
1>Done building project "Precog.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Got it. It seemed to be a namespace mismatch, since changing the declaration to:
winrt::Windows::Foundation::IAsyncAction loadSettings();
Solved the problem. The interesting bit is that Intellisense does not catch the error (no red line underneath the type), only the compiler does.

Related

Visual Studio warning C4596 in constructor declaration

Warning C4596 can, apparently, be solicited by several configuration. I found a few that did not match my problem so this is submited:
class dialog_base : public wxFrame
{
public:
dialog_base::dialog_base( const wxString& title );
… }
1> E:\WX\wx_numbers_01\dialog_base.h(18,28): warning C4596: '{ctor}': illegal qualified name in member declaration (compiling source file wx_numbers.cpp)
So how should this constructor be declared?
Just in case, as I read the error it comes from this part of the declaration:
dialog_base::dialog_base
I realize removing the "unexpected qualification" will resolve this warning. In your case, just use
dialog_base( const wxString& title );
May I know the reason why one would want to use
dialog_base::dialog_base( const wxString& title );

Defining a smart pointer as a member variable of a class

Header:
CChristianLifeMinistryHtmlView m_pHtmlView = nullptr;
Source:
m_pHtmlView = new CChristianLifeMinistryHtmlView();
Trying to change it to use a smart pointer. I can do this (inside OnInitDialog):
auto m_pHtmlView2 = std::make_unique<CChristianLifeMinistryHtmlView>;
But I can't work out how to have my smart pointer defined as a member variable of my CDialog class. I can't do: std::unique_ptr m_pHtmlView2.
I saw this discussion (Using smart pointers as a class member) and based on that I tried this in the header:
//CChristianLifeMinistryHtmlView *m_pHtmlView;
std::unique_ptr<CChristianLifeMinistryHtmlView> m_pHtmlView;
But that will not compile:
6>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30704\include\memory(3087,1): error C2248: 'CChristianLifeMinistryHtmlView::~CChristianLifeMinistryHtmlView': cannot access protected member declared in class 'CChristianLifeMinistryHtmlView'
6>D:\My Programs\2022\MeetSchedAssist\Meeting Schedule Assistant\ChristianLifeMinistryHtmlView.h(104): message : compiler has generated 'CChristianLifeMinistryHtmlView::~CChristianLifeMinistryHtmlView' here
6>D:\My Programs\2022\MeetSchedAssist\Meeting Schedule Assistant\ChristianLifeMinistryHtmlView.h(22): message : see declaration of 'CChristianLifeMinistryHtmlView'
6>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30704\include\memory(3085): message : while compiling class template member function 'void std::default_delete<CChristianLifeMinistryHtmlView>::operator ()(_Ty *) noexcept const'
6> with
6> [
6> _Ty=CChristianLifeMinistryHtmlView
6> ]
6>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30704\include\memory(3195): message : see reference to function template instantiation 'void std::default_delete<CChristianLifeMinistryHtmlView>::operator ()(_Ty *) noexcept const' being compiled
6> with
6> [
6> _Ty=CChristianLifeMinistryHtmlView
6> ]
6>C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30704\include\memory(3122): message : see reference to class template instantiation 'std::default_delete<CChristianLifeMinistryHtmlView>' being compiled
6>D:\My Programs\2022\MeetSchedAssist\Meeting Schedule Assistant\AvailableBrothersReportPreview.h(52): message : see reference to class template instantiation 'std::unique_ptr<CChristianLifeMinistryHtmlView,std::default_delete<CChristianLifeMinistryHtmlView>>' being compiled
Update
Based on the advice in the comments I now have:
Header:
std::unique_ptr<CChristianLifeMinistryHtmlView> m_pHtmlView;
Source (in OnInitDialog):
m_pHtmlView = std::make_unique<CChristianLifeMinistryHtmlView>();
if (m_pHtmlView != nullptr)
{
m_pHtmlView->Create(nullptr, nullptr, AFX_WS_DEFAULT_VIEW,
m_rctPreviewHtml, this, 0);
m_pHtmlView->ShowWindow(SW_SHOWNORMAL);
if(CMeetingScheduleAssistantApp::WaitForFileToBeReady(m_strTempHtmlFile))
m_pHtmlView->Navigate2(m_strTempHtmlFile, 0, nullptr);
}
It complies and works. My popup dialog displays and the CHtmlView derived control is visible. Cool. But when I click OK to close the dialog I get an exception:
How do we address that?
CHtmlView is derived from CFormView -> CView, which deletes itself in CView::PostNcDestroy with delete this; So the memory is already managed.
Replace new with std::make_unique, and call release() immediately, because you don't want unique_ptr to delete it anymore.
//m_pHtmlView = new CChristianLifeMinistryHtmlView();
m_pHtmlView = std::make_unique<CChristianLifeMinistryHtmlView>().release();
If you had written new and delete in your original code (that also means you at least override CMyHtmlView::PostNcDestroy) then unique_ptr can be used to replace both new and delete.
In this case, you only had new in the original code. You don't want unique_ptr to manage delete

vc++ undeclared indentifier 2015

Need help to resolve an error.
Currently I am working on a migration project from visual c++ 6.0 to visual studio c++ 2005.
And during compilation, I am getting "Undeclared Identifier Error"
I am hearing pasting the code and error.
code
const SMbfIndexCash* GetIxCashed(const CPoint& ptIxBlock, const short nMbfID)
{
SMbfIndexCash* pCashFound;
for(int ixFound=0; ixFound<MBF_IX_CASH_SIZE; ixFound++)
{
pCashFound=&ElementAt(ixFound);
if(pCashFound->nAge<0)
return NULL;
if(nMbfID==pCashFound->nMbfID && ptIxBlock==pCashFound->ptIxBlock)
break;
}
if(ixFound==MBF_IX_CASH_SIZE)
return NULL;
}
Error.
1>c:\cm and nemesis\cm code\cm 8.16\cm
8.16.0.1\source\cmoslib\tile.h(466) : error C2065: 'ixFound' :
undeclared identifier
Thank you.
The ixFound is now local to the scope of the for loop.
you need to do something like:
int ixFound = 0;
for(ixFound=0; ixFound<MBF_IX_CASH_SIZE; ixFound++)
{
//...
}
//...

c++ header file errors?

(Visual Studio c++ 6.0)
.\app.h(69) : error C2146: syntax error : missing ';' before identifier 'IsProcessRunning'
.\app.h(69) : error C2501: 'DWORD' : missing storage-class or type specifiers
.\app.h(69) : error C2061: syntax error : identifier 'LPCTSTR'
.\app.h(70) : error C2061: syntax error : identifier 'LPCTSTR'
Not sure why these errors? Why the syntax error? DWORD and LPCTSRT are recognized.
virtual BOOLEAN DoNew( void );
DWORD IsProcessRunning(LPCTSTR procname);
bool TerminateProcess(LPCTSTR procname);
void UpdateControllerStatus( void );
According to the errors, DWORD is not recognized. Are you sure you are including windows.h?
Add #include to the beginning of your code...

extern template DLLs and programs (crypto++)

I've been using Crypto++ with VS2005 and VS2010 for a while now. But recently I needed to use it with and application directly. The same code compiles fine when I'm compiling as a DLL and does not compile when compiling as an application.
This is the smallest sample that reproduces the error is this (based on cryptopp561\algparam.h:301 CryptoPP::AlgorithmParametersTemplate
class Base
{
protected:
virtual void MoveInto(void *p) const = 0;
};
template<class T>
class Test: public Base
{
public:
void MoveInto(void * buffer) const
{
Test<T> *x = new(buffer) Test<T>(*this);
}
};
extern template class Test<bool>;
The compilation parameters are the same, only difference that I saw was the configuration type in the project ("Application (.exe)" generates the error and "Dynamic Library (.dll)" does not).
This is the compiler error:
main.h(15): error C2061: syntax error : identifier 'buffer'
main.h(14) : while compiling class template member function 'void Test<T>::MoveInto(void *) const'
with
[
T=bool
]
main.h(20) : see reference to class template instantiation 'Test<T>' being compiled
with
[
T=bool
]
It seems to occur only when theres inheritance. Ommiting : public Base in the class Test declaration makes the error go away.
EDIT:
The problem was in a header included somewhere that defined a a debug version for operator new but didn't declared the placement new version.
Did you #include <new>, the header file that declares placement-new?
Funnily, extern templates are to tell the compiler to not instantiante at some point, so the second error does not make sense to me. Are you certain your compiler has support for extern templates? What if you do the opposite, explicit instantiation:
template class Test<bool>;

Resources