[System.Runtime.InteropServices.DllImport("user32", EntryPoint="SendMessageA")] 
static extern int SendMessage(int hwnd, int wMsg, int wParam,  [MarshalAs(UnmanagedType.AsAny)] 
object lParam); 
[System.Runtime.InteropServices.DllImport("user32", EntryPoint="SetWindowPos")] 
static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); 
[System.Runtime.InteropServices.DllImport("user32")] 
static extern bool DestroyWindow(int hndw); 
[System.Runtime.InteropServices.DllImport("avicap32.dll")] 
static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID); 
[System.Runtime.InteropServices.DllImport("avicap32.dll")] 
static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer);特别是 [MarshalAs(UnmanagedType.AsAny)]object lParam,这样的参数。
谢谢

解决方案 »

  1.   

    .net 技术交流群34938110 
      

  2.   

    System.Runtime.InteropServices.DllImport 
    应用非托管代码..user32 实际就是 user32.dllEntryPoint 给出 dll 中入口点的名称。如果未指定 EntryPoint,那就是本身名字
    [MarshalAs(UnmanagedType.AsAny)] 这个表示非托管里的动态类型..也就是说可能是Point SizeF StringBuilder在C#里用object 
    因为SendMessage 最后一个参数..返回的类型是动态的.
      

  3.   

    [MarshalAs(UnmanagedType.AsAny)]object lParam
    你可以把他当成是C#的硬性规定
    就象一句代码一定需要;来结束一样
      

  4.   

    System.Runtime.InteropServices.DLLimpor是其中的一个方法。调用DLL的API 接口
      

  5.   

    用MarshalAs 标记布尔型 P/Invoke 参数
      

  6.   

    下面的示例演示两个标记有相应 MarshalAsAttribute 属性的平台调用方法。Visual Basic
    Imports System
    Imports System.Runtime.InteropServices<assembly: ComVisible(False)>
    Namespace UsageLibrary   <ComVisible(True)> _
       Class NativeMethods      Private Sub New()
          End Sub      <DllImport("user32.dll", SetLastError := True)> _
          Friend Shared Function MessageBeep(uType As UInt32) _
             As <MarshalAs(UnmanagedType.Bool)> Boolean
          End Function      <DllImport("mscoree.dll", SetLastError := True)> _
          Friend Shared Function StrongNameSignatureVerificationEx( _
             <MarshalAs(UnmanagedType.LPWStr)> wszFilePath As String, _
             <MarshalAs(UnmanagedType.U1)> fForceVerification As Boolean, _
             <MarshalAs(UnmanagedType.U1)> ByRef pfWasVerified As Boolean) _
             As <MarshalAs(UnmanagedType.U1)> Boolean
          End Function   End ClassEnd NamespaceC#
    using System;
    using System.Runtime.InteropServices;[assembly: ComVisible(false)]
    namespace InteroperabilityLibrary
    {
       [ComVisible(true)]
       internal class NativeMethods
       {
          private NativeMethods() {}      [DllImport("user32.dll", SetLastError = true)]
          [return: MarshalAs(UnmanagedType.Bool)]
          internal static extern Boolean MessageBeep(UInt32 uType);      [DllImport("mscoree.dll", 
                     CharSet = CharSet.Unicode, 
                     SetLastError = true)]
          [return: MarshalAs(UnmanagedType.U1)]
          internal static extern bool StrongNameSignatureVerificationEx(
             [MarshalAs(UnmanagedType.LPWStr)] string wszFilePath,
             [MarshalAs(UnmanagedType.U1)] bool fForceVerification,
             [MarshalAs(UnmanagedType.U1)] out bool pfWasVerified);
       }
    }Visual C++
    using namespace System;
    using namespace System::Runtime::InteropServices;[assembly: ComVisible(false)];
    namespace InteroperabilityLibrary
    {
       [ComVisible(true)]
       ref class NativeMethods
       {
       private:
          NativeMethods() {}   internal:
          [DllImport("user32.dll", SetLastError = true)]
          [returnvalue: MarshalAs(UnmanagedType::Bool)]
          static Boolean MessageBeep(UInt32 uType);      [DllImport("mscoree.dll", 
                     CharSet = CharSet::Unicode, 
                     SetLastError = true)]
          [returnvalue: MarshalAs(UnmanagedType::U1)]
          static bool StrongNameSignatureVerificationEx(
             [MarshalAs(UnmanagedType::LPWStr)] String^ wszFilePath,
             [MarshalAs(UnmanagedType::U1)] Boolean fForceVerification,
             [MarshalAs(UnmanagedType::U1)] Boolean^ pfWasVerified);
       };
    }
      

  7.   

    window API这个玩儿得查微软的手册,
      

  8.   

    调用API啊,这个还是按11楼说的,查API手册吧
      

  9.   

    有关MashallAs属性,我建议阅读刚刚出版的新书:《精通.NET互操作P/Invoke,C++Interop和COM Interop》,这本书中的第2章“数据封送”详细介绍了这个属性的作用和使用方法。 该书的官方网站: 
    www.interop123.com 豆瓣网信息: 
    http://www.douban.com/subject/3671497/