[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,这样的参数。
谢谢
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,这样的参数。
谢谢
应用非托管代码..user32 实际就是 user32.dllEntryPoint 给出 dll 中入口点的名称。如果未指定 EntryPoint,那就是本身名字
[MarshalAs(UnmanagedType.AsAny)] 这个表示非托管里的动态类型..也就是说可能是Point SizeF StringBuilder在C#里用object
因为SendMessage 最后一个参数..返回的类型是动态的.
你可以把他当成是C#的硬性规定
就象一句代码一定需要;来结束一样
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);
};
}
www.interop123.com 豆瓣网信息:
http://www.douban.com/subject/3671497/