极度郁闷中,,,,,,,,高人进来~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
taoyi 2005-08-19 09:20:04 代码如下:
public class Ftp
{
#region 私有成员
//-------------------------------------------------------------------------------
1.
//private string host = "";
//private string user = "";
//private string password = "";
//private int port = 21;
//private string url = "";
//private string destPath = "";
//-----------------------------------------------------------------------------
2.
private string host;
private string user;
private string password;
private int port = 21;
private string url;
private string destPath;
//-------------------------------------------------------------------------------
private static MessageCallBackFunc lpMsg = null;
private static PacketRecvCallBackFunc lpPackRecv = null;
private static FileCompleteCallBackFunc lpFileComp = null;
#endregion
#region 回调函数
public delegate void MessageCallBackFunc(string msg);
public delegate void PacketRecvCallBackFunc(string file, int totalBytes, int bytesRecved);
public delegate void FileCompleteCallBackFunc(string file);
#endregion
#region API
[DllImport("FTP.dll", EntryPoint="FtpDownload",CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
private static extern void _Download(string host, string user, string pass,
int nPort, string url, string locaFile,
MessageCallBackFunc lpMsg, PacketRecvCallBackFunc lpPackRecv,
FileCompleteCallBackFunc lpFileComp);
#endregion
#region 属性
public String Host
{
get
{
return this.host;
}
set
{
if (value.Length == 0)
throw new Exception("Host空参数异常");
this.host = value;
}
}
public String UserID
{
get
{
return this.user;
}
set
{
if (value.Length == 0)
throw new Exception("UserID空参数异常");
this.user = value;
}
}
public String Password
{
get
{
return this.password;
}
set
{
if (value.Length == 0)
throw new Exception("Password空参数异常");
this.password = value;
}
}
public int Port
{
get
{
return this.port;
}
set
{
if (value == 0)
this.port = 21;
else
this.port = value;
}
}
public string DownFile
{
get
{
return this.url;
}
set
{
if (value.Length == 0)
throw new Exception("DownFile空参数异常");
this.url = value;
}
}
public string DestPath
{
get
{
return this.destPath;
}
set
{
if (value.Length == 0)
throw new Exception("DestPath空参数异常");
this.destPath = value;
}
}
#endregion
#region 构造及析构
public Ftp(MessageCallBackFunc lpMsg, PacketRecvCallBackFunc lpPackRecv, FileCompleteCallBackFunc lpFileComp)
{
if (lpMsg != null)
lpMsg = lpMsg;
if (lpPackRecv != null)
lpPackRecv = lpPackRecv;
if (lpFileComp != null)
lpFileComp = lpFileComp;
}
~Ftp()
{
}
#endregion
#region 方法申明
public void DownloadEx(string url, string localFile)
{
this.url = url;
Ftp._Download(this.host, this.user, this.password, this.port, this.url, localFile,
lpMsg, lpPackRecv, lpFileComp); <=============此处出现"未将对象引用设置为对象的实例"异常
}
public void DownloadEx()
{
string shortname = this.url.Substring(this.url.LastIndexOf("/") + 1,
this.url.Length - this.url.LastIndexOf("/") - 1);
Ftp._Download(this.host, this.user, this.password, this.port, this.url, this.destPath + "\\" + shortname,
lpMsg, lpPackRecv, lpFileComp);
}
}
如果将上面1处注释的代码替换为2外的代码,则在_Download调用处出现未将对象引用设置为对象实例的异常,如果使用2处的代码,则_Download有时会出现同样的异常,但却没有规律,,,,,极度郁闷中~~~~~
代码1处和2处的差别只是加了成员变量的初始化,为啥就这么一加就运行效果就那么大的差别,哪位高人指点一二,,,,,,,偶快疯掉了~~~~~~~~~~~~