Static Library C++/WinRT - c++-winrt

I have created a static library(c++/WinRT) and an Universal Windows App [Blank App] (c++/WinRT)project in VS 2019.
Then From Project Universal Window app I added project reference of the static library.
I am getting below error while building the universal app
D:\Dv\Main\Vib\CM\UI\UserInterfaceCppWinRT\Generated Files\XamlTypeInfo.g.cpp(178,52): error C2039: 'UIViewModelCppWinRT': is not a member of 'winrt'
Individually the static library build successfully. Not getting any clue about c++/winrt static library project consumption. Any suggestion?

When you add reference of the static library to main project and build main project successfully, you can find it has generated the StaticLibrary.h file under the \MyProject\MyProject\Generated Files\winrt folder along with other Windows namespaces. So if you want to import the idl(e.g. Class.idl), you don't need to import it manually, since your toolchain is set up to automatically reference any types that are in system namespaces. You only need to import any types that you've defined in your project. For example:
MainPage.idl
namespace WinrtApp
{
[default_interface]
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage();
Int32 MyProperty;
StaticLibrary1.Class MyClass;
}
}
When you want to access the property from static library, first include the header file and initialize it.
MainPage.h
private:
StaticLibrary1::Class myclass{nullptr};
.cpp:
#include "winrt/StaticLibrary1.h"
myclass = StaticLibrary1::Class();
int property = myclass.MyProperty();
Here is a simple sample that I created, you can download it to check the complete steps.

Related

Specify class loader for loading dependencies of an advice's dependency

I have an advice class that makes use of another class that's part of the agent jar, but this other class has a dependency on a class that's not present in the agent jar. This class that's not present in the agent jar is present in another jar that's on the application class loader. The agent jar is on the system class loader. So I run into NoClassDefFoundError. I have tried using Transformer.ForAdvice as suggested in this other post, but that only works for the advice class.
// In agent jar on system class loader
MyAdviceClass {
#Advice.OnMethodEnter
public static void onMethodEnter() {
YetAnotherClass.doSomething(); // works fine as Transformer.ForAdvice makes use of the correct class loader while inlining this code
AnotherClass.doSomething(); // NoClassDefFoundError happens inside this method call
}
}
// In agent jar on system class loader
public class AnotherClass {
public static void doSomething() {
YetAnotherClass.doSomething(); // NoClassDefFoundError happens here because the system class loader is used to load YetAnotherClass, but that class is only present on the application class loader
}
}
// In user jar on application class loader
public class YetAnotherClass {
public static void doSomething() {
// do something else
}
}
Transform looks like this:
.transform(new AgentBuilder.Transformer
.ForAdvice()
.include(getClass().getClassLoader())
.advice(methodMatcher, "com.something.advice.MyAdvice.class"));
MyAdviceClass and AnotherClass are present in the agent jar. YetAnotherClass is present in user jar that's not on the system class loader, its on the application class loader. How can I solve this problem? i.e. is there a way by which I can force the use of the application class loader in AnotherClass?
I assume that AnotherClass is not visible from the class being instrumented. In this case, you should not include the class in ypur agent jar but place it in a seperate jar that you append to the boot loader via Instrumentation.appendToBootSearchPath. Classes on the boot loader are universally visible and should therefore be accessible to your instrumented class.
If the injected classes reference classes of the instrumented class loader you might however need to inject classes into the class loader using a ClassInjector.

How can I execute a terminal command when opening IntelliJ Project?

Not even sure if this possible with IntelliJ but I'd like to tie the vagrant up command to run automatically when I open an IntelliJ project. I've scoured the settings but haven't been able to find anything that gives me this functionality.
You can write a plugin.
https://www.jetbrains.com/help/idea/plugin-development-guidelines.html
Define an application component in the plugin.xml
<application-components>
<component>
<implementation-class>com.steve.plugins.recentprojects.RecentProjects</implementation-class>
</component>
</application-components>
And then you implement ApplicationComponent, which defines these methods in a parent interface:
public interface BaseComponent extends com.intellij.openapi.components.NamedComponent {
default void initComponent() { /* compiled code */ }
default void disposeComponent() { /* compiled code */ }
}
It seems like initComponent() can be a nice place to insert a function to start vagrant.
Alternatively... externalise the startup, write a script that starts vagrant and then starts intellij...

Mixed C++ DLL Project with native and CLI code

