Steps for creating a dll in C# that can then be used from php -


by gleaning bits of information various posts, have come far, still not there yet.

i trying create dll in c# can used php.

i have created vs2012 c# class library project:

using system; using system.collections.generic; using system.linq; using system.runtime.interopservices; using system.text; using system.threading.tasks;  namespace test1 {     [system.runtime.interopservices.guid("0283f337-af8d-45be-bd32-829f5976e9ef")]     [comvisible(true)]     public class class1     {         public class1()         {             // nothing         }          public int blah()         {             return 42;         }     } } 

platform target: cpu

target framework: .net framework 4

i have compiled , have got test1.dll file.

i have tried registering with:

regsvr32 test1.dll 

but following error:

the module "test1.dll" loaded entry-point dllregisterserver not found. 

also tried:

regsvr32 /i /n test1.dll 

but error:

the module "test1.dll" loaded entry-point dllinstall not found. 

i use:

regasm test1.dll 

and says successful.

i next create test php file:

<?php $obj = new com("test1.class1"); $output=$obj->blah(); echo $output; ?> 

i add following php.ini:

[php_com_dotnet] extension=php_com_dotnet.dll 

but when run it, get:

fatal error: uncaught exception 'com_exception' message 'failed create com object `test1.class1': class not registered 

so seems me have use regsvr32 , make changes in c# deal dllregisterserver issue

can fill me in on else need make work.

i using:

php 5.6.7 visual studio express 2012 windows 8.1 (64 bit version) 

addendum:

also tried:

regasm test1.dll /tlb:test1.tlb regsvr32 test1.tlb 

that gives me:

the module "test1.tlb" may not compatible version of windows you're running.  check if module compatible x86 (32-bit) or x64 (64-bit) version of regsvr32.exe. 

i message whether platform target "x64" or "any cpu".

test1.dll not com dll, can't register it.

you need follow steps(https://msdn.microsoft.com/en-us/library/x66s8zcd.aspx) enable com.

enter image description here

to set code in class create com object

in solution explorer, double-click class1.vb display code. rename class comclass1. add following constants comclass1. store globally unique identifier (guid) constants com objects required have.

vb.net

public const classid string = ""  public const interfaceid string = ""  public const eventsid string = "" 

on tools menu, click create guid. in create guid dialog box, click registry format , click copy. click exit.

replace empty string classid guid, removing leading , trailing braces. example, if guid provided guidgen "{2c8b0aee-02c9-486e-b809-c780a11530fe}" code should appear follows.

vb.net

public const classid string = "2c8b0aee-02c9-486e-b809-c780a11530fe" 

repeat previous steps interfaceid , eventsid constants, in following example.

vb.net

public const interfaceid string = "3d8b5ba4-fb8c-5ff8-8468-11bf6bd5cf91"  public const eventsid string = "2b691787-6ed7-401e-90a4-b3b9c0360e31" 

make sure guids new , unique; otherwise, com component conflict other com components.

add comclass attribute comclass1, specifying guids class id, interface id, , events id in following example:

vb.net

<comclass(comclass1.classid, comclass1.interfaceid, comclass1.eventsid)> public class comclass1 

com classes must have parameterless public sub new() constructor, or class not register correctly. add parameterless constructor class:

vb.net

public sub new()     mybase.new() end sub 

add properties, methods, , events class, ending end class statement. select build solution build menu.

now, can register dlls using regsvr32.


Comments