using System.Runtime.InteropServices;
[DllImport("gdi32.dll")]
private static extern int GetPixel (IntPtr hdc , int x1,int y1);[DllImport("gdi32.dll")]
private static extern int SetPixel (IntPtr hdc , int x1,int y1,int color);
[DllImport("gdi32.dll")]
private static extern int GetPixel (IntPtr hdc , int x1,int y1);[DllImport("gdi32.dll")]
private static extern int SetPixel (IntPtr hdc , int x1,int y1,int color);
解决方案 »
- 关于sql server mobile 2005数据库操作问题
- 中文与日文全半角兼容问题?
- 用using语句来自动释放资源时,到底哪些对象可以用using语句啊?
- C# 调用 vb.net 编写的组件时出错
- select top 5 * from table order by (id) desc
- C#链表的问题紧急求助
- e.Graphics.DrawString() 怎么实现让字符串显示在矩形中间?谢谢!
- 急急急 C# 启动外部EXE,指定工作路径,调试可以用.打包软件后,EXE无法启动
- 怎样用GDI+绘制矢量图,能不能进行矢量绘图
- 如何高效的开发控件?
- 怎样才能学好 .net
- C#中如何调用.OCX中的函数?被调函数含有“VARIANT FAR*”参数?
// Copyright
// Microsoft Corporation
// All rights reserved// MsgBox.csusing System;
using System.Runtime.InteropServices;public class LibWrap
{
// int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
[ DllImport( "User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Auto )]
public static extern int MsgBox( int hWnd, String text, String caption, uint type );
// this will cause incorrect output in message window
[ DllImport( "User32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Ansi )]
public static extern int MsgBox2( int hWnd, String text, String caption, uint type );
// this will cause an exception
[ DllImport( "User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Ansi, ExactSpelling=true )]
public static extern int MsgBox3( int hWnd, String text, String caption, uint type );
}public class MsgBoxSample
{
public static void Main()
{
LibWrap.MsgBox( 0, "Correct text", "MsgBox Sample", 0 );
LibWrap.MsgBox2( 0, "Incorrect text", "MsgBox Sample", 0 );
try
{
LibWrap.MsgBox3( 0, "No such function", "MsgBox Sample", 0 );
}
catch( EntryPointNotFoundException )
{
Console.WriteLine( "EntryPointNotFoundException thrown as expected!" );
}
} private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult r = MessageBox.Show ( "是否关闭窗口!" , "关闭窗口!" , MessageBoxButtons.YesNo , MessageBoxIcon.Question ) ;
if (!(DialogResult.Yes ==r))
{
e.Cancel = true;
}
}
}
ms-help://MS.VSCC/MS.MSDNVS.2052/vbcn7/html/vaconCallingWindowsAPIs.htm
如果是字符串指针,在C#中用StringBuilder,用BYTE[]也行;
如果是int或long用int,是指针的话加一个ref或out;
其它的我也不多说了,只要注意到这点后,上网可以找些东东看看,还有是结构也要注意一下。