I have a SDK that will communicate with my Scanner device that is written in C++ language. I need to develop an Electron App that can access the Scanner device. I know there are many libraries available for scanner but I want to use this SDK since it will allow me to access full feature of the device and moreover it is provided by the device manufacturer. So, is there any way to implement this. Please suggest me any idea.
You can use the native V8 API for that. You will need to provide a layer over your C++ code and expose it as Javascript entities.
if there's also a C-style interface you could use node-ffi https://github.com/node-ffi/node-ffi
If you're using electron 3 (which in turn uses Node 10), you can use N-API which has great examples on how to wrap a C++ object into a JS object. N-API is stable and supported by Node 10, so it's a pretty good choice over NaN and node-addon-api for the long term.
https://nodejs.org/api/n-api.html
Here's a repository of examples that proves pretty useful. This one specifically is for wrapping C++ objects.
https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/6_object_wrap/napi
Related
We have a lot of business logic written in cross-platform C++. We want to write cross-platform UI for our application and use this business logic to create whole cross-platfrom application.
Is it possible to expose native module purely written in C++ to react-native?
We don't want to create wrappers around C++ code in native language (Java or Objective-C). Such wrappers will add more complexity it will make debugging and investigation much harder.
I am also looking for a way to do this directly in C++ without writing JNI for Android and Obj-C for iOS. I have found the CxxNativeModule class in the react native source. See the sample implementation SampleCxxModule.
The last thing to figure out is how to register that module in C++. In the JNI for React Native Android, implementation of NativeModule says
NativeModules whose implementation is written in C++ must not provide
any Java code (so they can be reused on other platforms), and instead
should register themselves using CxxModuleWrapper.
Then implementation of CxxModuleWrapper says
This does nothing interesting, except avoid breaking existing code.
So, this may help you get started. The last thing to figure out is how to register a CxxNativeModule so that it can be used in JS.
It seems as though you would need to find the code which is os dependent and write different versions of this code for different operating systems.
Here is a link which suggests how this might be done:
How do I check OS with a preprocessor directive?
With native c++, I mean, not managed c++, not cli, not any special things from microsoft, I can:
1) get high performance
2) use existing c++ code library and engine
3) write cross platform code (for example, for ios and android)
it needn't be fully native c++, I can use managed code to do the ui things, like object-c in ios and java in android, but beside interface, can I use native c++ code?
I suggest you have a look at the presentation here: Using the Windows Runtime from C++ and especially at the comments from Herb Sutter. I quote:
Please answer this question: If I decide to write C++ GUI application
in Metro style am I forced to use all these proprietary ref, sealed,
^, Platform::String^ extensions for GUI components or not?
#Tomas: No, you are not forced to use them. We are providing two
supported ways:
1) These language extensions (C++/CX).
2) A C++ template library (WRL), see
Windows Kits\8.0\Include\winrt\wrl as Yannick mentioned. WRL is a C++
library-based solution sort of along the lines of ATL, which offers
what I think you're looking for -- template wrapper/convenience
classes and explicit smart pointers and such.
Yes you absolutely can, real native C++ is fully supported.
You do however mostly have to use the new WinRT libraries to do an user interface or system calls and although they are native code and fully callable from C++ directly the interface to them makes it very painful indeed to do so, as everything is a reference counted COM object and in addition it's not so easy to create instances of them as just calling "new" so you have to write a lot of ugly code to do so.
As the earlier answer said, microsoft provide two ways to help with this. One is via language extensions to c++ and the other is a c++ template library. Personally I consider both to be rather ugly for doing something as simple as calling an API but that's just me :)
But to answer your question, it's completely possible to write your application in real native c++. You won't need to use managed code at all for anything. But you'll probably want to use either the language extensions or the template library to make calling the API more easy.
Personally I'm hoping someone writes a wrapper for WinRT that exposes the most necessary functionality as a more usable c++ native library and then everyone can just use that from c++ instead...
I am not sure if the title of this question gets to the point. I have written a large software system in C C++ for Windows, and want to give the users of this system the option to add compiled code to it. The user should be able to do basic stuff, and exchange data with my program.
Currently the implemented way is via DLLs. But for this, a grown up compiler is needed, and it is not as easy as I wished. Is there a tiny C compiler that can create Windows DLLs?
Another idea is the Java native interface. But this requires a complete Java system to run in the background, and it is not easy to run code in it.
Do you have any other ideas?
Any interpreted language? (TCL and Lua were designed as extension languages, but you can nearly as easily interface with any other).
How about python integration?
You could create an python interface that interfaces with your application. Python is rather easy to learn and should integrate easily with c/c++. The python documentation has an own chapter on that.
You could also use a tool like swig to generate the interface.
The advantage of this is that they wouldn't have to compile anything. They could just supply python files that could be loaded into your application and run within the software. This is a well known use for python, and something its simple syntax promotes.
As the other says you will be best of by providing an embedded language.
I would chip in for javascript and use the google v8 engine
By using javascript you get a language nearly everbody can use and program in.
There is other javascript engines you can embed like SpiderMonkey.
See this answer for what to choose.
An interpreted language is not good enough. I need speed. The software itself is an interpreted language. So I added support for the tiny C compiler. It is only C, and I do check mingw, which probably would not be as tiny as this. Thanks for all your hints.
Added after several months:
I have now two tools, actually: TinyC and Python. The speed difference between those is noticable (factor 5-10), but that usually does not matter too much. Python is much easier for the user, though I managed to integrate both into the Euler GUI quite nicely.
One of the ways is to add scripting. You application can host scripting environment and expose its services there. Users would be able to execute JScript/VBScript scripts and interact with your application. The advantage is that with reasonable effort you can get the power of well known and well documented scripting languages into your application (I suppose there is even debugger for scripting there). You will be required to shape your app services as COM interfaces and scripts will be able to access them automatically using method names you assigned on C++ side.
C++, Win32 and Scripting: Quick way to add Scripting support to your applications
MSDN Entry Point - IActiveScript interface
The MSDN documentation for WMPLIB states that syncing to device is not supported in .NET programming, only C++.
Is there, however, a simple wrapper class or DLL that can be used to interface between a .NET program and the nescessary C++ code?
Or is there a better way to sync files to a device using VB.NET? Are all devices suited/compatible with just a simple filesystem.copyfile ?
I don't know of any existing wrapper. Maybe others can help out with that.
Have you tried C++/CLI? You can write a simple C++/CLI project that can interop with C/C++, but its functions are visible from other .NET languages, just like C# or VB.NET. We've had a lot of success wrapping C++ code using C++/CLI, I recommend it.
We have an old application which has a FORTRAN API to be called from other applications. After some time they built a ( C ) wrapper for the FORTRAN API.Then I'm now building a c++ wrapper , with a little data handling , for the C API.
So I'm thinking what is the best way of building an API that can be called from any programming language.
Now I'm planning to bulde RPC server from my c++ API. Then any client using any programming language can call it.
I found that the XML-RPC is a good one. But it needs HTTP server for connection.
The problem is that the applications that call our API are desktop applications.And I found that XML-RPC can not manipulate complex objects.
Is SOAP a good solution? Can the client side be easily implemented?
So what is the best technical solution for my situation? Which technology should I use?
comment: I do not have a permission for changing the Fortran API and the C API. And I need the c++ API because I'm adding to it new methods , and enhancing the code so the user can call the methods easily.
Best Regards,
The best way is to leave it alone and just use the C API. virtually all programming languages can directly call a C API, so there's no reason to create wrappers unless a particular language's programming model makes more sense a different way.
To clarify what I mean, look at GTK+. It is a C API and is usable in virtually any language. Wrappers exist in object-oriented languages that provide a pure-OOP approach to the GTK+ API because it makes sense for those languages, given the domain of the API.
Does an objectified interface make sense for your application? If not, there is no reason to bother making a C++ wrapper.
As to RPC, why doesn't a simple message-passing interface with shared memory suffice?
Any decent language has a foreign function API. Just call the Fortran functions directly. The compiler documentation will tell you how - calling Fortran in a shared library is very similar to calling C in a shared library, except different compliers may normalise the function names to lower case or not, or may add an underscore. Some FFIs may require some C wrapper code - Java for example - but many can just take a function name and parameter types and the name of the library to load.
Failing that, you can implement a streaming interface to the Fortran (read and write to standard output) and just pipe input to and from it - I've done that when quickly porting interactive ISPF Fortran applications to PC.
Since you want to expose the C++ API and extensions rather than the Fortran API, then look at SWIG, which automates the process for a variety of languages, as long as the C++ isn't too complicated.
SOAP, XML-RPC ect are normally used for computer to computer communication, is this what you want? Or is this all just running on one comuputer?
If it's just on one computer, just stick with C API, most systems can use that
If you model the C API as a REST style service, then you can also provide a HTTP service for applications that can't use the C API without, but only have one system to document