c++/cli class implementing c++/cli interface - .net-core

I am working in Visual Studio 2022, building a Windows 10 solution with a mixture of native c++, c++/cli, and .NET 6.
I am defining a clr interface in a c++/cli project. The interface methods return types are native pointers and references. The native types are defined in a c++ project. Another c++/cli project should implement the clr interface, however there is a problem with the native types. The error is
Error C2553 'BusinessLogic::IRepository<int,std::shared_ptr<E>> &NlohmannJsonPersistence::JsonRepositoryManager::getProbeRepoRef(void)': overriding virtual function return type differs from 'BusinessLogic::IRepository<int,std::shared_ptr<Domain::Probe> > &NetGateways::IProbeRepository::getProbeRepoRef(void)'
The project with the implementing class, NlohmannJsonPersistence, has a project reference to the project with the interface, NetGateways.
Here is the interface definition in NetGateways:
#pragma once
#include <IRepository.h>
#include <Probe.h>
namespace NetGateways {
public interface class IProbeRepository {
public:
BusinessLogic::IRepository<int, std::shared_ptr<Domain::Probe>>& getProbeRepoRef();
};
}
Here is the implementation in NlohmannJsonPersistance:
#pragma once
#using <NetGateways.dll>
#include <Probe.h>
#include <ProbeFileRepository.h>
#include "NlohmannJSONReaderWriter.h"
namespace NlohmannJsonPersistence {
public ref class JsonRepositoryManager :
public NetGateways::IProbeRepository
{
private:
System::String^ rootDirectory;
Infrastructure::ProbeFileRepository* probeRepo;
public:
JsonRepositoryManager(System::String^ rootDirectory);
~JsonRepositoryManager();
// Inherited via IProbeRepository
virtual BusinessLogic::IRepository<int, std::shared_ptr<Domain::Probe>>& getProbeRepoRef();
};
}
I have tried removing the project reference and importing the interfaces header into NlohmannJsonPersistence but that creates ambiguity in the UI project that depends on NlohmannJsonPersistence and NetGateways. I have also tried removing the #using statement but that produces the same error. Keeping the project reference and including the interface header creates a redifinition error. I think that the issue is that the native Domain::Probe object is compiled into CLI, so when I include the Probe header from the native project, it is incompatible.

Related

library module upgrade to Glide 4, where should the AppGlideModule be put in

