Trying to use methods from a COM Object / DLL...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Trying to use methods from a COM Object / DLL...

Post by Wolf_22 »

I have a WAMP system (Windows 7) and I'm trying to use some methods in a DLL that I've tried to load into PHP using "$obj = new COM('foo.bar');" but no matter what I do, I can never seem to get any of the methods to do anything that I see with "com_print_typeinfo($obj);".

Here's my code so far:

Code: Select all

$gif = '';
$test = 12345;//Random variable I *thought* I might need... Just used it to test with.

try {
	$gif = new COM("TLGIF.TLGIF");
	$variant = new VARIANT();

	print '<pre>';
	print_r(variant_get_type($gif));//Returns 9.
	print '</pre>';

	print '<pre>';
	com_print_typeinfo($gif);//Returns what appears to be interface information (i.e. - various method names)...
	print '</pre>';

	print '<pre>';
	var_dump($gif->GetGif($test));//Returns NULL.
	print '</pre>';

}catch(com_exception $e){
	print 'Cannot load dll...';
}

exit;
com_print_typeinfo($gif) outputs the following:

Code: Select all

class ITLGIF { /* GUID={29D1ECFD-A1E3-11D4-9E7C-00C04F18F4A7} */
	/* DISPID=1610612736 */
	function QueryInterface(
		/* VT_PTR [26] [in] --> ? [29]  */ &$riid,
		/* VT_PTR [26] [out] --> VT_PTR [26]  */ &$ppvObj 
		)
	{
	}
	/* DISPID=1610612737 */
	/* VT_UI4 [19] */
	function AddRef(
		)
	{
	}
	/* DISPID=1610612738 */
	/* VT_UI4 [19] */
	function Release(
		)
	{
	}
	/* DISPID=1610678272 */
	function GetTypeInfoCount(
		/* VT_PTR [26] [out] --> VT_UINT [23]  */ &$pctinfo 
		)
	{
	}
	/* DISPID=1610678273 */
	function GetTypeInfo(
		/* VT_UINT [23] [in] */ $itinfo,
		/* VT_UI4 [19] [in] */ $lcid,
		/* VT_PTR [26] [out] --> VT_PTR [26]  */ &$pptinfo 
		)
	{
	}
	/* DISPID=1610678274 */
	function GetIDsOfNames(
		/* VT_PTR [26] [in] --> ? [29]  */ &$riid,
		/* VT_PTR [26] [in] --> VT_PTR [26]  */ &$rgszNames,
		/* VT_UINT [23] [in] */ $cNames,
		/* VT_UI4 [19] [in] */ $lcid,
		/* VT_PTR [26] [out] --> VT_I4 [3]  */ &$rgdispid 
		)
	{
	}
	/* DISPID=1610678275 */
	function Invoke(
		/* VT_I4 [3] [in] */ $dispidMember,
		/* VT_PTR [26] [in] --> ? [29]  */ &$riid,
		/* VT_UI4 [19] [in] */ $lcid,
		/* VT_UI2 [18] [in] */ $wFlags,
		/* VT_PTR [26] [in] --> ? [29]  */ &$pdispparams,
		/* VT_PTR [26] [out] --> VT_VARIANT [12]  */ &$pvarResult,
		/* VT_PTR [26] [out] --> ? [29]  */ &$pexcepinfo,
		/* VT_PTR [26] [out] --> VT_UINT [23]  */ &$puArgErr 
		)
	{
	}
	/* DISPID=1 */
	function GetGIF(
		/* VT_PTR [26] [out] --> VT_VARIANT [12]  */ &$pvargif 
		)
	{
		/* method GetGIF */
	}
}
...but when I try the first snippet that tries to use GetGif(), it doesn't output anything. Am I trying to call it wrong or am I not passing in the correct parameter?

Any information / insight is appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Trying to use methods from a COM Object / DLL...

Post by requinix »

Try dumping out $test instead - the method looks like it uses a by-reference argument, not a return value.
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Trying to use methods from a COM Object / DLL...

Post by Wolf_22 »

Thanks for the quick response, requinix.

I did a var_dump() on both $test and $gif:

Code: Select all

$gif = '';
$test = 12345;//Random variable I *thought* I might need... Just used it to test with.

try {
        $gif = new COM("TLGIF.TLGIF");
        $variant = new VARIANT();

        print '<pre>';
        //print_r(variant_get_type($gif));//Returns 9...
        print '</pre>';

        print '<pre>';
        //com_print_typeinfo($gif);//Returns what appears to be interface information (i.e. - various method names)...
        print '</pre>';

        print '<pre>';
        //var_dump($gif->GetGif($test));//Returns NULL...
        print '</pre>';

        print '<pre>';
        var_dump($test);//Returns "int(12345)"...
        print '</pre>';

        print '<pre>';
        var_dump($gif);//Returns "object(com)#1 (0) {}"...
        print '</pre>';

}catch(com_exception $e){
        print 'Cannot load dll...';
}

exit;
$test outputs the number I assigned it and $gif outputs object(com)#1 (0) {}... (Which doesn't make sense to me unless the DLL isn't coded correctly or else if PHP just can't get the contents of it.)

Any additional insight into this is appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Trying to use methods from a COM Object / DLL...

Post by requinix »

...You commented out the parts of the code that actually do the work. Like the bit that calls GetGif.
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Trying to use methods from a COM Object / DLL...

Post by Wolf_22 »

That's what my post conveys, you're right... But when I tested those parts, they returned what I noted in the comments I made.

(So for the "var_dump($gif)", the result was essentially an empty COM object, etc.)
Post Reply