PHP와 COM

PHP는 Win32 플랫폼의 COM과 DCOM 객체에 접근할수 있습니다.

어떤것을 계산하는 DLL을 빌드했습니다. PHP상에서 이 DLL을 실행시킬수 있는 방법 이 있습니까?

간단한 DLL이라도 PHP에서 실행할 방법은 아직 없습니다. 접근가능한 COM서버를 포함하는 DLL이고, IDispatch 인터페이스로 구현되어있다면 가능할수도 있습니다.

'Unsupported variant type: xxxx (0xxxxx)'은 무엇을 의미합니까?

몇가지의 VARIANT 타입과 그 타입간의 조합이 가능합니다. 그들 대부분은 거의 지원이 되고있지만 일부가 아직 구현되어있지 않습니다. 배열은 완전히 지원되지 않습니다. 오직 1차원 배열만이 PHP와 COM사이에서 전달이 가능합니다. 지원되지 않는 다른 타입을 발견했다면 그 타입을 버그 레포트로 알려주기랍니다 (아직 보고되지 않는것들이라면) 그리고 더 자세한 정보도 함께 제공해주십시오.

PHP에서 비주얼한 객체(visual object)를 조작할수 있습니까?

가능합니다. 하지만 PHP는 대부분 웹서버의 환경에서 웹 스크립트 언어로서 이용되고 있습니다. 따라서 서버가 비주얼 객체를 보여주지는 않을것입니다. 응용프로그램 스크립트를 위한 PHP(PHP-GTK같은)를 사용한다면 COM을 통해서 비주얼 객체(visual object)에 접근하고 조작하는데 아무 제한이 없습니다.

세션안에 COM 객체를 저장할 수 있습니까?

그건 안됩니다. COM 인스턴스는 리소스로 취급되므로 오직 단일 스크립트의 문맥에서만 가용한것입니다.

COM 에러를 어떻게 추적할 수 있습니까?

PHP 5에서, COM 확장은 com_exception 예외를 발생합니다. 이를 잡아서 code 멤버를 조사함으로써 다음에 취할 행동을 결정할 수 있습니다.

PHP 4에서는 COM 오류를 PHP 자체에서 제공하는 방법(@, track_errors, ..)으로 추적할 수 없습니다.

펄에서 쓰던 방법으로 PHP 스크립트에서 DLL 파일을 만들수 있습니까?

만들수 없습니다. 재수없게도 PHP를 위해 그런 툴이 존재하지 않습니다.

'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}'의 의미는 무엇입니까?

이 에러는 다음과 같은 원인일수 있습니다.

  • CLSID가 잘못되었다
  • 필요한 DLL이 존재하지 않는다
  • 필요한 컴포넌트가 IDispatch 인터페이스로 구현되지 않았다

원격 서버에서 COM 객체를 어떻게 실행할수 있습니까?

로컬 객체를 실행시키는것과 완전히 똑같습니다. 단지 COM 생성자의 두번째 인수에 다른 서버의 IP를 넘겨주면 됩니다.

php.ini에서 com.allow_dcom=TRUE로 설정해야 합니다.

'DCOM is disabled in C:\path...\scriptname.php on line 6'라는 메시지를 봤습니다. 어떻게 해야 하나요?

php.ini를 수정하여 com.allow_dcom=TRUE로 설정합니다.

PHP에서 ActiveX 객체를 부르거나/변경할수 있습니까?

이것은 PHP에서 할일이 아닙니다. HTML 문서에서 ActiveX 객체가 포함되있으면 클라이언트 단에서 그 코드를 처리하는 것입니다. PHP 스크립트와는 전혀 관련이 없고 따라서 서버단과는 직접적인 관련이 없습니다.

특정 컴포넌트에서 실행중인 인스턴스에 접근 가능합니까?

모니커(monikers)의 도움으로 가능합니다. 하나의 워드 인스턴스로 다방향 레퍼런스를 얻고 싶다면 다음처럼 그 인스턴스를 만들 수 있습니다.

