Linking CIL with native code - assemblies

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.

Related

Emulating a yamaha fm chip inside arduino

I want to run an audio emulator of the genesis fm sound chip inside arduino. I plan to run it on a rp2040 which has plenty of power to run it
This is the emulator code:
https://github.com/nukeykt/Nuked-OPN2/blob/master/ym3438.h
And this is how Im trying to instantiate it, but I have errors. Can you point me on how to run the emulator?
#include "ym3438.h"
int buff = 0;
ym3438_t myChip;
void setup() {
}
void loop() {
buff++;
//this should advance the emultor clock
OPN2_Clock(myChip, buff);
//this should generate the sound samples
OPN2_Generate(myChip, buff);
}
Thanks!!
When trying to compile I get:
Compilation error: cannot convert 'ym3438_t' to 'ym3438_t*' for argument '1' to 'void OPN2_Clock(ym3438_t*, Bit16s*)'
I have tried putting* like:
OPN2_Clock(myChip*, buff*);
But it does not work either. Honesty Im not sure how to instantiate it

c++/cli class implementing c++/cli interface

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.

Visual Studio not compiling

I am trying to compile my code. If I compile it in Arduino IDE it works, but if I try it in Visual Studio 2019 it fails.
I am trying to use a struct as a parameter.
I have tried pointer and typedef, but get the same error
I can compile it in Arduino IDE, but the same code gets this error in VS 2019:
Compiling debug version of 'test' for 'ATmega2560 (Mega 2560) (Arduino Mega)'
test.ino: 7:17: error: variable or field 'myFunction' declared void
Error compiling project sources
Debug build failed for project 'test'
test.ino: 7:17: error: 'data' was not declared in this scope
test.ino:7: note suggested alternative atan
atan
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct){
}
int main(){}
You did not provide a declaration for myFunction. That's done by the Arduino IDE behind the scenes.
Try:
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct);
void myFunction(data data_struct){
}
int main(){}

freebsd network program compilation

I am trying to compile some simple networking programs on freebsd 8 and running into compilation issues. I am creating a simple client-server programs but no function or structure from networking is not getting compiled.
For eg. I use standard socket() call to create a socket but I run into an error "Called object socket is not a function."
If I remove the network code then my toy program compiles. For simplicity I have just put a simple example which does not compile. :
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void main(){
int socket = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
printf("Could create sockets without any issues.\n");
}
I compiled it with "cc toy_prog.c -lc" and gave me the mentioned error.
A very simple error. You have defined a local variable with the same name as the external function you are trying to call (socket). Try the following and you will get the same error:
int f()
{
return 0;
}
void main()
{
int f = f();
}

How to start video-suite in MeeGo / Nokia N9 from Qt code?

I am having problems with launching Nokia's own video player from my application that I just don't seem to be able to solve.
My first attempt included calling
Qt.openUrlExternally(url)
from QML and that seemed to do the trick just fine, except that it opened the browser every time and used it instead of the video-suite (native player).
Next I tried cuteTube -approach where I start new process like this:
QStringList args;
args << url;
QProcess *player = new QProcess();
connect(player, SIGNAL(finished(int, QProcess::ExitStatus)), player, SLOT(deleteLater()));
player->start("/usr/bin/video-suite", args);
That worked, except that it required video-suite to be closed upon calling player->start, otherwise it did nothing.
My third attempt involved starting the video-suite via QDBus, but that didn't work any better:
QList<QVariant> args;
QStringList urls;
urls << url;
args.append(urls);
QDBusMessage message = QDBusMessage::createMethodCall(
"com.nokia.VideoSuite",
"/",
"com.nokia.maemo.meegotouch.VideoSuiteInterface",
"play");
message.setArguments(args);
message.setAutoStartService(true);
QDBusConnection bus = QDBusConnection::sessionBus();
if (bus.isConnected()) {
bus.send(message);
} else {
qDebug() << "Error, QDBus is not connected";
}
The problem with this is that it requires video-suite to be up and running - autoStartService parameter didn't help either. If video-suite isn't running already, the call opens it just fine but, alas, no video starts to play.
Eventually I tried using also VideoSuiteInterface, but even having the program compile with it seemed to be difficult. When I eventually managed to compile and link all relevant libraries, the results didn't differ from option 3 above.
So, is there a way to use either VideoSuiteInterface directly or via DBus so that it would start video playback regardless of the current state of the application?
The solution was actually simpler than I really thought initially; the VideoSuiteInterface -approach worked after all. All it took was to use it properly. Here are the full sources should anyone want to try it themselves.
player.h:
#ifndef PLAYER_H
#define PLAYER_H
#include <QObject>
#include <maemo-meegotouch-interfaces/videosuiteinterface.h>
class Player : public QObject {
Q_OBJECT
private:
VideoSuiteInterface* videosuite;
public:
Player(QObject *parent = 0);
Q_INVOKABLE void play(QString url);
};
#endif // PLAYER_H
player.cpp:
#include "player.h"
#include <QObject>
#include <QStringList>
#include <QtDeclarative>
Player::Player(QObject *parent) : QObject(parent) {}
void Player::play(QString url) {
QList<QVariant> args;
QStringList urls;
urls << url;
args.append(urls);
videosuite = new VideoSuiteInterface();
videosuite->play(urls);
}
In addition you may want to connect some signals to make the UI more responsive, but basically that should do the trick.
Finally, you need to remember to add following to your .pro file and you are good to go:
CONFIG += videosuiteinterface-maemo-meegotouch

Resources