I've created C++ DLL project, this dll contains mostly native c++ code, but it have 1 mixed class written in C++ and using some .NET types.
This class is declared in header file and have implementation in .cpp
I can use it from all *.cpp files, but when i try to declare reference to C++/CLI class in some c++ header file i got tons of errors about project doesnt support CLR(CLR support in project settings as /clr is set up), it looks like header files doesnt support links to managed classes.
This works from .CPP perfectly but fails with errors when used from .H
#include "NativeBitmap.h"
using namespace Native;
NativeBitmap.H:
#pragma once
namespace Native
{
using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
public ref class NativeBitmap
{
}
}
NativeBitmap.CPP:
#include "stdafx.h"
#include "NativeBitmap.h"
using Native::NativeBitmap;
using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
void NativeBitmap::Create(...)
{
...
}
and so on ...

Adobe AIR ANE default platform can't find method name

I have an Adobe AIR ANE that builds and runs fine on iOS. I want to run this app in the AIR simulator, but with an actionscript version of the native ANE.
Reading the docs, it seems like a default profile would be perfect for this.
I added the default profile to the extension.xml file. I added a AS implementation of the native interface to every project in my workspace. I have made methods static/not static, etc. I have tried everything but I keep getting this error:
ArgumentError: Error #3500: The extension context does not have a method with the name
I am at a complete loss. Here are the relevant files:
extension.xml
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
<id>com.novel.analytics.ext.ApsalarNativeInterface</id>
<versionNumber>0.0.0</versionNumber>
<platforms>
<platform name="iPhone-ARM">
<applicationDeployment>
<nativeLibrary>libApsalarNativeInterface.a</nativeLibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
<platform name="default">
<applicationDeployment/>
</platform>
</platforms>
</extension>
My AS implementation:
package com.novel.analytics.ext
{
public class ApsalarNativeInterface
{
public function ApsalarNativeInterface()
{
}
private static function initExtension():void
{
}
public function initApsalar(apiKey:String, secret:String):void
{
}
}
}
my native interface:
package com.novel.analytics
{
import flash.external.ExtensionContext;
public class ApsalarInterface
{
private static const EXTENSION_ID : String = "com.novel.analytics.ext.ApsalarNativeInterface";
private var context : ExtensionContext;
public function ApsalarInterface()
{
this.context = ExtensionContext.createExtensionContext(EXTENSION_ID, null);
}
public function initApsalar(apiKey:String, secret:String):void
{
context.call("initApsalar", apiKey, secret);
}
}
}
Here is my adt command line (library.swf is the lib that contains the two above files:
/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adt -package -target ane ../../$PRODUCT_NAME.ane extension.xml -swc NativeInterface.swc -platform iPhone-ARM -C . library.swf -platform default -C . library.swf
Like I said, I am at a complete loss on this one.
Sorry for the much delayed response, but I think you'd benefit from checking out this wonderful tutorial:
http://www.digitalprimates.net/author/nweber/2012/04/10/building-a-native-extension-part-3/
Based on your code snippets above, it looks like you're trying to define your pure-ActionScript implementation in a different package, with a different classname. Seems you actually want to use the same package+class+method names and just store it in a different library (so it's bundled as its own SWF). Then you tell ADT how to bundle things.

The hierarchy of the type AddEntryAction is inconsistent (Jface)

i have the following class in eclipse
class AddEntryAction extends Action {
public AddEntryAction() {
super("Add Entry");
setToolTipText("Add Entry");
}
public void run() {
WizardDialog dlg = new WizardDialog(MainClass.mainWindow.getShell(),
new AddEntryWizard());
dlg.open();
}
}
and Action class extends AbstractAction which intern extends EventManager class. Both these parent classes are part of the eclipse SWT/jface libraries... I get the following error on the above class declaration
The project was not built since its
build path is incomplete. Cannot find
the class file for
org.eclipse.core.commands.common.EventManager.
Fix the build path then try building
this
project DisplayExample Unknown Java
Problem
The type
org.eclipse.core.commands.common.EventManager
cannot be resolved. It is indirectly
referenced from required .class
files MainClass.java /DisplayExample/src line
94 Java Problem
AddEntryAction is declared within the same source file MainClass.java. Actually, this is an example from Java2s.com ... I have the libraries/jars because i can see the compiles classes of all these clases
The error "The project was not built since ... org.eclipse.core.commands.common.EventManager cannot be resolved..." with swt/jface dependencies can be caused by missing reference sources or binaries containing org.eclipse.core packages in addition to org.eclipse.swt and org.eclipse.jface packages.
E.g. build path in my case included:
swt.jar
org.eclipse.jface_3.4.2.M20090107-0800.jar
Following jar was missing and caused above error:
org.eclipse.core.commands_3.4.0.I20080509-2000.jar