<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7733893741350207472</id><updated>2011-11-27T17:02:25.786-08:00</updated><category term='COM'/><category term='Code Access Security'/><category term='Security'/><category term='Interoperating'/><category term='CAS'/><title type='text'>Study .NET Framework</title><subtitle type='html'>Study and Learn .NET Framework</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-4149069763679584463</id><published>2009-01-10T10:55:00.000-08:00</published><updated>2009-01-10T11:15:39.921-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><title type='text'>To understand the Windows Security</title><content type='html'>There are many references existing in &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;MSDN&lt;/span&gt; to talk about Windows Security. Some of them are for the new users, but some of them are for experienced users or even programmers. Moreover, they explain the concepts in different ways for different version of Windows or .NET Framework. It's still frustrating to search through all those documents and check them one by one.&lt;br /&gt;&lt;br /&gt;During search the &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_1"&gt;fundamental&lt;/span&gt; comprehensive documents, I found this link is quite &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_2"&gt;useful&lt;/span&gt;:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc246013(PROT.10).aspx"&gt;[MS-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;SECO&lt;/span&gt;]: Windows Security Overview&lt;/a&gt;&lt;br /&gt;Not only you can learn the overall &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_4"&gt;fundamental&lt;/span&gt; knowledge of Windows security online, but you can aslo download the whole topics in PDF format from the link side to read offline.&lt;br /&gt;&lt;br /&gt;Actually, when you go upper level of the we site, you will find that link provides many documents for all Windows protocols:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc216517(PROT.10).aspx"&gt;Windows Protocols&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And Microsoft keeps updating those documents!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-4149069763679584463?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/4149069763679584463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2009/01/to-understand-windows-security.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/4149069763679584463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/4149069763679584463'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2009/01/to-understand-windows-security.html' title='To understand the Windows Security'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-1159138346184659820</id><published>2009-01-08T11:58:00.000-08:00</published><updated>2009-01-09T14:57:15.392-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><title type='text'>Reference links about "Role-Based Security, Principal, and Identity" of .NET Framework</title><content type='html'>Here are some basic important links to explain the security concepts of Windows.&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_JMErl8GRWoY/SWfRszvJyNI/AAAAAAAACAU/QrfmT_4WPZU/s1600-h/Security.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5289426855102367954" style="WIDTH: 596px; CURSOR: hand; HEIGHT: 423px" alt="" src="http://2.bp.blogspot.com/_JMErl8GRWoY/SWfRszvJyNI/AAAAAAAACAU/QrfmT_4WPZU/s400/Security.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;.NET Securiy Overview (Althought it applies to .NET Framework 1.1)&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa302422.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa302422.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Security Policy Model:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ck90k585.aspx"&gt;http://msdn.microsoft.com/en-us/library/ck90k585.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Security Permissions:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/5ba4k1c5(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/5ba4k1c5(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Code Access Permissions: &lt;a href="http://msdn.microsoft.com/en-us/library/h846e9b3(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/h846e9b3(VS.80).aspx&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Identity Permissions: &lt;a href="http://msdn.microsoft.com/en-us/library/d3wktt6a(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/d3wktt6a(VS.80).aspx&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Role-Based Security Permissions: &lt;a href="http://msdn.microsoft.com/en-us/library/7sxk9k2h(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/7sxk9k2h(VS.80).aspx&lt;/a&gt; &lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Introduction of Role-Based Security:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/shz8h065(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/shz8h065(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Introduction of Cose Access Security:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/c5tk9z76(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/c5tk9z76(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_JMErl8GRWoY/SWfV8dl_B2I/AAAAAAAACAc/3Cxq92fj-tE/s1600-h/CAS.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5289431522082752354" style="WIDTH: 467px; CURSOR: hand; HEIGHT: 515px" alt="" src="http://2.bp.blogspot.com/_JMErl8GRWoY/SWfV8dl_B2I/AAAAAAAACAc/3Cxq92fj-tE/s400/CAS.gif" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;What is "Principal"?&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/axt6w9h8(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/axt6w9h8(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Principal and Identity Objects:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ftx85f8x(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/ftx85f8x(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The principal object encapsulates: &lt;/div&gt;&lt;ul&gt;&lt;li&gt;An identity object: .NET Framework identity objects represent users.&lt;/li&gt;&lt;li&gt;A role: Roles represent membership and securiy contexts. A SecurityContext object captures all security-related information for a logical thread, including the information contained in the &lt;a id="ctl00_rs1_mainContentContainer_ctl22" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe337404_cctl00_rs1_mainContentContainer_ctl22',this);" href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity(VS.80).aspx"&gt;WindowsIdentity&lt;/a&gt; and &lt;a id="ctl00_rs1_mainContentContainer_ctl23" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe337404_cctl00_rs1_mainContentContainer_ctl23',this);" href="http://msdn.microsoft.com/en-us/library/system.threading.compressedstack(VS.80).aspx"&gt;CompressedStack&lt;/a&gt; objects.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;.NET Framework application grant rights to the principal based on its identiy or, more commonly, its role membership.&lt;br /&gt;&lt;br /&gt;What is "Evidence"?&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/7y5x1hcd(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/7y5x1hcd(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Security Context:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.security.securitycontext(VS.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/system.security.securitycontext(VS.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Credentials Management:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa374789(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa374789(VS.85).aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-1159138346184659820?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/1159138346184659820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2009/01/reference-links-about-role-based.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1159138346184659820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1159138346184659820'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2009/01/reference-links-about-role-based.html' title='Reference links about &quot;Role-Based Security, Principal, and Identity&quot; of .NET Framework'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_JMErl8GRWoY/SWfRszvJyNI/AAAAAAAACAU/QrfmT_4WPZU/s72-c/Security.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-5396864458983891263</id><published>2008-12-30T13:33:00.000-08:00</published><updated>2008-12-30T14:25:53.319-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='COM'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperating'/><title type='text'>Interoperating with COM - Using COM from the .NET Framework (5)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How to Implement Callback Functions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Sometimes, you need to implement a function inside a managed application for unmanaged function to call to complete the task. That is a "Callback" function.&lt;br /&gt;&lt;br /&gt;Calls to a callback function pass indirectly from a managed application, through a DLL function, and back to the managed implementation. Basically, you create a callback function in your managed application, and then call the DLL function with passing a pointer to the callback function as an argument.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_JMErl8GRWoY/SVqYcSqsaQI/AAAAAAAAB-s/5SZ8_th8yuA/s1600-h/d186xcf0.pinvokecallback%28en-us,VS.90%29.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 167px;" src="http://2.bp.blogspot.com/_JMErl8GRWoY/SVqYcSqsaQI/AAAAAAAAB-s/5SZ8_th8yuA/s320/d186xcf0.pinvokecallback%28en-us,VS.90%29.gif" alt="" id="BLOGGER_PHOTO_ID_5285704724487366914" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Callback functions are ideal for use in situations in which a task is performed repeatedly. For example, The &lt;strong&gt;EnumWindows&lt;/strong&gt; function enumerates through all existing windows on your computer, calling the callback function to perform a task on each window:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;//One clue that this function requires a callback is the presence of the &lt;/span&gt;&lt;strong style="color: rgb(51, 255, 51);"&gt;lpEnumFunc&lt;/strong&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;argument. It is common to see the&lt;/span&gt; &lt;strong style="color: rgb(51, 255, 51);"&gt;lp&lt;/strong&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; (long pointer) prefix combined with the &lt;/span&gt;&lt;strong style="color: rgb(51, 255, 51);"&gt;Func&lt;/strong&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; suffix in the name of arguments that take a pointer to a callback function. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;br /&gt;Simple steps:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a function to handle callback task.&lt;/li&gt;&lt;li&gt;Create a delegate for this function.&lt;/li&gt;&lt;li&gt;Create a prototype for the COM unmanaged function, and specify the delegate as the callback function argument.&lt;/li&gt;&lt;li&gt;Call the COM unmanaged function.&lt;/li&gt;&lt;/ol&gt;Example:&lt;br /&gt;&lt;pre class="libCScode" style="white-space: pre-wrap;" id="ctl00_rs1_mainContentContainer_ctl09CSharp" space="preserve"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;//step 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;color:blue;" &gt;public&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; delegate &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;bool&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; CallBack(&lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; hwnd, &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; lParam);&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; EnumReportApp&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;  //step 3&lt;/span&gt;&lt;br /&gt; [DllImport(&lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"user32"&lt;/span&gt;&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color:blue;"&gt;  public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; extern &lt;span style="color:blue;"&gt;int&lt;/span&gt; EnumWindows(&lt;span style="font-weight: bold;"&gt;CallBack&lt;/span&gt; x, &lt;span style="color:blue;"&gt;int&lt;/span&gt; y);&lt;br /&gt;&lt;span style="color:blue;"&gt;  public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main()&lt;br /&gt; {&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;   //step 4&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold;"&gt;CallBack myCallBack = &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;new&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; CallBack(EnumReportApp.Report);&lt;/span&gt;&lt;br /&gt;  EnumWindows(&lt;span style="font-weight: bold;"&gt;myCallBack&lt;/span&gt;, 0);&lt;br /&gt; }&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;  //step 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;color:blue;" &gt;  public&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;static&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;bool&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; Report(&lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; hwnd, &lt;/span&gt;&lt;span style="font-weight: bold;color:blue;" &gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; lParam)&lt;/span&gt;&lt;br /&gt; {&lt;br /&gt;  Console.Write(&lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"Window handle is "&lt;/span&gt;&lt;/span&gt;);&lt;br /&gt;  Console.WriteLine(hwnd);&lt;br /&gt;  &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;For more information, please refer to MSDN:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/d186xcf0.aspx"&gt;Callback Functions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/843s5s5x.aspx"&gt;How to: Implement Callback Functions&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-5396864458983891263?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/5396864458983891263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_30.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/5396864458983891263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/5396864458983891263'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_30.html' title='Interoperating with COM - Using COM from the .NET Framework (5)'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_JMErl8GRWoY/SVqYcSqsaQI/AAAAAAAAB-s/5SZ8_th8yuA/s72-c/d186xcf0.pinvokecallback%28en-us,VS.90%29.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-1607404115227809994</id><published>2008-12-28T23:31:00.000-08:00</published><updated>2008-12-30T13:32:44.841-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='COM'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperating'/><title type='text'>Interoperating with COM - Using COM from the .NET Framework (4)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How to Pass Structures&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; to unmanaged functions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you called unmanaged functions in managed code, you might need to pass structures as parameters. Typically, the CLR controls the physical layout of the data fields of a class or structure in managed memory. However, sometimes, you might need to specify the layout of a structure when passing it, and you can do that by using the &lt;span style="font-weight: bold; font-style: italic;"&gt;StructLayout &lt;/span&gt;and &lt;span style="font-weight: bold; font-style: italic;"&gt;FieldOffset &lt;/span&gt;attributes. (Both are in the namespace "&lt;span style="font-weight: bold; font-style: italic;"&gt;System.Runtime.InteropServices&lt;/span&gt;")&lt;br /&gt;&lt;br /&gt;Whe using StructLayout attribute, the &lt;span style="font-weight: bold; font-style: italic;"&gt;LayoutKind.Sequential&lt;/span&gt; is used to force the data members to be laid out sequentially in the order they appear. You also can use &lt;span style="font-weight: bold; font-style: italic;"&gt;LayoutKind.Explicit&lt;/span&gt; to control precise position of each data member by applying FieldOffset attribute to each data member. If you want to give CLR full cotrol of the layout and the sequence of the fields, you can use &lt;span style="font-weight: bold; font-style: italic;"&gt;LayoutKind.Auto&lt;/span&gt; instead.&lt;br /&gt;&lt;br /&gt;Here is an example:&lt;br /&gt;&lt;pre class="libCScode" style="white-space: pre-wrap;" id="ctl00_rs1_mainContentContainer_ctl40CSharp" space="preserve"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[StructLayout(LayoutKind.Sequential)]&lt;/span&gt;&lt;br /&gt;public struct Point{&lt;br /&gt;public int x;&lt;br /&gt;public int y;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[StructLayout(LayoutKind.Explicit)]&lt;/span&gt;&lt;br /&gt;public struct Rect{&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[FieldOffset(0)]&lt;/span&gt;public int left;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[FieldOffset(4)]&lt;/span&gt;public int top;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[FieldOffset(8)]&lt;/span&gt;public int right;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[FieldOffset(12)]&lt;/span&gt;public int bottom;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Example()&lt;br /&gt;{&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[DllImport(&lt;/span&gt;&lt;span style="font-weight: bold;color:maroon;" &gt;&lt;span style="color:maroon;"&gt;"user32.dll"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;)]&lt;/span&gt;&lt;br /&gt;public static extern bool PtInRect(ref Rect r, Point p);&lt;br /&gt;}&lt;br /&gt;&lt;span style="font-family:Georgia,serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Here is the reference link from MSDN about StructLayoutAttribute:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-1607404115227809994?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/1607404115227809994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1607404115227809994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1607404115227809994'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_28.html' title='Interoperating with COM - Using COM from the .NET Framework (4)'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-1370392738725170051</id><published>2008-12-25T18:19:00.001-08:00</published><updated>2008-12-26T01:01:29.081-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='COM'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperating'/><title type='text'>Interoperating with COM - Using COM from the .NET Framework (3)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How to Call Unmanaged DLLs Using DLLImport&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Except adding a reference to unmanaged DLLs in Visual Studio, you also can import an unmanaged DLL programmatically.&lt;br /&gt;&lt;br /&gt;Using (C#) or Imports (VB.NET) &lt;span style="font-weight: bold; font-style: italic;"&gt;System.Runtime.InteropServices&lt;/span&gt; namespace and then use the &lt;span style="font-style: italic; font-weight: bold;"&gt;DllImport&lt;/span&gt; attribute to import an unmanaged DLL.&lt;br /&gt;&lt;br /&gt;Here is a sample in C# (from &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx"&gt;MSDN&lt;/a&gt;):&lt;br /&gt;&lt;pre class="libCScode" style="white-space: pre-wrap;" id="ctl00_rs1_mainContentContainer_ctl40CSharp" space="preserve"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; Example&lt;br /&gt;{&lt;br /&gt;  &lt;span style="color:green;"&gt;// Use DllImport to import the Win32 MessageBox function.&lt;/span&gt;&lt;br /&gt;  [DllImport(&lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"user32.dll"&lt;/span&gt;&lt;/span&gt;)]&lt;br /&gt;  &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; extern &lt;span style="color:blue;"&gt;int&lt;/span&gt; MessageBox(IntPtr hWnd, String text, String caption, uint type);&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main()&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color:green;"&gt;// Call the MessageBox function using platform invoke.&lt;/span&gt;&lt;br /&gt;      MessageBox(&lt;span style="color:blue;"&gt;new&lt;/span&gt; IntPtr(0), &lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"Hello World!"&lt;/span&gt;&lt;/span&gt;, &lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"Hello Dialog"&lt;/span&gt;&lt;/span&gt;, 0);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Also, you can use DLLImportAttribute's fields to have more control of the external functions. For example, if you want to call the MessageBox function using the new method name, you can specify the new function name using the &lt;span style="font-weight: bold; font-style: italic;"&gt;EntryPoint&lt;/span&gt; property.&lt;br /&gt;&lt;br /&gt;&lt;pre class="libCScode" style="white-space: pre-wrap;" id="ctl00_rs1_mainContentContainer_ctl40CSharp" space="preserve"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; Example&lt;br /&gt;{&lt;br /&gt;  &lt;span style="color:green;"&gt;// Use DllImport to import the Win32 MessageBox function.&lt;/span&gt;&lt;br /&gt;  [DllImport(&lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"user32.dll"&lt;/span&gt;&lt;/span&gt;, EntryPoint = "TestMessageBox")]&lt;br /&gt;  &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; extern &lt;span style="color:blue;"&gt;int&lt;/span&gt; MessageBox(IntPtr hWnd, String text, String caption, uint type);&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main()&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color:green;"&gt;// Call the TestMessageBox function using platform invoke.&lt;/span&gt;&lt;br /&gt;      TestMessageBox(&lt;span style="color:blue;"&gt;new&lt;/span&gt; IntPtr(0), &lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"Hello World!"&lt;/span&gt;&lt;/span&gt;, &lt;span style="color:maroon;"&gt;&lt;span style="color:maroon;"&gt;"Hello Dialog"&lt;/span&gt;&lt;/span&gt;, 0);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;For more information about DLLImportAttribute members, please visit here: &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute_members.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute_members.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-1370392738725170051?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/1370392738725170051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_3691.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1370392738725170051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/1370392738725170051'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_3691.html' title='Interoperating with COM - Using COM from the .NET Framework (3)'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-8215703237881363131</id><published>2008-12-25T15:25:00.001-08:00</published><updated>2008-12-28T20:10:13.045-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='COM'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperating'/><title type='text'>Interoperating with COM - Using COM from the .NET Framework (2)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How to Import a Type Library Using the Type Library Importer (Tlbimp.exe)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can use the Type Library Importer (Tlbimp.exe) to create an interop assembly which will allow your .NET application to use a type defined in it.&lt;br /&gt;&lt;br /&gt;How to use Tlbimp.exe:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Open  a Visual Studio Command Prompt (under the "Visual Studio Tools" menu of the "Start" menu)&lt;/li&gt;&lt;li&gt;Use "&lt;span style="font-weight: bold; font-style: italic;"&gt;Tlbimp.exe /?&lt;/span&gt;" or "&lt;span style="font-weight: bold; font-style: italic;"&gt;Tlbimp /help&lt;/span&gt;" to see the usage message.&lt;/li&gt;&lt;li&gt;Sample:&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Tlbimp.exe C:\test\MSO9.dll&lt;/span&gt;  (By default, it will generate the file base on the name of the type library contained within the original COM dll file.)&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Tlbimp.ee C:\test\MSO9.dll /out:NewNameOffice.dll&lt;/span&gt;  (Or you can use /out to specify the name of output file.)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The namespace of the imported library uses the same name as that of the library from which it was created by default. You can use this to change the namespace:&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Tlbimp.exe MSO9.dll /namespace:MyNewNameSpace&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;After you create the new assembly dll by using Tlbimp.exe, you can then add a reference to it and use the types just as you would use a native .NET Framework type.&lt;br /&gt;&lt;br /&gt;For more information about Tlbimp.exe, you can visit here: &lt;a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx.aspx"&gt;http://msdn.microsoft.com/en-us/library/tt0cf3sx.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-8215703237881363131?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/8215703237881363131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_25.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/8215703237881363131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/8215703237881363131'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from_25.html' title='Interoperating with COM - Using COM from the .NET Framework (2)'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-162156076437308662</id><published>2008-12-22T13:40:00.000-08:00</published><updated>2008-12-22T15:00:52.873-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='COM'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperating'/><title type='text'>Interoperating with COM - Using COM from the .NET Framework (1)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How to Add a Reference to a COM Library or Type Library&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;COM libraries contain classes, methods, and types.&lt;br /&gt;COM types are defined in a type library which can be a stand-alone .tlb file or can be embedded in a .dll, .exe, .ocx, or .olb file.&lt;br /&gt;&lt;br /&gt;The easiest way to access a COM library or type library file in . NET framework application is to add a reference to it from Visual Studio, and then you can use the methods in it.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Open your project or create a new project in Visual Studio.&lt;/li&gt;&lt;li&gt;Go to "Project" menu, click "Add Reference". (Or right-click "References" folder of your project, and select "Add Reference".)&lt;/li&gt;&lt;li&gt;Click "COM" tab, and select a COM component from the list&lt;/li&gt;&lt;li&gt;Or you can click "Browse" tab to select a file. Then click OK.&lt;/li&gt;&lt;/ol&gt;After you add a reference to the COM component, Visual Studio will automatically create a assembly version of that COM file with Interop.*.dll name. For example, if you add MSO9.dll (Microsoft Office 9.0 Object Library) to the reference, VS will create a Interop.Office.dll, while "Office" is the namespace of the COM file.&lt;br /&gt;&lt;br /&gt;Moreover, you can see the new reference in your References folder of your project. You can double-click it to open it in Object Browser to see its namespace, methods, classes...etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-162156076437308662?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/162156076437308662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/162156076437308662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/162156076437308662'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/interoperating-with-com-using-com-from.html' title='Interoperating with COM - Using COM from the .NET Framework (1)'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7733893741350207472.post-7399343617208686429</id><published>2008-12-21T15:08:00.000-08:00</published><updated>2008-12-21T15:27:45.439-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CAS'/><category scheme='http://www.blogger.com/atom/ns#' term='Code Access Security'/><title type='text'>Code Access Security (CAS) of .NET Framework</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Code Access Security (CAS)&lt;/span&gt; is a security system that allows administrators/developers to control application authorization to access system resources in a similar way like they authorize users. (Role-Based Secuirty, RBS)&lt;br /&gt;&lt;br /&gt;CAS: authorize applications (managed assemblies)&lt;br /&gt;RBS: authorize roles&lt;br /&gt;&lt;br /&gt;CAS is implmented by using the following components:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Evidence: identify an assembly&lt;/li&gt;&lt;li&gt;Permissions: describe which resources an assembly (decided by Evidence) can access&lt;/li&gt;&lt;li&gt;Permission Sets: collect multiple permissions&lt;/li&gt;&lt;li&gt;Code Groups: assign permissions (permission set) to an assembly based on evidence&lt;/li&gt;&lt;/ul&gt;A Security Policy: a logical grouping of code groups and permission sets.&lt;br /&gt;&lt;br /&gt;An assembly receives the most restrictive set of permissions assigned by each of the policy levels within CAS control. Moreover, the final effective permissions of an assembly are the intersection of permissions granted by CAS and by OS.&lt;br /&gt;&lt;br /&gt;Two ways to configure any aspect of CAS:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;.NET Framework Configuration tool: It's a graphical tool. Go to "Control Panel" &gt; "Administrative Tools" &gt; "Microsoft .NET Framework 2.0 Configuration"&lt;/li&gt;&lt;li&gt;Caspol (The Code Access Security Policy Tool): It's a command-line tool. For more information about this tool, please refer to this MSDN page: &lt;a href="http://msdn.microsoft.com/en-us/library/cb6t8dtz%28VS.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cb6t8dtz(VS.80).aspx&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7733893741350207472-7399343617208686429?l=studydotnetframework.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://studydotnetframework.blogspot.com/feeds/7399343617208686429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/code-access-security-cas-of-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/7399343617208686429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7733893741350207472/posts/default/7399343617208686429'/><link rel='alternate' type='text/html' href='http://studydotnetframework.blogspot.com/2008/12/code-access-security-cas-of-net.html' title='Code Access Security (CAS) of .NET Framework'/><author><name>Will</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_JMErl8GRWoY/SJ-I13WvtMI/AAAAAAAABZk/CaYQlc_zPxs/s1600-R/haircut.JPG'/></author><thr:total>0</thr:total></entry></feed>
