Page 1 of 1

expose Phalanger .dll as COM component ?

PostPosted: April 8th, 2014, 11:42 pm
by spencer hollon
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

?>

Re: expose Phalanger .dll as COM component ?

PostPosted: April 9th, 2014, 12:38 pm
by Jakub Misek
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#?

Re: expose Phalanger .dll as COM component ?

PostPosted: April 11th, 2014, 5:10 am
by spencer hollon
Thank you Jakub. Using OLE/COM viewer my public functions are exposed now.

Re: expose Phalanger .dll as COM component ?

PostPosted: April 15th, 2014, 10:23 pm
by Jakub Misek
Great! Do you have a sample project?

Thanks,