Is it possible to create a PHP Extension using C#?
We have a need to connect PHP to in house libraries we have written in C#.NET 4.6 targeting Windows and would like to be as close as possible to PHP without needing to have a serivce we can call external to php, thus the idea of making an extension in house.
I've looked at a couple options:
Use PHP DOTNET extension to call C# assembly.
As far as I can tell this extension does not work with .NET 4+ and the C# code requires 4.6 sadly.
Write a PHP extension.
So far I have only seen examples for Windows using Win32 and C++, idealy it would be nice if the extension could be written in C#. I have thoughts on making a lib using the C# code we need, then utilizing that inside the Win32/C++ extension and trying that if I absolutly have to.
Call the C# code as an external service.
As a very last option this would be viable and I can see this being more flexible for other sources to use (i.e. PHP, Java, C#, etc)
It would be interesting to be able to write a PHP Extension using C# assuming this is possible. I can see how this may not be the "best" option if it is possible though.
Thanks for reading and advice!!!
Coming off of #SevaAlekseyev idea I was able to get PHP to call C# using COM.
<?php
$object = new COM('ComClassExample.ComClassExample');
echo '1 and 1 added: ' . $object->AddTheseUp(1,1);
?>
Using the following site I was able to make a C# dll that exposed itself like a COM object. https://whoisburiedhere.wordpress.com/2011/07/12/creating-a-com-object-from-scratch-with-c/
And with a little tweak to the Post-build event I was able to get the new version to load for PHP (had to copy because PHP was getting an access denied message)
iisreset /stop
copy /Y "$(TargetPath)" C:\com\$(TargetFileName)
$(frameworkdir)\$(frameworkversion)\regasm.exe C:\com\$(TargetFileName) /codebase /tlb /nologo
iisreset /start
#JuanDelaCruz Peachpie looks like an interesting tool to keep in mind but it looks like it is meant to be compiled before deployment which wont work in our shop for the moment.
Thanks all!
Related
I'm beginner to C# and have to develop some C# code under linux.
Until now, I could work it all out in a single file, just by using the two commands mcs and mono, without any GUI. And if possible, I'd like to avoid the GUI.
But now I want to seperate code in different files or even folders, but I could not find any explanation online.
Let's say I have some code like this
public class SpecialVector
{
// some code
}
in some special.cs file. How can I use SpecialVector in some other file, let's say normal.cs? (Btw how do you call code grouped in a file in C#?)
Excuse me if this question has already been asked, but I don't know how to twist it so that the search engine understands my problem...
As has been mentioned in the comments, if you aren't limited to Mono for a particular reason, you are highly encouraged to switch to .NET Core (now called .NET as of version 5). It has native support for both Windows, Mac and Linux, and comes with command line tools that allow you to create and build entire multi-file projects in a single command, without having to specify each individual file manually.
That being said, if you continue using Mono, you can specify multiple files to the compiler in the following manner:
mcs File1.cs File2.cs
(and so on)
Have a look at the man page for mcs for more info.
In my application, I have provision to run Python scripts through IronPython. In one of the requirement, the data from my C# application should be displayed in 3D using Visualization Toolkit. When I try to use VTK in a script and execute it, I get "ImportError: No module named vtk" error. I have searched for file named vtkCommonPython.pyd but cannot find it on my computer. Should Python be installed even after installing IronPython? What is the correct way to use VTK from IronPython?
In most cases, IronPython does not work with native/CPython modules like what vtkCommonPython.pyd seems to be. You will probably want to look at .NET bindings for VTK in order to use it from your IronPython scripts.
ActiViz.NET might be what you should be using. Wiki/Documentation, Download
Other modules containing only pure python should typically work fine. It's 'just' the native extensions that do not work as there is no easy (and built-in) way to make native code callable from .NET/IronPython using the same conventions as in CPython.
For additional info see the FAQ ('Compatibility') and the issue tracker.
You might also want to keep an eye on the recent effort to revive and port ironclad to IronPython 2.7. This project aims to provide the marshalling layer required to invoke CPython modules.
I've delved into trying to use the FatSecret REST API directly from code, but getting it to work correctly has been pretty difficult. On my quest to get it working I ran into a FatSecret C# wrapper that looked appealing, found here:
https://fatsecretsharp.codeplex.com/
When I downloaded the folder from that site I found two files:
- FatSecretSharp.Win.dll
- FatSecretSharp.Win
What I wonder is how to actually include these files in a C# project and start using the wrapper.
Looks like I just needed to go to solution references and add the win.dll.
Is it possible to make from a HTML5-APP (PHP,SQLITE,HTML,CSS,JS) a installable Windows Software in c#?
The software must start PHP (5.4), and must just load the document-root in the webbrowser object.
In theory it should work without problems. But what about protecting this code? Is it possible to protect at least the PHP part? Will ioncube or zend-guard work on PHP 5.4's embeded server? And is it possible to hide the shell window, which will open everytime, when i start the PHP Webserver via cmd?
Or do you know an alternate, how i can make a software from a HTML-5 (with PHP) App?
Your choosing the wrong language. PHP, HTML, JS, CSS and SQLLite are separate technologies.
I'd suggest writing the app in another language capable of producing an executable like C / C++ (and one that can plug into to SQLITE fairly easy).
If you want to create a installer out of HTML5-APP (PHP,SQLITE,HTML,CSS,JS) , take a look at bitnami package, it may solve your problem, if you have any explicit reason to use C#, and then you have see its library or namespace which may give you installer capability. However your question is unclear, can be be more clear?
You can embed a Chrome browser in C# using the CefSharp project. You would also need to embed some webserver (php built-in webserver might work, but it's single threaded so it might be an issue).
If it doesn't necessarily need to be C#, then take a look at the PHP Desktop project that is using C++ to embed a Chrome engine, a multithreaded webserver Mongoose and a PHP interpreter. Sources can be protected using many available php encoders, see the KnowledgeBase wiki page on the project site for details.
I am developing an activity tracker for my development work in Eclipse (with Java). I now have the program's path and the duration i spent in it.
e.g.: 7min C:\Program Files (x86)\Internet Explorer\iexplore.exe and
10min C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE
I now want to know the name of the program. In C# I get it like this:
System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file);
return (versionInfo.FileDescription == string.Empty) ? null : versionInfo.FileDescription;
Unfortunately, I found no such way in Java and i am not sure if this is even possible?
Thank you!
Edit: I also read this post and the accepted answer but was unable to get the FileDescription...
I am not aware of such API in Java. However, what you can do is as follows:
Create a C# project with the required method that returns program name.
Export this project to DLL.
In your java code you can use JNI to call the native code from you DLL project. You can check these examples: SUN JNI Example , Making Native Windows API calls from within a Java Application
(I would suggest you to consider whether you absolutely need this description.)
Good luck!
It took me forever to find this, but I finally was able to piece together this inline script:
(get-command *.exe).fileversioninfo.filedescription
Now I used *.exe and .filedescription because I was attempting to return the prettified file names for every exe in a directory, but you can use any of the available variables.