How to import into a C++/WinRT project a UserControl from a windows runtime component written in C#? - windows-runtime

I have a very simple windows runtime component project written in C# in my solution where I added a UserControl that I would like to export to a C++/WinRT project.
This component works fine when imported into another C# project, but I get a compilation error when I try to import and use it in my C++/WinRT project.
\my_project\generated files\xamltypeinfo.g.cpp(1313): error C3083: 'my_component_XamlTypeInfo': the symbol to the left of a '::' must be a type
I added the reference to the component and I have added the following include to my pch.h thinking that it would resolve it:
#include "winrt/my_component.h"
but then I get the following compilation error:
\my_project\generated files\xamltypeinfo.g.cpp(1306): error C3083: 'my_component_XamlTypeInfo': the symbol to the left of a '::' must be a type
I noticed that there is also that if I include the header:
#include "winrt/data_grid.data_grid_XamlTypeInfo.h"
I no longer get a compiler error but the app crashes at startup when it tries to instantiate the component.
What is the normal procedure for importing windows runtime components that include XAML into C++/WinRT apps?

Related

Cython: calling C function throws 'undefined symbol'

I am attempting to use the LMDB C API with Cython.
I want to import the following definitions from the header file:
typedef struct MDB_env MDB_env;
int mdb_env_create(MDB_env **env);
So I created a .pxd file:
cdef extern from 'lmdb.h':
struct MDB_env:
pass
int mdb_env_create(MDB_env **env)
And I am using it in a Cython script:
cdef MDB_env *e
x = mdb_env_create(&e)
This code compiles fine, but If I run it, I get:
ImportError: /home/me/.cache/ipython/cython/_cython_magic_15705c11c6f56670efe6282cbabe4abc.cpython-36m-x86_64-linux-gnu.so: undefined symbol: mdb_env_create
This happens both in a Cython .pyx + .pxd setup and in a prototype typed in IPython.
If I import another symbol, say a constant, I can access it. So I seem to be looking at the right header file.
I don't see any discrepancy between my syntax and the documentation, but I am clearly doing something wrong. Can somebody give me a hint?
Thanks.
To compile it with IPythons-magic (would be nice if you would mention this explicitly in your question) you have to provide library-path (via -L-option) and library name (via -l-option) of the built c-library you want to wrap, see also the documentation:
%%cython -L=<path to your library> -l=<your_library>
The library you are trying to wrap is not a header-only library. That means that some symbols (e.g. mdb_env_create) are only declared but not defined in the header. When you build the library, the definitions of those symbols can be found in the resulting artifact, which should be provided to the linker when your extension is built. These definitions is what is needed when the program runs.
If you don't do it, the following happens on Linux: When the extension (the *.so-file) is built,the linker allows undefined symbols per default - so this step is "successful" - but the failure is only postponed. When the extension is loaded via import, Python loads the corresponding *.so with help of ldopen and in this step loader checks that the definitions of all symbols are known. But we didn't provide a definition of mdb_env_create so, the loader fails with
undefined symbol: mdb_env_create
It is differently for symbols which are defined in the header-file, for example enums MDB_FIRST&Co - the compiled library isn't necessary and thus the extension can be loaded, as there are no undefined symbols.

getDefinitionByName "Variable Not defined" workaround

Ok so I have game data parser that creates a game out of data file basically, it is using extensively getDefinitionByName which has one problem if the class is not loading somewhere else it throw variable not defined error information=ReferenceError: Error #1065: Variable {MyClass} is not defined. to workaround it I am using a class that holds all the list of components and instantiate it to make these classes available to the compiler.
Ok the question part is there any more efficient way to do that or playing with compiler argument or something ?
Is there something like export in first frame in flash professional as a compiler argument ?
I think what you want is to have a library project with all those "callable" classes, and then reference that library project in your game.
In flash builder, for a library project, you can check which classes are compiled (and so available to getDefinitionByName). (info here)

Dart confusing TYPE error

