expose Phalanger .dll as COM component ?

Integrating PHP and C# together. Using .NET libraries from PHP and vice versa.

expose Phalanger .dll as COM component ?

Postby spencer hollon » April 8th, 2014, 11:42 pm

Can you give a simple example of how to expose a class and member method in a Phalanger .dll to COM? I am trying to write a COM add-in for Microsoft Retail Management System which looks for a COM exposed function named "Process()"... works great in VB.net but can't get it working with Phalanger. I have tried to adapt C# examples to PHP but I am having no luck. Any help would be greatly appreciated. Sample code below:

<?php
use System;
use System\Windows\Forms;
use System\Runtime\InteropServices;

[\Export]

[assembly: System\Runtime\InteropServices\ComVisible(true)]

class RMStoPMSLibraryClass
{

function __construct(){

}

[System\Runtime\InteropServices\ComVisible(true)]
public function Process(System\Object $QSSession){
Forms\MessageBox::Show('Sample Message Box in Phalanger');

return TRUE;
}//close function process()
}//close RMStoPMSLibraryClass

?>
spencer hollon
 
Posts: 5
Joined: April 8th, 2014, 5:40 pm

Re: expose Phalanger .dll as COM component ?

Postby Jakub Misek » April 9th, 2014, 12:38 pm

Phalanger produces standard .NET assemblies, but anything explicitly about COM components.

You may add Guid, InterfaceType and ProgId attributes as well. Also I've added \Export attribute for the whole assembly (all classes will be emitted with nice .NET interface).

Please note, compiled assembly has to be registered for COM interop
Code: Select all
regasm "PathToDll.dll" /codebase /tlb


Code: Select all
<?php
use System;
use System\Runtime\InteropServices;

[assembly: \Export]  // emits nice C# public methods
[assembly: InteropServices\ComVisible(true)]

[InteropServices\Guid('7BD20046-DF8C-44A6-8F6B-687FAA26FA88')]
class RMStoPMSLibraryClass {

  function __construct() {}

  [InteropServices\ComVisible(true)]
  public function Process(System\Object $QSSession){
    System\Windows\Forms\MessageBox::Show('Sample Message Box in Phalanger');

    return TRUE;
  }
}


Do you have a working sample in VB or C#?
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2078
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: expose Phalanger .dll as COM component ?

Postby spencer hollon » April 11th, 2014, 5:10 am

Thank you Jakub. Using OLE/COM viewer my public functions are exposed now.
spencer hollon
 
Posts: 5
Joined: April 8th, 2014, 5:40 pm

Re: expose Phalanger .dll as COM component ?

Postby Jakub Misek » April 15th, 2014, 10:23 pm

Great! Do you have a sample project?

Thanks,
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2078
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to PHP/C# interoperability

Who is online

Users browsing this forum: No registered users and 2 guests

User Control Panel

Login

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 77 on September 4th, 2018, 9:46 pm

Users browsing this forum: No registered users and 2 guests
Phalanger