MF 的个人资料CMF.net照片日志列表更多 工具 帮助
 

取得網路磁碟機及其路徑的對照 (VB.NET)

 
  '   TO  UNC Path
' ================================================================
  Imports System.Runtime.InteropServices
 ...
     Dim bufSize As Int32 = 2000
     Dim bufPtr As IntPtr = Marshal.AllocHGlobal(bufSize)
     Dim ret As Int32 = WNetGetUniversalName("Z:\", 2, bufPtr, bufSize)
     If ret = 0 Then
         Dim remNil As New RemoteNIL()
         Marshal.PtrToStructure(bufPtr, remNil)
     End If
     Marshal.FreeHGlobal(bufPtr)
 ...
     <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), Serializable()> Class RemoteNIL
         <MarshalAs(UnmanagedType.LPTStr)> Public UniversalName As String
         <MarshalAs(UnmanagedType.LPTStr)> Public ConnectionName As String
         <MarshalAs(UnmanagedType.LPTStr)> Public RemainingPath As String
     End Class
 ...
     <DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
     Function WNetGetUniversalName( _
         ByVal lpLocalPath As String, _
         ByVal dwInfoLevel As Int32, _
         ByVal lpBuffer As IntPtr, _
         ByRef lpBufferSize As Int32) As Int32
     End Function
 
 
1月30日

加入參考 System.Design 組件 (.NET)

 
 方案總管  ->  右鍵選單  ->  加入參考
 
Add System.Design
 

命名空間: System.ComponentModel.Design
組件: System.Design (在 system.design.dll 中)

System.ComponentModel.Design 命名空間 (Namespace) 包含的類別,可供開發人員用來建置 (Build) 元件的自訂設計階段行為以及在設計階段設定元件的使用者介面。設計階段環境提供讓開發人員排列元件和設定其屬性的系統。有些元件可能需要僅適用設計階段的行為,才能在設計階段環境中正常作用。提供協助開發人員設定元件或複雜資料型別值的自訂使用者介面可能也頗有價值。在此命名空間內定義的類別和介面,也可以用來建置元件的自訂設計階段行為、存取設計階段服務以及實作自訂的設計階段組態介面

說明文件

http://msdn2.microsoft.com/zh-tw/library/system.componentmodel.design(VS.80).aspx

 

Visual Studio 2008 中文版 2008 年 2 月 1 日正式發表

 
Visual Studio 2008 中文版 2008 年 2 月 1 日正式發表
 

劃下 Visual Studio 2008 等待的休止符!中文版 2008 年 2 月 1 日正式發表!

台灣微軟將於 2008 年 2 月 1 日 正式發表 Visual Studio 2008 與 .NET Framework 3.5 。Visual Studio 2008 包含超過 250 個新功能,在每個版本中都包括重大的增強功能,包括 Visual Studio Express 與 Visual Studio Team System。所有層級的開發人員 (從開發者到企業開發團隊) 現在都有一致、安全和可靠的解決方案來替最新平台 (Web、Windows Vista、Windows Server 2008、2007 Office system 等等) 開發應用程式。 進一步瞭解 Visual Studio 2008

若需有關解除安裝 Visual Studio 2008 預先發行版本的說明,請瀏覽 解除安裝 Visual Studio 2008 預先發行版本





 

體驗生產力大躍進

建立不同凡響的使用者經驗

橫跨開發週期的協同作業

使用嶄新的視覺設計工具以及超過 50 項嶄新控制,來更快速地建立和部署 Windows 和 Web 應用程式 ,並能透過 LINQ 更順暢地運用來自任何資料來源的資訊。

利用 2007 Microsoft Office System 和 Windows Vista 使用者經驗與功能建立引人注目的解決方案,並可以建立運用 ASP.NET AJAX 互動式 Web 介面構成的多樣化與高互動之應用程式。

整個團隊可以更有效地共同作業與通訊以確保軟體品質,並透過 Visual Studio Team System 提供開發程序的可見度。

 

 

 

1月25日