I am building a web application using dart with web_ui.
Everything was working fine until i added the web_ui pub, and now, when I am trying to run a build.dart file I get an error:
Uncaught Error: type 'AttributeName' is not a subtype of type 'String' of 'name'.
What does this mean?
From what I understand, this means there is somewhere an instance named 'name' of class 'AttributeName' that is extending 'String' class.
I searched my entire project and there is nowhere a class named 'AttributeName', nowhere an instance of 'name'.
I have the latest Dart editor and SDK:
Dart Editor version 0.4.7_r21658
Dart SDK version 0.4.7.5_r21658
EDIT:
this is my build.dart file:
import 'package:web_ui/component_build.dart';
import 'dart:io';
void main() {
build(new Options().arguments, ['web/menyplattan.html']);
}
Also, i updated all the pubs
This message looks like web_ui is failing a type check.
The similar SO question MarioP links to has a stacktrace showing this message coming from within the web ui library itself.
Do you have an xmlns attribute in your html?
Have a look at this web-ui issue.
AttributeName is defined within the html5lib library. Perhaps web-ui is expecting a newer version of this library but getting an older one. Make sure you've done a pub install. You can also try deleting your packages folder and doing a fresh pub install.
This could be caused by out-of-date packages, but it could also be a bug in web-ui. See if you can get a stacktrace and file a bug report, or post it on the web-ui mailing list.

Changing namespace name of C++ component in Windows Phone causes exception

I have a C++ runtime component in a WP8 application, and if I change the namespace name, I get a "TargetInvocation" exception thrown whenever I try to instantiate a class in that namespace.
As an example, if I create the default C++ Windows Runtime Component, the header looks like this:
#pragma once
namespace CppComponent1
{
public ref class WindowsPhoneRuntimeComponent sealed
{
public:
WindowsPhoneRuntimeComponent();
};
}
If I change CppComponent1 to CppComponent2 in the .h and the .cpp, and then try to instantiate a WindowsPhoneRuntimeComponent object in my C# code, I get the following error:
A first chance exception of type 'System.TypeLoadException' occurred in Unknown Module.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll
How can I change the namespace of a native module in a WP8 app? Thanks!
The name of the Windows Metadata (WinMD) file that declares the component must be a prefix of the namespace in which the public types are declared. (I provided a slightly more detailed explanation of the namespace rules in an answer to another question.)
If you rename the namespace from CppComponent1 to CppComponent2, you also need to rename the WinMD file produced by the build from CppComponent1.winmd to CppComponent2.winmd.

WP8: can't consume a native component

Windows Phone 8 C# project (MyApp), migrated from WP7.1. I've added a native Windows Runtime component library (AppLib) to the solution, created a reference. There's a public sealed ref class (MyClass) in it. There's a reference to it in the C# code (in OnLoaded of the main XAML page). The whole thing compiles - meaning the metadata of the component is being generated.
When I'm trying to run, the project fails with the exception or type TypeLoadException with the following message:
Typename or Namespace was not found in metadata file. (Exception from HRESULT: 0x8000000F)
Both AppLib.DLL and AppLib.winmd can be found in the XAP. The winmd contains the information about the type, and in the right namespace, too. What else should I check?
At exception time, the AppLib.dll is not listed in the modules window of the debugger. It's as if the DLL loading fails for some reason.
I've tried with brand new class in an arbitrary namespace - same problem. Looks like the problem is on the DLL level, not on class level.
The name of the WinMD file must be a prefix of the name of the namespace in which any public and activatable types are declared. For example, if your WinMD is named AppLib.winmd, your MyClass type must be defined in namespace AppLib or some other namespace nested within that namespace, for example AppLib::Something.
It must also be declared in the "best matching" WinMD, so if your type is named A.B.MyClass and you have both A.winmd and A.B.winmd in your package, the type must be defined in A.B.winmd.
The Windows Runtime uses the name of the type to determine which WinMD file defines the type. See also my answer to "XAML cannot find reference in local namespace."