In library module to upgrade to Glide 4.9.0.
api "com.github.bumptech.glide:glide:4.9.0"
api "com.github.bumptech.glide:annotations:4.9.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.9.0"
and having a kotlin extension
fun ImageView.loadImg(imageUrl: String) {
// 4.+ code
var requestOptions : RequestOptions = RequestOptions()
.placeholder(ColorDrawable(Color.LTGRAY))
.diskCacheStrategy(DiskCacheStrategy.ALL)
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(context)
.setDefaultRequestOptions(requestOptions) // or use .apply(requestOptions) but after the .load()
.asBitmap()
.load(imageUrl)
.into(this)
}
}
but it crashes
java.lang.AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"
at com.bumptech.glide.Glide.initializeGlide(Glide.java:270)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:223)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:184)
at com.bumptech.glide.Glide.get(Glide.java:168)
at com.bumptech.glide.Glide.getRetriever(Glide.java:689)
at com.bumptech.glide.Glide.with(Glide.java:716)
at com.common.extentions.ExtensionsKt.loadImg(Extensions.kt:44)
After adding
#GlideModule
class TheAppGlideModule : AppGlideModule() {
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
to the library module does not help, or adding it to hosting app only does not work either,
but after adding it to both the library module and the hosting app the crash goes away.
according to documentation https://bumptech.github.io/glide/doc/generatedapi.html,
isnt it that it not supposed to have this class defined in the library module?
anyone has same experience?
* For now the API is only generated when a properly annotated AppGlideModule is found.
* There can only be one AppGlideModule per application.
* As a result it’s not possible to generate the API for a library without precluding any application
* that uses the library from using the generated API.
Resolved, it has missed
api "com.github.bumptech.glide:annotations:$versions.glide"
in the application side (not sure why adding single one in the module did not work and why with both it worked, maybe didnt do clear/rebuild after change?)

Extensible ASP.NET Core 2 application

I need to create an ASP.NET Core 2 application that can be extensible.
An extension, is a project that reference the main assembly and can extends it adding new controllers, models (with EF migrations), views, razor pages, etc.
Because the extensions need use the main application base classes like base controller, base model or view/page layout, the main application cannot reference the module project (avoid circular references).
I'm not sure how can I achieve this, but the idea is an installation of the main project, can add new functionality simple putting the modules DLL (or by online market in the main application, that download the DLL).
In my research, I found Applications parts, but my problem here is I need specify the part assembly in Startup class, and I need in installed the capacity of install modules without doing any changes in the code.
Some modules, need be extensible too, for example, an accounting module, need to connect with bank, and it have an interface that defines the methods of working with the bank, for example:
public interface IBankingOperation
{
public async void PayInvoiceAsync(Invoice invoice);
// More methods...
}
Then, differents projects can reference the banking assembly and provide implementation for differents banks.
In the main application, this modules can be installed like other modules, but checking the base module is intalled, for example, I can install the Santander module like other module, but only if banking module is installed (module dependency).
In conclusion, I need to create a modular ASP.NET Core 2 application, but the main assembly cannot reference the modules, the modules must reference the main assembly. The modules can contain Controllers, Models, Views, Pages, Etc.
In the main web app you would call a class which loads the extensions in the memory
ModuleManager.LoadModules(Path.Combine(_env.ContentRootPath, "Modules"));
this is the load modules function
public static void LoadModules(string modulesFolder)
{
var appsFolders = new DirectoryInfo(modulesFolder).GetDirectories();
foreach (var appFolder in appsFolders)
{
var binFolder = new DirectoryInfo(Path.Combine(appFolder.FullName, "bin"));
if (!binFolder.Exists)
{
continue;
}
var assemblies = AssemblyProvider.GetAssemblies(binFolder.FullName);
foreach (var assembly in assemblies)
{
var iModuleClass = assembly.GetTypes().FirstOrDefault(type => type.GetInterfaces().Contains(typeof(IModule))
&& type.GetConstructor(Type.EmptyTypes) != null);
if (iModuleClass != null)
{
var module = Activator.CreateInstance(iModuleClass) as IModule;
module.ModuleFolder = appFolder;
Modules.Add(module);
Assemblies.Add(assembly);
break;
}
}
}
}
then you should have an interface which should be implemented by each module the class which implement this interface should do the work of registering services and database models and all staff needed and you will load them as follows
public static IEnumerable<IExtensionRegister> GetModuleRegistrars()
{
lock (Modules)
{
return Modules.Select(item => item.Registrar).Where(item=>item!=null).ToList();
}
}

Qt C++ Q_OBJECT error undefined reference to vtable

I am constantly running into problems while using the Q_OBJECT macro: (I use QT Creator 2.8.1 / Qt 4.8.4) I asked before but it seems to be leading to even more trouble. Can anybody help me? I am totally lost .
I have a huge C++ program with about 50+ classes to adapt to new needs.
Now I created a new (very simple) parent-class and 3 child classes in a new directory within the src-directory. To do so I used the template Qt->Qt Designer Form Class.( I did that because this automatically implements Q_OBJECT even though I do not need a *.ui-file. I then removed all concerning ui-Fileand the ui-file itself))
When I run my program I always get lots of „ undefined reference to vtable for“ ..-errors. When I remove all Q_OBJECT my program runs OK. But then I am not able to use signal-slots which I would need later on.
I looked it up in the internet and found out it has something to do with the .pro-file/.o-Files in my build-directory. I (several times) tried to delete all .o-Files including the .pro.user and compile again. Sometimes I still got the error, sometimes not.
This is my code ( the 3 child classes are the same at the moment):
geometry.h:
#ifndef GEOMETRY_H
#define GEOMETRY_H
#include <QMetaType>
#include <QWidget>
#include <QObject>
#include <QDebug>
class Geometry
{
Q_OBJECT
protected:
public:
Geometry();
virtual ~Geometry(void) {}
virtual void write_LNE();
//Q_DECLARE_METATYPE(Geometry);
#endif // GEOMETRY_H
-
geometry.cpp:
#include "geometry.h"
Geometry::Geometry()
{ qDebug() << "Constructor: hier ist Geometry"; }
void Geometry::Haupt()
{ qDebug() << " Das hier ist die Haupt von Geometry ....." ; }
void Geometry::write_LNE(){}
-
Geo_1PF.h:
#ifndef GEO_1PF_H
#define GEO_1PF_H
#include "geometry.h"
class Geo_1PF : public Geometry
{
Q_OBJECT
public:
Geo_1PF();
~Geo_1PF() {}
virtual void write_LNE();
};
//Q_DECLARE_METATYPE(Geo_1PF);
#endif // GEO_1PF_H
Geo_1PF.cpp:
#include "Geo_1PF.h"
Geo_1PF::Geo_1PF()
{
}
I found the advice to do qmake manually. I never used qmake manually.
How and from which directory do I do this ? Exactly what do I write qmake …….?
Is it correct to use the template Qt->Qt Designer Form Class to create these classes?
Do I have to create the classes in another directory?
Are there any additional entries I have to make in the +.pro-File
and where in the file do they have tob be put?
Do I have to change anything in my makefile? And if so what?
Thank you
If you use Qt Creator:
Everytime you create a class using Q_OBJECT,
Build → Run qmake
Build → Rebuild All
To use the QOBJECT macro in your class you need to extend QObject.
class MyObject: public QObject
{
Q_OBJECT
public:
MyObject (QObject *_parent);
.....
};

Flex / Parsley - Internal class quirk with compile mode

This is a puzzler.
Relevant Environment: Flex app, running parsley, which gets built by ant.
Problem class:
package com.foo.bar {
public class ProblemClass {
// constructor
public ProblemClass(enforcer:Enforcer) {}
public static function build():ProblemClass {
// Do some setup
return new ProblemClass(new Enforcer())
}
}
// internal private class
class Enforcer() {}
Elsewhere, in a seperate class (which gets defined in a Parsley context):
package com.foo.bar {
public class ProblemClassBuilder {
[Factory]
public function getProblem():ProblemClass {
return ProblemClass.build();
}
}
}
Here's the kicker:
When I compile this from an ant task with debug="true", it works fine. When I compile it with debug="false", parsley throws an error while building the context:
Error applying [object
FactoryMethodDecorator]: Error #1065:
Variable Enforcer is not defined.
No other code changes, except turning debug on / off in the mxmlc ant task.
Has anyone seen similar problems with internal classes & ant debug compile modes?
I've been able to fix the issue, (by removing the internal class), but don't understand why it didn't work in the first place.
Sounds like a bug in the compiler... I'd file it at bugs.adobe.com
you are only allowed one class definition per actionscript file, otherwise you have to use the internal keyword so it should be private internal class Enforcer()

Linking CIL with native code

In C++/CLI the following is sample code that links native and managed code within the same file.
#include "stdafx.h"
#pragma unmanaged
__declspec( dllexport ) void func2()
{
//native code goes here
}
#pragma managed
void func_clr()
{
func2(); //managed code calls native
}
#pragma unmanaged
__declspec( dllexport ) void func()
{
func_clr(); //native calls managed
}
#pragma managed
I am trying to experiment in getting other languages to link with managed code. I can compile other languages with the available tools and can compile CIL with ilasm. Ilasm produces the final .dll/.exe directly and I cant figure out a way to link in .obj files from other compilers.

Resources