Saxon .NET with C++ CLI - c++

I had an idea to use C++ CLI to interact with the Saxon .NET interface . The problem is that every single example on Saxonica is with C# , and not C++ . can you give me an example that caches an XML file , and using Xslt filepaths to transform it using C++ CLI to use the .NET interface ???
Also pls dont give me workarounds that dont use C++ CLI

A minimal sample using Saxon .NET HE 10 (tested with 10.6 initially, now updated to 10.7) run on Windows against .NET framework 4.8 is e.g.
#include "pch.h"
using namespace System;
using namespace Saxon::Api;
int main(array<System::String ^> ^args)
{
Processor^ processor = gcnew Processor();
Console::WriteLine(processor->ProductVersion);
DocumentBuilder^ docBuilder = processor->NewDocumentBuilder();
Uri^ baseUri = gcnew Uri(System::Environment::CurrentDirectory + "\\");
XdmNode^ inputDoc = docBuilder->Build(gcnew Uri(baseUri, "input-sample1.xml"));
XsltCompiler^ xsltCompiler = processor->NewXsltCompiler();
xsltCompiler->BaseUri = baseUri;
XsltExecutable^ xsltExecutable = xsltCompiler->Compile(gcnew Uri(baseUri, "sheet1.xsl"));
Xslt30Transformer^ xslt30Transformer = xsltExecutable->Load30();
xslt30Transformer->ApplyTemplates(inputDoc, processor->NewSerializer(Console::Out));
return 0;
}
Example project at https://github.com/martin-honnen/SaxonHECLIExample1.
To write to a file instead, use e.g.
FileStream^ resultStream = File::OpenWrite("result1.xml");
xslt30Transformer->ApplyTemplates(inputDoc, processor->NewSerializer(resultStream));
resultStream->Close();
instead of xslt30Transformer->ApplyTemplates(inputDoc, processor->NewSerializer(Console::Out));; example adaption is at https://github.com/martin-honnen/SaxonHECLIExample1/tree/WriteToFileInsteadOfConsole

Related

Mixing Objective-c with C++ to create local notification in notification center on osx

