Cannot compile WinUI 3.0 app that references a custom Windows Runtime component - winrt-xaml

I have a Visual Studio 2019 solution that contains two project.
The first project has been created using the "Windows Runtime Component (WinUI 3) Visual Studio template (library project). It generates a dll and associated winmd file that contains a DirectX-based Windows Runtime component to be used in the user interface of a WinUI 3.0 app.
The second project has been created using the "Blank App, Packaged (WinUI 3 in Desktop)" Visual Studio template. It generates a Win32 app that utilizes WinUI 3.0 as the UI framework and consumes the output of the first project.
That second project references the first project via Visual Studio / MSBuild project reference.
The first project defines the component via MIDL as follows:
namespace My.Company.Name.DirectX
{
runtimeclass CustomControl : Microsoft.UI.Xaml.Controls.SwapChainPanel
{
CustomControl();
// All interface methods and properties
}
}
The header that gets generated form this looks as follows:
namespace winrt::My::Company::Name::DirectX::implementation
{
struct CustomControl : CustomControlT<CustomControl>
{
public:
CustomControl();
~CustomControl();
// // All interface methods and properties
};
}
namespace winrt::My::Company::Name::DirectX::factory_implementation
{
struct CustomControl : CustomControlT<CustomControl, implementation::CustomControl>
{
};
}
I then attempt to use that component within a Microsoft.UI.Xaml.Controls.Page XAML file as follows:
<Page
x:Class="My.Company.Name.App.CustomControlPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:My.Company.Name.App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="using:My.Company.Name.DirectX"
mc:Ignorable="d">
<Controls:CustomControl/>
</Page>
However, if I compile the entire code I get the following error messages:
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(145): message : see reference to class template instantiation 'winrt::My::Company::Name::App::implementation::CustomControlPageT<D,I...>' being compiled (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,66): error C3646: 'CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,76): error C2059: syntax error: '(' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(30,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,62): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,71): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,1): error C2061: syntax error: identifier 'CustomControl' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,66): error C3646: '_CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,77): error C2059: syntax error: '{' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,13): error C3861: '_CustomControl': identifier not found (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,27): error C3861: 'value': identifier not found (compiling source file Page\CustomControlPage.cpp)
Somehow, my CustomControl is not recognized when compiling the source code that is generated for the XAML file that references it. I don't understand what the problem is. In theory, all I that is required to use that component is the winmd file because it should describe that component.
Can someone tell me why I'm getting these errors?
Edit:
I have attempted to reproduce the problem and the resulting Git repository is available here

Related

I have no erors in my scripts I but receive many errors in the xlocnum, io, and the xiosbase files, I tried looking at the errors but dont understand

The errors might be showing because of the internal thing I had created and defined as static
here is the build ouput
1>------ Build started: Project: C++_Game_Stuff, Configuration: Debug Win32 ------
1>win64_maybe32_idk_platform.cpp
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(41,1): error C2159:
more than one storage class specified
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(93): message : see
reference to class template instantiation 'std::_Iosb<_Dummy>' being compiled
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(41,43): error C2059:
syntax error: '='
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(41,1): error C2238:
unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(112,56): error C2589:
'static': illegal token on right side of '::'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xiosbase(112,1): error C2062:
type 'unknown-type' unexpected
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xlocnum(1439,73): error C2589:
'static': illegal token on right side of '::'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xlocnum(1555): message : see
reference to class template instantiation 'std::num_put<_Elem,_OutIt>' being compiled
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xlocnum(1522,73): error C2589:
'static': illegal token on right side of '::'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\ios(216,45): error C2059: syntax
error: 'type'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\ios(216,66): error C2143: syntax
error: missing ';' before '{'
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\ios(216,66): error C2447: '{':
missing function header (old-style formal list?)
1>C:\Users\maazs\source\repos\C++_Game_Stuff\C++_Game_Stuff\win64_maybe32_idk_platform.cpp(71,5): warning C4007: 'WinMain': must be '__stdcall'
1>Done building project "C++_Game_Stuff.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The rest of the code is just warnings about int to float conversions:
I am not to skilled in programming and I am also following a tutorial however though I believe I had defined a macro variable for the static keyword called #define internal static however this had caused errors due to the files I was talking about(Xiobase, xlocnum, io) containing a keyword named internal thus causing errors because of the two variables with different meaning having the same name the program was confused.

timespec redefinition error occurs after applying all known solutions

so I'm using visual studio 2019 and I installed pthread package but whenever I run my code the following error pops up "'timespec': 'struct' type redefinition "
the most common solution I found is to put #define HAVE_STRUCT_TIMESPEC before including pthread.h but whenever I do so two errors occur:
1- LNK2019 unresolved external symbol __imp__pthread_create referenced in function _main
2- 1 unroslved externals
I know this problem is common but I didn't find any solution to the two new errors specified.

