www.red-gate.com网站淘宝之旅

  现在说起应该是昨天的事了,我没啥事在网上“淘些宝贝”,我网上淘宝当然不是买东西,是上国外网上搜集些开源GIS和.NET Plateform Invoke(简写为PInvoke)资料。主要是讲一下我在http://www.red-gate.com/网站淘宝之旅。

     淘宝一:PInvoke.net

  在google上搜索发现http://www.pinvoke.net/网站,就是个Wiki形式的PInvoke技术站点,算是个技术资料库吧。该网站采用WIKI形式,这点我很欣赏,只是知名度不高或是深入了解PInvoke的网友较少吧,所以网站给人很冷清的感觉。从WIN 32 API 查询价值看,该网站API内容不全,根本跟MSDN不是一个档次的,但是它又有个值得使用的优点:它给出了WIN 32 API在C#/VB语言中声明的方式,对初学NET互操作的还是很方便的工具,至少保证声明处不会出错了。

      该网站提供了PInvoke.net Visual Studio Add-in 插件下载PInvoke.net。安装完成后,在VS的工具栏中出现PInvoke.net,截图如下:

www.red-gate.com网站淘宝之旅_第1张图片

点击PInvoke.net按钮,弹出窗体,你可以在里面搜索WIN 32 API,选择目标函数,会出现Signature里加亮显示部分,就是该API在C#中的声明,点击Insert,自动在你代码里插入声明部分。此处可参看http://www.winu.cn/space-14160-do-blog-id-28045.html,里面有个使用入门过程及一个DEMO。现在引用DEMO源码如下:

PInvoke获取短路径名代码

namespace  ShortPathNameSample
{
    
class  Program
    {
        [DllImport(
" kernel32.dll " , CharSet  =  CharSet.Auto, SetLastError  =   true )]
        
static   extern   uint  GetShortPathName(
          [MarshalAs(UnmanagedType.LPTStr)]
             
string  lpszLongPath,
          [MarshalAs(UnmanagedType.LPTStr)]
           StringBuilder lpszShortPath,
          
uint  cchBuffer);

        
static   void  Main()
        {
            Console.WriteLine(GetShortPathName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)));
            Console.ReadLine();

        }
        
///   <summary>
        
///  
        
///   </summary>
        
///   <param name="longName"> The long name path </param>
        
