您的位置:首页 > 其它

访问和调用外部组件

2005-08-25 23:52 204 查看
访问.NET和COM组件
创建引用 Add Reference
使用 using 关键字

实例化ActiveX控件
添加引用
添加到Toolbox
拖放控件或代码方式

访问Web Service
添加web 引用 Add Web Reference
实例化 webService1 myService = new WebService1();
调用 myService.myMethod();
异步调用


public class AsyncDemo
{
WebService1 myService;
public void CallMethodAsynchronously()
{
myService = new WebService1();
System.AsyncCallback myCallBack = new System.AsyncCallback(CallBack);
myService.BeginMyMethod(myCallBack,new object());
}
public void CallBack(IAsyncResult e)
{
string myString;
myString = myService.EndMyMethod(e);
}
}
采用回调方式
public void AsyncDemo()
{
WebService1 myService = new WebService1();
IAsyncResult Async;
//为回调方法创建委托
System.AsyncCallback myCallBack = new System.AsyncCallback(SomeMethod);
Async = myService.BeginMyMethod(myCallBack,new object());
string myString;
//程序暂停,直到调用返回
myString = myService.EndMyMethod(Async);
}

访问Windows API
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int Beep(int dwFreq, int dwDuration);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