C#调用Win32 API

来源:互联网 发布:微信排雷软件 编辑:程序博客网 时间:2024/05/16 00:53

http://www.cnblogs.com/benwu/p/4132026.html

https://msdn.microsoft.com/zh-cn/library/windows/desktop/ff818516(v=vs.85).aspx


1.通过URL获取域名:

将hashvalue.dll放入bin中,并右键项目->属性-》build-》平台:x64:

 [DllImport("hashvalue.dll", EntryPoint = "GetUrlDomainW", CharSet = CharSet.Unicode)]        public static extern bool GetUrlDomain(            string url,            ref UInt32 domainBegin,            ref UInt32 domainLength);

public static string GetUrlDomain(string url)        {            UInt32 uDomainBegin = 0;            UInt32 uDomainLength = 0;            GetUrlDomain(url, ref uDomainBegin, ref uDomainLength);            return url.Substring((int)uDomainBegin, (int)uDomainLength);        }
string domain =GetUrlDomain("http://www.microsoft.com/test.html");//microsoft.com


2.messagebox:

  [DllImport("User32.dll")]        public static extern int MessageBox(int h, string m, string c, int type);



0 0
原创粉丝点击