<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joey Rivera &#187; com</title>
	<atom:link href="http://www.joeyrivera.com/tag/com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joeyrivera.com</link>
	<description>Blogging about PHP, Actionscript, MySQL, and other interests.</description>
	<lastBuildDate>Fri, 02 Dec 2011 03:55:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Calling a DLL with PHP</title>
		<link>http://www.joeyrivera.com/2009/calling-a-dll-with-php/</link>
		<comments>http://www.joeyrivera.com/2009/calling-a-dll-with-php/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 22:10:25 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[com]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[regsvr32]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=293</guid>
		<description><![CDATA[So here&#8217;s a quick post on calling dll&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s a quick post on calling dll&#8217;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.</p>
<p>I tried calling the dll using the <a href="http://us.php.net/manual/en/class.com.php" target="_blank">COM class</a> 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 <a href="http://www.ss64.com/nt/regsvr32.html" target="_blank">register a dll in windows</a> you do the following in your command line:</p>
<div class="dean_ch" style="white-space: wrap;">REGSVR32 MyStuff.dll</div>
<p>Now that the dll is registered you can do the following to start accessing the dll:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$my_dll</span> = <span class="kw2">new</span> COM<span class="br0">&#40;</span><span class="st0">&#8216;MyStuff.Functions&#8217;</span><span class="br0">&#41;</span>;</div>
<p>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:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$encrypted_text</span> = <span class="kw2">null</span>;<br />
<span class="re0">$input</span> = <span class="st0">&#8216;This needs to be encrypted.&#8217;</span>;<br />
<span class="re0">$my_dll</span>-&gt;<span class="me1">EncryptString</span><span class="br0">&#40;</span><span class="re0">$input</span>, <span class="re0">$encrypted_text</span> <span class="br0">&#41;</span>;</div>
<p>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:</p>
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="re0">$encrypted_text</span>;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2009/calling-a-dll-with-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