取得網路磁碟機及其路徑的對照 (C#)

//  Get UNC Path
 

    [DllImport("mpr.dll")]
        [return: MarshalAs(UnmanagedType.U4)]
        static extern int WNetGetUniversalName(
                string lpLocalPath,
                [MarshalAs(UnmanagedType.U4)] int dwInfoLevel,
                IntPtr lpBuffer,
                [MarshalAs(UnmanagedType.U4)] ref int lpBufferSize);

       [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode), Serializable()]
        class MyUNC
        {
                [MarshalAs(UnmanagedType.LPStr)]
                public string UniversalName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string ConnectionName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string RemainingPath;
        }
        [STAThread]
        static void Main()
        {
                int bufferSize = 2000;
                IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
                int ret = WNetGetUniversalName("Z:", 2, buffer, ref bufferSize);
                if (ret == 0)
                {
                        MyUNC unc = new MyUNC();
                        Marshal.PtrToStructure(buffer, unc);
                        Console.WriteLine(unc.UniversalName);
                }
                Marshal.FreeHGlobal(buffer);
                return;
        }

 說明文件

說明文件

===============================
範例2
 
Converting network drive-based path to universal path name

'The following code shows how to use the WNetGetUniversalName for converting
'network drive-based path (Like I:\windows) to universal path name (Like \\MyComputer\c\windows)
'
Private Declare Function WNetGetUniversalName Lib "mpr" Alias "WNetGetUniversalNameA" _
(ByVal lpLocalPath As String, ByVal dwInfoLevel As Long, lpBuffer As Any, lpBufferSize As Long) As Long

Private Const UNIVERSAL_NAME_INFO_LEVEL = 1
Private Const REMOTE_NAME_INFO_LEVEL = 2
Private Const UNIVERSAL_NAME_BUFFER_SIZE = 1000
Private Const NO_ERROR = 0

Private Type UNIVERSAL_NAME_INFO
    lpUniversalName                         As Long
    buf(UNIVERSAL_NAME_BUFFER_SIZE - 4)     As Byte
End Type

Private Sub cmdGetUniversal_Click()
    Dim BufSize         As Long
    Dim uni             As UNIVERSAL_NAME_INFO
    
    BufSize = UNIVERSAL_NAME_BUFFER_SIZE
    If WNetGetUniversalName(txtPath.Text, UNIVERSAL_NAME_INFO_LEVEL, uni, BufSize) = NO_ERROR Then
        'After we return from WNetGetUniversalName, the lpUniversalName contains a pointer for the 
	'universal path name.
        'The pointer is usually points to the first byte of the buffer array 
	'(buf variable in UNIVERSAL_NAME_INFO ).
        
	'Just to be safe, I calculate the exact location of the string in the buffer, 
	'by the following expression: (The result is always 1)
        StartLoc = uni.lpUniversalName - VarPtr(uni) - 3
        txtUniversal.Text = Mid$(StrConv(uni.buf, vbUnicode), StartLoc)
    Else
        MsgBox "Error: cannot find the universal path of " & txtPath.Text, vbOKOnly Or vbExclamation, ""
    End If
    
End Sub


 
 
1月23日

取得 電腦中已安裝的 序列埠 數量 (Using VC++ 2008 MFC)

 
//  GET   SERIAL PORTS
 
   void  CMFC_Dlg::OnBnClicked()
{
 
    long   lReturn   =   0;    
     HKEY   hk;  
     LPCTSTR   data_Get = _T("HARDWARE\\DEVICEMAP\\SERIALCOMM");  
      //在註冊表裡的位置  
    lReturn   =   ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Get,0,KEY_READ,&hk);  
 
    //通過ERROR_SUCCESS判斷打開是否成功。    
 if(lReturn   !=   ERROR_SUCCESS)  
      MessageBox(_T("打開註冊表1出現錯誤!"), _T("錯誤"));  
 else{  
     DWORD NumValues;
     ::RegQueryInfoKey(hk,0,0,0,0,0,0,&NumValues,0,0,0,0);
 
      CString  str_ComPortNum;
     str_ComPortNum.Format(_T("Com Port Num=%d"), NumValues);

  
    AfxMessageBox(str_ComPortNum);
   }
  ::RegCloseKey(hk);

}
 
 
說明文件

RegOpenKeyEx Function (Windows)

 

RegQueryInfoKey Function (Windows)

 
 
1月22日

.Net 取得 執行檔 所放置的目錄 (C#)

 
  private void button1_Click(object sender, EventArgs e)
        {
        
            String ExePath=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            MessageBox.Show(ExePath);
            
        }
 
說明文件

Assembly.GetExecutingAssembly 方法(System.Reflection)

Assembly.Location 屬性(System.Reflection)

Path.GetDirectoryName 方法(System.IO)

 

 

 

.NET 取得 執行檔 的 起始路徑(C#)

 
 
        private void button1_Click(object sender, EventArgs e)
        {        
            MessageBox.Show(Application.StartupPath);            
        }
 
 
說明文件:

Application.StartupPath 屬性(System.Windows.Forms)