LNK2019 unresolved symbol compiling LuaJava with Visual Studio 2012

I am working with visual studio 2012 to compile LuaJava. The problem I am having is when I call the linker. The line that calls the linker in the makefile is:
link /dll /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64"
/out:luajava-1.1.dll src\c\luajava.obj
"C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib" /VERBOSE
This seems to almost be linking everything successfully, until it gets to the Lua library.
The linker outputs the following when I try to make the project:
...//linking of other libraries
Finished searching libraries
Unused libraries:
C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\OLDNAMES.lib
luajava.obj : error LNK2019: unresolved external symbol lua_close referenced in function Java_org_keplerproject_luajava_LuaState__1close
luajava.obj : error LNK2019: unresolved external symbol lua_newthread referenced in function Java_org_keplerproject_luajava_LuaState__1newthread
luajava.obj : error LNK2019: unresolved external symbol lua_gettop referenced in function Java_org_keplerproject_luajava_LuaState__1getTop
...//lots of these errors
luajava-1.1.dll : fatal error LNK1120: 88 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\x86_amd64\link.EXE"' : return code '0x460'
Stop.
I'm confused as to why it says that the Lua library is unused, and then complains when it can't find the Lua library functions.
You can not link a 32 bit library to your 64 bit application. After some searces I do not believe LuaJava has a x64 download so to use this you must change your application to 32 bit.
Edit:
A second method would be to recomile LuaJava as a 64 bit dll. Here is a very recent post about that: LuaJava compile error "Unresolved external symbol"

Issue in convert project from vc6 to vc9

I have a project that was build in vc6,Now I have to convert it into vc9.
In the code there is line
CMapStringToOb cLogPathMap;
ofstream tlogFile;
But when I build the project the following error occur.
error C2146: syntax error : missing ';' before identifier 'tlogFile'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
When I go to definition of ofstream the file iosfwd is opened where ofstream defined as
typedef basic_ofstream<char, char_traits<char> > ofstream;
The following microsoft suggests to include fstream:
http://msdn.microsoft.com/en-us/library/e9cabcax%28v=vs.90%29.aspx
So put the following line in your header includes for that c++ file:
#include <fstream>

Compilation Qt 4.7.3 under Windows x64 with VS 2008

I tried to compilation Qt 4.7.3 under Windows x64 with VS 2008.
Step by step:
Start Start Menu\Microsoft Visual Studio 2008\Visual Studio Remote Tools\Visual Studio 2008 x64 Win64 Command Prompt
Go to C:\Qt\4.7.3\
Type configure
Type nmake.
But I have compilation error:
qnetworkdiskcache.cpp
c:\qt\4.7.3\include\qtcore\private\../../../src/corelib/io/qiodevice_p.h(170) :
warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss
of data
c:\qt\4.7.3\include\qtcore\private\../../../src/corelib/io/qiodevice_p.h(170) :
warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss
of data
c:\qt\4.7.3\include\qtcore\private\../../../src/corelib/io/qiodevice_p.h(170) :
warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss
of data
access\qnetworkrequest.cpp(997) : warning C4996: 'sscanf': This function or vari
able may be unsafe. Consider using sscanf_s instead. To disable deprecation, use
_CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\stdio.h(32
4) : see declaration of 'sscanf'
c:\Qt\4.7.3\src\network\tmp\moc\debug_shared\moc_qnetworkreplyimpl_p.cpp(99) : e
rror C2079: '_r' uses undefined class 'QSslConfiguration'
c:\Qt\4.7.3\src\network\tmp\moc\debug_shared\moc_qnetworkreplyimpl_p.cpp(99) : e
rror C3861: 'sslConfigurationImplementation': identifier not found
c:\Qt\4.7.3\src\network\tmp\moc\debug_shared\moc_qnetworkreplyimpl_p.cpp(100) :
error C2582: 'operator =' function is unavailable in 'QSslConfiguration'
c:\Qt\4.7.3\src\network\tmp\moc\debug_shared\moc_qnetworkreplyimpl_p.cpp(101) :
error C3861: 'setSslConfigurationImplementation': identifier not found
c:\Qt\4.7.3\src\network\tmp\moc\debug_shared\moc_qnetworkreplyimpl_p.cpp(102) :
error C3861: 'ignoreSslErrorsImplementation': identifier not found
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\amd64\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
I used nmake /I for compilation Qt. I compiled modules, what was needed me successful.
Not all modules of Qt are easily build-able in VS. The following configure parameters have worked for people in the past:
configure.exe -platform win32-msvc2008 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast

Resources