I am really a newbie in osX development environment. My application is developed for cross-platform, written in C++ without using any framework and non-gui. I want to add notification mechanism to my application for osX. My os version is Monterey now.
I tried to write an application by inspiring from this repo objective-c in c. But this repository is using a deprecated method that NSUserNotificationCenter. Apple recommends that method create any local notification.
After then wrote this code,
#define OBJC_OLD_DISPATCH_PROTOTYPES 1
#include <CoreFoundation/CoreFoundation.h>
#include <objc/objc-runtime.h>
int main(int argc, char** argv) {
Class contentClass = objc_getClass("UNMutableNotificationContent");
id content = objc_msgSend((id)contentClass, sel_registerName("alloc"), sel_registerName("init"));
Ivar titleIvar = class_getInstanceVariable(contentClass, "title");
object_setIvar((id)contentClass, titleIvar, objc_msgSend((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "asdas"));
Ivar bodyIvar = class_getInstanceVariable(contentClass, "body");
object_setIvar((id)contentClass, bodyIvar, objc_msgSend((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "asdasdasdasd"));
id notificationTrigger = objc_msgSend((id)objc_getClass("UNTimeIntervalNotificationTrigger"), sel_registerName("triggerWithTimeInterval:repeats:"), 5, true);
id notificationRequest = objc_msgSend((id)objc_getClass("UNNotificationRequest"), sel_registerName("requestWithIdentifier:content:trigger:"), objc_msgSend((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "FiveSecond"), (id)contentClass, notificationTrigger);
id center = objc_msgSend((id)objc_getClass("UNUserNotificationCenter"), sel_registerName("currentNotificationCenter"));
objc_msgSend(center, sel_registerName("addNotificationRequest:"), notificationRequest);
return 0;
}
but it did not work. May I have misunderstood the usage of the runtime library of Objective-c.
I don`t want to migrate my application to any language, it should keep in C++.

how to call uwp class library in win32 C++ console application

I wanna call a uwp app with Uri in a win32 C++ console application.The first thing I thought is using LaunchUriAsync, but I couldn't find Windows.System.Launcher.LaunchUriAsync in win32 C++. So I wanna create a uwp class library to call LaunchUriAsync and win32 call this library. I find an example and now I can load the library sucessfully, but GetProcAddress always returns null. Not sure whether it is feasible calling uwp class library in win32 console. Pls help me out. The project is at https://github.com/vincent1000/win32CallUwpLibrary
The code is very simple:
UWP Classy Library:
namespace ExportedCodeSolution
{
public class Class1
{
[DllExport(ExportName = "callUri", CallingConvention = CallingConvention.StdCall)]
static public async void callUri()
{
Console.WriteLine("call URI start");
await Launcher.LaunchUriAsync(new Uri("www.bing.com"));
}
}
}
And Win32 Console:
using CallUriFn = void(__stdcall*) ();
int main()
{
HMODULE mod = LoadLibraryA("ExportedCodeSolution.dll");
CallUriFn fn = reinterpret_cast<CallUriFn>(GetProcAddress(mod, "callUri"));
fn();
}
Also, is any other method to call LaunchUriAsync in win32? I have searched some methods but none works for me.
The solution is trivial: Simply call Launcher.LaunchUriAsync from your console application. The easiest route is to use C++/WinRT. Assuming that you are using Visual Studio with the C++/WinRT extension installed, create a "Windows Console Application (C++/WinRT)", and replace the wizard generated code with this:
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.System.h>
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::System;
int main()
{
init_apartment();
Uri uri(L"www.bing.com");
Launcher::LaunchUriAsync(uri).get();
}
This will compile, but fail at runtime due to "www.bing.com" not being a valid URI. This needs to be replaced with a valid URI (e.g. "https://www.bing.com").

xmlserialization without managed code?

Is there a possibility to use xmlwriter (xmlserialization) without managed code (cli)?
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::Xml::Serialization;
My XML serialization managed code:
void TXML_Interface::LoadXML( String^ filename )
{
XmlSerializer^ serializer = gcnew XmlSerializer( TTEST::typeid );
FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
XmlReader^ reader = gcnew XmlTextReader( fs );
m_test = dynamic_cast<TTEST^>(serializer->Deserialize( reader ));
}
Yes and no.
Yes it is possible to do XML maniuplation (including serialisation) without managed code - I'd normally do this using MSXML however there are various ways to perform xml serialisation in C++ (I'm not really a C++ person but Google is almost certainly the first place to look).
However this is using a different mechanism from the ones contained in the System.Xml.Serialization namespace. Unfortunately for you the Xml serialisation in .Net is all implemented in managed code, and so if you want to use it you will need to call into managed code (e.g. by using the /clr compiler option or COM interop).
Maybe the boost::serialization libary is what you are looking for.
Serialization capabilities are rather limited in C++ so boost::serialization is more like a framework that enable you to make your own classes serializable.

Dynamics Solomon Customization

My company wants me to create a custom screen in solomon to load some data from a table in the database.
They said used visual studio .net and i see manuals it says use VBA.
What should I use? VBA or visual studio 5?
How do I create a new application?
We got similar request from our customer. We're using Dynamics Solomon 2011. After doing some research, we found that we will need to create a development environment by installing VS 2008 first and then install Solomon over it. Installing Solomon after VS will setup some project templates in Visual Studio for Solomon development.
https://community.dynamics.com/product/sl/f/35/t/80585.aspx
There is some talks also that VS 2010 is not recommended for use when developing for Dynamics Solomon.
I believe also that there is SDK for Dynamics Solomon that you can use inside you application to connect to Solomon database and use data objects. We didn't try this yet but we found some references talking about developing code using this SDK.
http://www.microsoftdynamicsforums.com/forums/forum_posts.asp?TID=191&title=solomon-Object-model-code
Below is a sample code that uses Solomon SDK:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Dynamics.SL.ObjectModel;
using System.Threading;
using System.Runtime.InteropServices;
namespace LoginSL
{
class Program
{
[DllImport("kernel32")]
static extern void Sleep(uint dwMilliseconds);
public static Microsoft.Dynamics.SL.ObjectModel.SIVToolbar sivTB;
public static Microsoft.Dynamics.SL.ObjectModel.SIVApplication sivApp;
static void Main(string[] args)
{
sivTB = new SIVToolbar();
sivTB.Login("servername", "systemdb", "company", "username", "password");
sivApp = sivTB.StartApplication("9850000.exe");
sivApp.Visible = true;
string datafile = "C:\\0101000.DTA";
string ctrlfile = "C:\\0101000.ctl";
string outfile = "C:\\0101000.log";
//In C# "\\" is the predefined escape sequence for backslash.
sivApp.Controls["cdata"].Value = (datafile.ToUpper());
sivApp.Controls["cfiletype"].Value = "ASCII";
sivApp.Controls["cscreen"].Value = "0101000";
sivApp.Controls["ccontrol"].Value = (ctrlfile.ToUpper());
sivApp.Controls["coutput"].Value = (outfile.ToUpper());
sivApp.Controls["cBegProcessing"].Value = true;
Sleep(5000); //remove the comment marks at the beginning of this line for workaround
sivApp.Quit();
sivApp.Dispose();
//GC.Collect();
//GC.WaitForPendingFinalizers();
//GC.Collect();
Sleep(5000); //remove the comment marks at the beginning of this line for workaround
sivTB.Logout();
sivTB.Quit();
sivTB.Dispose();
//GC.Collect();
//GC.WaitForPendingFinalizers();
//GC.Collect();
//MessageBox.Show("TI is complete"); // Displays complete message
}
}
}

C++\IronPython integration example code?

I'm looking for a simple example code for C++\IronPython integration, i.e. embedding python code inside a C++, or better yet, Visual C++ program.
The example code should include: how to share objects between the languages, how to call functions\methods back and forth etc...
Also, an explicit setup procedure would help too. (How to include the Python runtime dll in Visual Studio etc...)
I've found a nice example for C#\IronPython here, but couldn't find C++\IronPython example code.
UPDATE - I've written a more generic example (plus a link to a zip file containing the entire VS2008 project) as entry on my blog here.
Sorry, I am so late to the game, but here is how I have integrated IronPython into a C++/cli app in Visual Studio 2008 - .net 3.5. (actually mixed mode app with C/C++)
I write add-ons for a map making applicaiton written in Assembly. The API is exposed so that C/C++ add-ons can be written. I mix C/C++ with C++/cli. Some of the elements from this example are from the API (such as XPCALL and CmdEnd() - please just ignore them)
///////////////////////////////////////////////////////////////////////
void XPCALL PythonCmd2(int Result, int Result1, int Result2)
{
if(Result==X_OK)
{
try
{
String^ filename = gcnew String(txtFileName);
String^ path = Assembly::GetExecutingAssembly()->Location;
ScriptEngine^ engine = Python::CreateEngine();
ScriptScope^ scope = engine->CreateScope();
ScriptSource^ source = engine->CreateScriptSourceFromFile(String::Concat(Path::GetDirectoryName(path), "\\scripts\\", filename + ".py"));
scope->SetVariable("DrawingList", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingList::typeid));
scope->SetVariable("DrawingElement", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingElement::typeid));
scope->SetVariable("DrawingPath", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingPath::typeid));
scope->SetVariable("Node", DynamicHelpers::GetPythonTypeFromType(AddIn::Node::typeid));
source->Execute(scope);
}
catch(Exception ^e)
{
Console::WriteLine(e->ToString());
CmdEnd();
}
}
else
{
CmdEnd();
}
}
///////////////////////////////////////////////////////////////////////////////
As you can see, I expose to IronPython some objects (DrawingList, DrawingElement, DrawingPath & Node). These objects are C++/cli objects that I created to expose "things" to IronPython.
When the C++/cli source->Execute(scope) line is called, the only python line
to run is the DrawingList.RequestData.
RequestData takes a delegate and a data type.
When the C++/cli code is done, it calls the delegate pointing to the
function "diamond"
In the function diamond it retrieves the requested data with the call to
DrawingList.RequestedValue() The call to DrawingList.AddElement(dp) adds the
new element to the Applications visual Database.
And lastly the call to DrawingList.EndCommand() tells the FastCAD engine to
clean up and end the running of the plugin.
import clr
def diamond(Result1, Result2, Result3):
if(Result1 == 0):
dp = DrawingPath()
dp.drawingStuff.EntityColor = 2
dp.drawingStuff.SecondEntityColor = 2
n = DrawingList.RequestedValue()
dp.Nodes.Add(Node(n.X-50,n.Y+25))
dp.Nodes.Add(Node(n.X-25,n.Y+50))
dp.Nodes.Add(Node(n.X+25,n.Y+50))
dp.Nodes.Add(Node(n.X+50,n.Y+25))
dp.Nodes.Add(Node(n.X,n.Y-40))
DrawingList.AddElement(dp)
DrawingList.EndCommand()
DrawingList.RequestData(diamond, DrawingList.RequestType.PointType)
I hope this is what you were looking for.
If you don't need .NET functionality, you could rely on embedding Python instead of IronPython. See Python's documentation on Embedding Python in Another Application for more info and an example. If you don't mind being dependent on BOOST, you could try out its Python integration library.