<?php
$word 
= new COM("C:\docs\word.doc");
?>

위처럼 하면 실행중인 인스턴스가 없을 때에는 새로운 인스턴스를 만들수 있고, 실행중인 인스턴스가 이미 존재하면 그 핸들을 넘겨주게 됩니다.

COM 객체로부터 받은 이벤트를 제어할 방법이 있습니까?

com_event_sink()를 사용하여 이벤트 싱크와 바인드를 정의할 수 있습니다. PHP가 이벤트 싱크 클래스의 뼈대을 생성하게 하기 위하여 com_print_typeinfo()를 사용할 수 있습니다.

하나 이상의 인터페이스를 갖는 COM 객체의 메쏘드를 불러 들이려고 하는데 문제에 봉착했습니다. 어떻게 해야 합니까?

답은 불만스럽겠지만 간단합니다. 확실치는 않지만 당신은 아무것도 할수없습니다. 어떤사람은 이 문제와 관련된 정보를 가지고 있습니다. » 저에게 알려주시라 :)

그래서 PHP와 COM이 작동하는군요. COM+는 어떤가요?

MTS와 MTMQ를 통해서 컴포넌트를 관리하는 프레임워크가 추가되면서 COM에서 COM+로 발전된것입니다. 그런데 PHP는 그런 컴포넌트를 지원하지 않습니다.

PHP가 COM 객체를 다룰수있다면, PHP로 컴포넌트 자원을 관리하는 MTS를 쓸수있지 않을까요?

PHP 자체로는 아직 트랜젝션을 관리할수 없습니다. 따라서 에러가 발생하더라도 롤백으로 초기화되지않습니다. 트랜젝션을 지원하는 컴포넌트를 사용한다면 트랜젝션 관리를 구현해서 써야합니다.

add a note add a note

User Contributed Notes 3 notes

up
8
Anonymous
18 years ago
Re: The Windows English CHM Sample with MS Word Automation.

I see that $Word->Release() is called after $Word->Quit().
This seems to be erroneous. Actually, $Word->Release() should not have to be called if proper COM garbage collection is taking place. Release() is a C++ construction not used in either Visual Basic or VBScript or even MS-JScript. Just to be sure, however, I ran the sample through php.exe (5.04 CLI on Windows XP SP1 with Office 2003) and got a RPC failed error on the line containing $Word->Release(). The rest of the sample works fine, and the results are as expected. So, I propose 2 scenarios:
      1.There is a problem with the documentation (more likely).
      2.There is a problem with PHP504 itself, as this problem is reproduced with any COM Automation call, not just Word.
up
4
junk.ghost@virgin dOtt net
19 years ago
It may be obvious to everyone else but...

If you want to write your own COM DLL in MSVC++6 and you want to pass it a string, you need the following in your .idl file:

HRESULT function_name([in] BSTR parameter_name,
                      [retval, out] BSTR * retval);

retval is the result of your function as a string to be passed back.

BSTR is an unsigned short *, so if you want to use your string with STL string etc. you may need to convert parameters to and from char *.

The burden of my message is that from PHP

$comThing = new COM("comThing.comThing");
print $comThing->function_name("Jeremy");

Jeremy will be marshalled as wide chars, which match BSTR.
up
-1
codeslinger at compsalot dot com
17 years ago
in response to item #1 above:  "If this is a simple DLL there is no way yet to run it from PHP."

Answer: There are several different packages/add-ons to php that enable low level access to the windows api. One of the most popular of these packages is available at http://www.winbinder.org

Winbinder does have the ability to load a dll and call it's functions.  Winbinder also provides a large set of windows apis for creating windows and controls.  This is useful for creating stand-alone desktop apps.  It is a possible alternative to php-gtk.

I've had mixed results with Winbinder, some things work very well, others are buggy; source code is available.  It's worth a look, Evaluate carefully.
To Top