So here’s a quick post on calling dll’s in Windows using php. I have a dll that encrypts data in a certain format that we need for another process. So I need to pass the dll a string and it returns the encrypted string back.
I tried calling the dll using the COM class in code and was having issues until I realized I have to register the dll in windows first before I can call it using the COM class. To register a dll in windows you do the following in your command line:
Now that the dll is registered you can do the following to start accessing the dll:
MyStuff is the dll name an/or id and Functions is the object inside the dll that we want to use. Now I call the method I need and pass the parameters:
$input = ‘This needs to be encrypted.’;
$my_dll->EncryptString($input, $encrypted_text );
This is pretty much it. We instantiate the COM class with the dll and function I want. Then I call the method in the dll passing my text and it returns into my $encrypted_text var the encrypted text. I can now do my next process with the encrypted text like:







#1 by alfred co on July 31, 2011 - 1:24 am
Quote
i am a newbie on php, i wanted to ask if this sample could access the dll installed in the client machine or the server
#2 by Joey on August 1, 2011 - 8:47 am
Quote
Hi Alfred,
PHP can only access what is in the server and not the client so if you would need to make sure the dll is available to PHP on the server side where the PHP code relies.
#3 by Eric on August 31, 2011 - 5:16 pm
Quote
This is possible to do without register the dll?
Is possible to do without using the COM class?
Thank you.
#4 by Joey on September 2, 2011 - 10:39 am
Quote
Hey Eric, when I tried this I had to register the dll. To be honest, I don’t remember how much time I spent trying without registering but it was how I was able to get it to work. I don’t remember what the documentation says but I would assume as long as you pass a correct path to the file it should have worked. I don’t know if this helps you but there seems to be a .net class object that may help you but it also uses com I believe: http://us.php.net/manual/en/class.dotnet.php
#5 by Jenny on September 16, 2011 - 7:29 pm
Quote
Hi, I was wondering if you can do the following:
I have the dll of an application, this application reads two-dimensional bar codes using a webcam and decodes them to show a result, when I download the dll that came with examples of its use in vb.net, c++ y c #, but not in php . Now I need to use this application and return me the number that stores the bar code.
Hope some advisement from you… the application is QuickMark
#6 by Joey on September 20, 2011 - 9:00 am
Quote
Jenny,
I’m not sure I’ll be much help. If I remember correctly, this only worked with some dll’s I tried and not all but I could have done something wrong. Also, I think if the dll couldn’t get registered with the system then I was not able to use them in PHP.
#7 by aruna on January 10, 2012 - 10:59 am
Quote
iam trying to call c++ dll in php.
while creating a COM object iam getting error,can’t create COM object..like this…
Is it mandatory to register the dll into system to use that dll in php.
and how to write wrapper for that dll to use those functions in php..
if anybody knows ,please clarify this.
Thanks..
#8 by lawrence on January 10, 2012 - 5:44 pm
Quote
I think we have to rememer that all DLLs cannot be registered or use .NET. I’m just now looking to do the same. I’ve called dlls from other scripting languages in the past. I’m sure I’ll find an answer.
I just wanted to mention that when working with third party dlls that all cannot be registered and developers should either code a wrapper that can be registered of document how they can be used otherwise.