///   <returns> A short name path string </returns>
         public   static   string  GetShortPathName( string  longName)
        {
            StringBuilder shortNameBuffer 
=   new  StringBuilder( 256 );
            
uint  bufferSize  =  ( uint )shortNameBuffer.Capacity;
            
uint  result  =  GetShortPathName(longName, shortNameBuffer, bufferSize);
            
if  (result  !=   0 )
                
return  shortNameBuffer.ToString();
            
return  longName;
        }
    }
}

     官方给了个DEMO:How PInvoke.net can help(http://www.red-gate.com/products/pinvoke.net/example.htm) 由于官方内容比较好,我这里与大家分享全文引用如下:

How PInvoke.net can help (Native method signatures )

Problem: disabling the Close button

Sometimes, in an application, you want to have a window which has a control box (and thus an icon) that can be minimized and/or maximized, but cannot be closed. This requires a little work, but an important step is to disable the Close button in the top right of the window. In .NET you can set Form.ControlBox to false, but that will get rid of your minimize and maximize icons as well, which may not be what you want.

Desired effect: Close is disabled, but Minimize still works.

In cases such as this one, it's necessary to "go native". To achieve this effect, we will need to disable the Close option on the system menu. When Windows renders the close box in the non-client area, and handles clicks on it, it obeys the state of that menu item.

www.red-gate.com网站淘宝之旅_第2张图片 

The Close tab on the system menu needs to be greyed out as in this screenshot.

Find a solution with PInvoke.net

We will need to call two functions: GetSystemMenu and EnableMenuItem. In the latter case, we need to tell EnableMenuItem to find the menu item denoted by command SC_CLOSE, and make it either enabled or grayed out, as appropriate.

Since we don't know the exact syntax of the two signatures we are after, we can simply choose to insert them directly from Visual Studio, by clicking on our PInvoke.net menu in Visual Studio.

The PInvoke.net website suggests the following code:

www.red-gate.com网站淘宝之旅_第3张图片

PInvoke.net often offers both a C# signature and a VB signature

www.red-gate.com网站淘宝之旅_第4张图片

C# signature for EnableMenuItem

Via the website, PInvoke.NET also lists appropriate constant values for EnableMenuItem, three of which are of particular interest:

 

Constant values for EnableMenuItem

We also need the constant value SC_CLOSE which, again, is easily found on PInvoke.net by typing it into the search box:

internal const UInt32 SC_CLOSE = 0xF060;

We've now got all our pieces, which we can finally put together by writing code such as:

// Modify the close button for a form or other window.

            public static void EnableCloseButton(IWin32Window window, bool bEnabled)

            {

                  IntPtr hSystemMenu = GetSystemMenu(window.Handle,false);

                  EnableMenuItem(hSystemMenu,

                        SC_CLOSE,

                        (uint)(MF_BYCOMMAND | ( bEnabled ? MF_ENABLED : MF_GRAYED ) ));

            }

This was an example illustrating how the PInvoke.net resource and the PInvoke.net Visual Studio add-in can help you find and insert tried and tested PInvoke signatures directly into your application.

         淘宝二:.NET Reflector

         .NET Reflector是免费的.net反编译软件,以前也用过,但昨天刚知道原来也是RED-GATE的产品,该软件是免费的,最新版为.NET Reflector 6.0 下载

请参考官方:http://www.red-gate.com/products/reflector/index.htm

使用视频:http://www.red-gate.com/products/reflector/video.htm

         淘宝三:.NET Buddle (最新版官方售价:$795)

          NET Buddle里面有3个收费产品,截图如下:

www.red-gate.com网站淘宝之旅_第5张图片

       我关注的产品主要是前两个,当软件代码量较大时,就会出现很多难以认为控制的因素,如果处理数据量再较大,很容易出现问题。我之前参与的一个软件编写,当处理大数据量时,出现严重问题。最后查找原因:发现是大量共有变量没有及时释放,同时AE中的COM游标类组件没有及时释放,导致内存不足。痛定思痛,我一方面提高自己写代码的严谨性,一方面格外关注提高.NET编程性能的辅助工具。三个工具是很不错,只是网站上之提供14天的试用下载。我当然是买不起这套.NET工具了,想想VS.net都用破解的,这类小工具肯定也希望找到破解的。网上搜索了一下,终于让我找到5.0破解版了,与感兴趣的网友分享:http://download.csdn.net/source/1438956#acomment 破解版中还包括了一些SQL工具。

       淘宝四:swfobject.js

       swfobject.js是Javascript脚本,主要功能是在网页中动态创建SWF对象,并设置SWF对象的参数。下载1.5版

      使用实例代码:

      
    
< div id = " flashcontent " >< / div> 
       
    
< script type = " text/javascript "  src = " 640x480/swfobject.js " >< / script>
           < script type = " text/javascript "  src = " 640x480/NET_Reflector_640x480_210808.js " >< / script>
      
< script type = " text/javascript " >
          
//  <![CDATA[          
          var  fo  =   new  SWFObject(  " 640x480/NET_Reflector_640x480_210808_controller.swf " " csSwf " " 640 " " 499 " " 8 " " #FFFFFF "  );
         fo.addVariable(  " csConfigFile " " 640x480/NET_Reflector_640x480_210808_config.xml "   ); 
         fo.addVariable(  " csColor "      ,  " FFFFFF "            );
         fo.addVariable(  " csPreloader "  ,  " 640x480/NET_Reflector_640x480_210808_preload.swf "  );
fo.addVariable(  " csScaleLoadingMov "  ,  " true "  );
         
if ( args.movie )
         {
            fo.addVariable(  " csFilesetBookmark " , args.movie );
         }
         fo.write( " flashcontent " );                  
         
//  ]]>

       
< / script>

 

 

       希望自己以后能将昨天淘到的几件宝贝在开发中运用起来,提高开发效果!

       另附一个微软Invoke工具:P/Invoke Interop Assistant 

参考资料:http://www.cnblogs.com/wuhenke/archive/2010/01/24/1655131.html

 

你可能感兴趣的:(com)