• Advertisement
Sign in to follow this  

[web] How To Access A DLL In PHP

This topic is 4147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've programmed a simple test DLL in C++:
extern "C"
{
	__declspec(dllexport) int DisplayHelloFromDLL()
	{
		return 0;
	}
}
I compiled it under release mode in MSVS 2k3 and I now have a sucessfully compiled DLL. Now, my problem is using this DLL in PHP. I read up on w32api for PHP, and I wrote a quick script:
<?
dl("php_w32api.dll");

w32api_register_function("COM32_DLL_TEST.dll","DisplayHelloFromDLL","int");

echo DisplayHelloFromDLL();
?>
I then placed the php_w32api.dll in my extension's folder on the server and my test DLL in the folder with the script file. I go to run the script and this is what I see:
Warning: dl() [function.dl]: Unable to load dynamic library 'C:\PHP\ext\php_w32api.dll' - The specified module could not be found. in C:\Projects\www\test\win32API.php on line 4

Fatal error: Call to undefined function w32api_register_function() in C:\Projects\www\test\win32API.php on line 6
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\PHP\ext\php_w32api.dll' - The specified module could not be found. in Unknown on line 0
That was using the latest PHP5 and using the old 4.4.x w32api. I know there's another method of using a COM object in PHP, I've done that before using verisign and it worked well, but I can't find any info on creating a COM DLL in C++, as well as it just complicates things more. If someone could possibly help me out with this situation, it would be greatly appreciated! :D

Share this post


Link to post
Share on other sites
Advertisement
If you want to create COM object i would suggest you create an ATL (ActiveX Template Library) DLL project type this will create a base COM+ object that contains all the required interfaces. check here for some information about creating ATL COM objects

Share this post


Link to post
Share on other sites
In order to use the w32api extension, you must install it as describe on that page, or use the PECL system to build and install it.

Don't use dl() - it's semi-deprecated now (Will likely be removed from most SAPIs in PHP6), and doesn't work on some servers under Windows anyway. Instead, load extensions from php.ini

The DLL is missing which is why it's not working.

You don't NEED to make a COM DLL to call it from PHP - you can use the w32api instead. But be sure you know whether you're using COM or not, otherwise you will confuse yourself.

Consider carefully before doing any of this, whether it's really the right thing to do (Hint: probably not).

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement