python-sip: How to access a DLL from both Python and C++ - c++

I have a C++ GUI, it load a DLL when running. I use SIP to import the DLL in python. I need to embed the python part in the GUI, and some data are needed to exchange between python and C++.
For example, in the C++ GUI, I can enter command from a panel, such as "drawSomething()", it will call corresponding function in python, and the result will be shown in the GUI.
Can I use SIP to
extract a C++ object from python object (just like the way boost.python does), or is there a better way to share data between python and c++ seamlessly?
thanks.

It turns out that I do not need to do anything complicated...
In my case, there is no difference to call functions in DLL from C++ or from python code embedded in C++.
I am totally over-thinked.

Please take a look at this Library
http://www.swig.org/Doc1.3/Python.html

Related

Use Node.js as an interpreter

I would like to embed NodeJS in my application. The reason i would like to use NodeJS and not just the V8 directly, is because of the extensions that exist for NodeJS.
To do that i understand that i need to compile NodeJS with GYP. Got it. But how do i work with it? is there a static lib to link to? how to start it up? say i want to provide it with a V8 context, how do i pass it?
a bit at a loss here. hope for help.
Note - i want to activate nodejs from my C++ code, not the other way around. i understand extensions, this is not what i want.
Regards,
Gal.
As I got from this question the problem of immediate linking with node.js is still unsolved. Actually the workaround may be running it in a separated process like an ordinary command line application. You may save your script to file, pass it as cmdline argument, then obtain std output from the node.js executable.

how to get value from spinctrl and send it to .exe file in python script

I am new to python and wxpython, I am making a automated tool using python and for user interface wxpython and i use shell script.shell script can be called from the python. but now I am facing problem with the spinctrl value. whenever that spinctrl value changes it have to send that value into one txt.exe file which is written in BASH .{ if we run txt.exe file in command line it will ask for number then it will accept that value whenever we press enter}. but i am not able to understand that how to send value from spinctrl to txt.exe whenever i press "ok" button in GUI. please share your thoughts and knowledge.
Thank you
To call an executable in Python, you need to look at Python's subprocess module: http://docs.python.org/2/library/subprocess.html
If your exe doesn't accept arguments, then it won't work. If you created the exe yourself using something like PyInstaller or py2Exe, then you need to make it so your app can accept arguments. The simplest way is using sys.argv, but there are also the optparse and argparse libraries in Python as well.
I do not get a good feeling about your concept. It is hard to say, but I suspect you would benefit from talking with someone experienced about what you are trying to achieve and how it could best be done.
However, to get you started down your current path, I think you should take a look at wxExecute ( http://docs.wxwidgets.org/2.8/wx_processfunctions.html#wxexecute ). This will allow you to run your txt.exe utility from inside your GUI.
wxExecute is a wxWidgets utility. If you are working in python then there will be a more direct way to do this using a python utility - some-one else will have to advise on that. I suggest you edit your question for clarity so a python expert can help you.

python script to create another python script (or python executable)

As part of my code, I want to write a python method which when called, creates an executable file. (Another script that I can execute with python's interpreter is also fine).
This final script is almost fixed, except for a few input objects that only my method knows about, and which are necessary for the final executable to work (a dictionary for example). How can I link these objects to the final executable?
This sounds like a work for some templating engine. Jinja for example.
You can also use pickle to serialize/deserialize (save/load) the data which the other executables would use.

AngelScript, how to load a script file?

I know how I can bind C++ functions to AngelScript, but in my C++ code, how do I load an .as script file? How can I say in my C++ "Execute myscript.as now!" ?
In the AngelScript API I don't find any function like "LoadScript" or "ExecuteScript".
Or do I have to define a path somewhere from where AngelScript loads all scripts and I don't need to tell it the exact files?
Just found it out (in a small side sentence in the docs):
AngelScript doesn't provide a build in file loading. That's why there is no API function. So the manual loading is indeed the only way.
asIScriptModule::AddScriptSection will load a script string. asIScriptContext::Execute will execute a function from a script. The documentation was pretty clear about all of this; you might want to give it a look.

How to add a new row to Excel file using unmanaged C++?

How can I add a new row (with contents) to an existing Excel .xls file using unmanaged C++ running on Windows?
I don't mind using OLE, COM, or any external free library, whatever is the easiest way.
There is a COM interface which is well documented.
I'd suggest you start with the Workbooks.Open method to open an existing excel file.
If you only need basic features (no formatting, formula's, ...), you can also use BasicExcel: A c++ library which doesn't have any dependencies (it reads and writes the excel file as a compound file) and is much easier to use than the COM interface (at least from c++).
I've used SQL to do this. I don't have sample code handy, but a quick google search brought this up: Link
Hope its helpful.
If you have no restrictions to use managed libraries you can check NPOI, a managed library to handle Excel file format.
Since it is managed it should be possible to register it as a COM server. If, for any reason, it proves hard/impossible to register it as a COM server you can write a thin COM server (either in C++ or C# or whatever you prefer) to expose just the functionality you need to your unmanaged C++ code.
I've used this one: ExcelFormatLib, it's great and simple to use, C++, well maintained, compiles and works without any trouble.