<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://technolog.nl/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>eprogrammer : Active Directory</title><link>http://technolog.nl/blogs/eprogrammer/archive/tags/Active+Directory/default.aspx</link><description>Tags: Active Directory</description><dc:language>en</dc:language><generator>CommunityServer 2.1 (Build: 60809.935)</generator><item><title>HOWTO: Associate a custom WKGUID (well known guid) to a custom Container</title><link>http://technolog.nl/blogs/eprogrammer/archive/2006/10/05/HOWTO_3A00_-Associate-a-custom-WKGUID-_2800_well-known-guid_2900_-to-a-custom-Container.aspx</link><pubDate>Thu, 05 Oct 2006 11:05:00 GMT</pubDate><guid isPermaLink="false">3420c8e2-8f96-4c4a-9e98-3bc38250dfb6:1127</guid><dc:creator>eprogrammer</dc:creator><slash:comments>1</slash:comments><comments>http://technolog.nl/blogs/eprogrammer/comments/1127.aspx</comments><wfw:commentRss>http://technolog.nl/blogs/eprogrammer/commentrss.aspx?PostID=1127</wfw:commentRss><description>&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Active Directory and ADSI (ldap in fact) have many unutilized features that, if the APIs would explain better be used much better!&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Let me draw a situation for you.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Imagine you have an app, that is distributed and sold among international customers (congrats for that by the way &lt;/font&gt;&lt;span style="font-family:Wingdings;"&gt;&lt;span&gt;J&lt;/span&gt;&lt;/span&gt;&lt;font face="Times New Roman"&gt;). Now there could happen 2 things, or 3 if nothing happens is a count as well). &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:-18pt;tab-stops:list 36.0pt;"&gt;&lt;span&gt;&lt;span&gt;&lt;font face="Times New Roman"&gt;&lt;font size="3"&gt;1)&lt;/font&gt;&lt;span style="font:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Times New Roman" size="3"&gt;Your company suddenly got sold out to a rich guy or girl and now everything gets renamed including your &amp;lsquo;custom company container&amp;rsquo;. &lt;br /&gt;So cn=ourcompany data,cn=Program Data,dn=nwtraders,dc=msft&lt;br /&gt;Must become (because your boss asks you to do so!)&lt;br /&gt;cn=thenewcompany data,cn=Program data,dn=nwtraders,dc=msft&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:-18pt;tab-stops:list 36.0pt;"&gt;&lt;span&gt;&lt;span&gt;&lt;font face="Times New Roman"&gt;&lt;font size="3"&gt;2)&lt;/font&gt;&lt;span style="font:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Some dn (distinguished Name) is subject to translation. Eg: &lt;br /&gt;cn=Program Information,cn=etc blah blah&lt;br /&gt;must be translated (because your boss asks you to do so &lt;/font&gt;&lt;span style="font-family:Wingdings;"&gt;&lt;span&gt;J&lt;/span&gt;&lt;/span&gt;&lt;font face="Times New Roman"&gt; ) to&lt;br /&gt;cn=Information du programme,cn=etc blah blah&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;In both situations 1 and 2 you&amp;rsquo;ll have to keep a list of paths per language and many companies of course, understand this is a difficult and risky task, so they might choose to keep up with a single international English name.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;table cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td style="background-color:transparent;border:#ece9d8;"&gt;&lt;div&gt;&lt;p class="MsoNormal" style="margin:12pt 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Note: The WKGUID protects against renaming or translating, but it is not meant to &amp;lsquo;protect&amp;rsquo; against moving your container within Active Directory)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Why should you accept this risk &lt;em&gt;if Active Directory supports immunity against renaming this out of the box if you associate a WKGUID?&lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;em&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;&lt;em&gt;&lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;However there is no obvious documentation about this and you just should know that setting this property more or less is hidden through usage of IDirectoryObject while ADSI /scripting/vb6 environments were not able to use this interface.&amp;nbsp;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Worse, the sample at the MSDN might be working but goes lowest by using the ldap_connect API within a ADSI call (that&amp;rsquo;s rather dirty) instead of using CLSID_DNWithBinary and the sample is &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/example_code_for_creating_a_container_object.asp"&gt;&lt;font color="#800080" face="Times New Roman" size="3"&gt;flawed&lt;/font&gt;&lt;/a&gt;&lt;font face="Times New Roman" size="3"&gt; with leaks but let&amp;rsquo;s not bash the writer, I&amp;rsquo;m not intending to do so).&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;(update) b.t.w. in the attachment temp.zip you&amp;#39;ll find full source code for the sample. Note that Active Directory has a bug that makes custom WKGUIDs useless. It simply cannot find your custom WKGUID. I reported this bug to Microsoft.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;How could you ever figure that WKGUID and it&amp;rsquo;s query syntax is related to the following attribute: &amp;lsquo;otherWellKnownObjects&amp;rsquo;?&lt;/font&gt;&lt;font size="3"&gt;&lt;span style="font-family:Wingdings;"&gt;&lt;span&gt;J&lt;/span&gt;&lt;/span&gt;&lt;font face="Times New Roman"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;This sort of documentation, it&amp;#39;s&amp;nbsp;complexity in Active Directory on LDAP makes it hard to see any utilization for this feature.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;I hope to support MS-es Active Directory (that I love, just as IIS and SQL server) usage and ease in practice by posting the following sample code.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Note that this code is not &amp;lsquo;well-formed&amp;rsquo; and &amp;lsquo;error-proof&amp;rsquo; but it works and gives you an idea.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;The logging (debug feature) is done through the logging module posted just before this posting.&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Now how do we profit from this feature?&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;Imagine you have created through an LDIF or through code a container object&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;cn=our CompanyData,cn=Program Data,dc=nwtraders,dc=msft&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:-18pt;tab-stops:list 36.0pt;"&gt;&lt;font face="Times New Roman"&gt;&lt;span&gt;&lt;span&gt;&lt;font size="3"&gt;1)&lt;/font&gt;&lt;span style="font:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;Now we associate &amp;lsquo;our CompanyData&amp;rsquo; with the &amp;lsquo;otherWellKnownObjects&amp;rsquo; property using a custom hexadecimal guid &lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;ldquo;&lt;span style="color:maroon;"&gt;81a3469a653959419309b33e27bdd2c9&amp;rdquo;!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:-18pt;tab-stops:list 36.0pt;"&gt;&lt;font face="Times New Roman"&gt;&lt;span&gt;&lt;span&gt;&lt;font size="3"&gt;2)&lt;/font&gt;&lt;span style="font:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;Eg: &lt;/font&gt;&lt;/font&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;WriteADSAttributeDnWithString([ourcompnayCN], L&amp;rdquo;cn=our Company Data,cn=Program Data,dc=nwtraders,dc=msft&amp;rdquo;, ourGUID, ADS_ATTR_APPEND&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:-18pt;tab-stops:list 36.0pt;"&gt;&lt;span&gt;&lt;span&gt;&lt;font face="Times New Roman"&gt;&lt;font size="3"&gt;3)&lt;/font&gt;&lt;span style="font:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Now you can query your company data like this, no matter your company is being renamed in future&lt;/span&gt;&lt;span style="font-size:10pt;font-family:Wingdings;"&gt;&lt;span&gt;J&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;, through the following syntax: LDAP://&amp;lt;WKGUID=&lt;span style="color:maroon;"&gt;8a3469a653959419309b33e27bdd2c9,cn=Program Data,dc=nwtraders,dc=msft&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 18pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:#ff6600;"&gt;&lt;font face="Times New Roman"&gt;Normally the dn for &lt;em&gt;Program Data&lt;/em&gt; is WKGUID-ed by Microsoft as well! The Program Data container should be reliably formatted as &lt;/font&gt;&lt;/span&gt;&lt;span style="font-size:10pt;color:#ff6600;font-family:'Courier New';"&gt;L&amp;quot;LDAP://&amp;lt;WKGUID=%s,%s&amp;gt;&amp;quot;, GUID_PROGRAM_DATA_CONTAINER_W, L&amp;rdquo;dc=nwtraders,dc=msft&amp;rdquo;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;span style="z-index:3;position:absolute;"&gt;&lt;table cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td style="background-color:transparent;border:#ece9d8;"&gt;&lt;div class="shape" style="padding-right:7.95pt;padding-left:7.95pt;padding-bottom:4.35pt;padding-top:4.35pt;"&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Note: After you usage of the WKGUID or the GUID- syntax, you must resolve the &lt;em&gt;fully qualified dn&lt;/em&gt; by using the &amp;lsquo;distinguishedName&amp;rsquo; property and refetching your Actife Directory object before you go on with it.&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/span&gt;&lt;font face="Times New Roman" size="3"&gt;&amp;nbsp;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;table cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td style="background-color:transparent;border:#ece9d8;"&gt;&lt;div&gt;&lt;p class="MsoNormal" style="margin:12pt 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Note: You would wish you could set the objectGUID attribute at creation of your object instead of the WKGUID. Unfortunately, this value is generated by Active Directory itself.)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;STDMETHODIMP WriteADSAttributeDnWithString(&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;IADs *piADs, &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;PCWSTR dn, &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt 36pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;PCWSTR guid) &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CComVariant v;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span&gt;CComPtr&amp;lt;IADsDNWithBinary&amp;gt; dnWithBin;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CComBSTR assocDn(&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;dn&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span&gt;dnWithBin.CoCreateInstance(CLSID_DNWithBinary);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;v.vt = VT_UI1 | VT_ARRAY;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;hr = ConvertHexGuidToArray(guid, &amp;amp;v.parray);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = dnWithBin-&amp;gt;put_BinaryValue(v);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = dnWithBin-&amp;gt;put_DNString(assocDn);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;CComBSTR attribute( L&lt;span style="color:maroon;"&gt;&amp;quot;otherWellKnownObjects&amp;quot;)&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;text-indent:36pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;v.Clear();&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;v.vt = VT_DISPATCH;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;dnWithBin.QueryInterface(&amp;amp;v.pdispVal);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = pADs-&amp;gt;Put(attribute, v);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = pADs-&amp;gt;SetInfo();&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; hr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/p&gt;&lt;/span&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;color:green;font-family:'Courier New';"&gt;// converts hexadecimal string to a octet encoded byte array&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;STDMETHODIMP ConvertHexGuidToArray(PCWSTR hexGuid, LPSAFEARRAY *sa)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (hexGuid == NULL) &lt;span style="color:blue;"&gt;return&lt;/span&gt; E_INVALIDARG;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; hexLen = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)wcslen(hexGuid);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;HRESULT hr = S_OK;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CTempBuffer&amp;lt;CHAR&amp;gt; sHex(hexLen);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; loopLen = hexLen;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;while&lt;/span&gt;(loopLen-- != 0)&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sHex[loopLen] = (CHAR) hexGuid[loopLen];&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;SAFEARRAY *temp= SafeArrayCreateVector(VT_UI1, 0, hexLen / 2);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (temp == NULL) &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return E_OUTOFMEMORY;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;PBYTE dst ;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = SafeArrayAccessData(temp, (&lt;span style="color:blue;"&gt;void&lt;/span&gt;**)&amp;amp;dst);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; dstLen = hexLen /2;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (hr == S_OK)&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;AtlHexDecode(sHex, hexLen, dst, &amp;amp;dstLen ); &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;hr = SafeArrayUnaccessData(temp);&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;*sa = temp; &lt;span style="color:green;"&gt;//return the array&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; hr;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0cm 0cm 0pt;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;img src="http://technolog.nl/aggbug.aspx?PostID=1127" width="1" height="1"&gt;</description><enclosure url="http://technolog.nl/blogs/eprogrammer/attachment/1127.ashx" length="8398" type="application/x-zip-compressed" /><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/ATL/default.aspx">ATL</category><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/WKGUID/default.aspx">WKGUID</category><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/rename-safety/default.aspx">rename-safety</category><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/translation-safe/default.aspx">translation-safe</category><category domain="http://technolog.nl/blogs/eprogrammer/archive/tags/Active+Directory/default.aspx">Active Directory</category></item></channel></rss>