none
FtpGetCurrentDirectory返回FALSE RRS feed

  • 问题

  • 我的FTP链接已经打开了 但是获取不到目录

    窗口过程如下

    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static int x_width,y_width,x_char_width,y_char_width;
    	static HWND upload_button,file_list,FTP_server,username,password,FTP_server_text,username_text,password_text;
    	static HWND download_button,login_button,exit_button;
    	static HINSTANCE hInstance;
    	static HINTERNET Internet_session,Ftp_session,find;
    	HDC hdc;
    	TCHAR FTP_server_str[22],username_str[22],password_str[22],path_str[MAX_PATH+1];
    	DWORD i=0;
    
    	switch (message)
    	{
    	case WM_CREATE:
    		x_width=500;
    		y_width=300;
    		x_char_width=LOWORD(GetDialogBaseUnits());
    		y_char_width=HIWORD(GetDialogBaseUnits());
    		hInstance=((LPCREATESTRUCT)lParam)->hInstance;
    		upload_button=CreateWindow(TEXT("button"),TEXT("上传"),WS_CHILDWINDOW|WS_VISIBLE|BS_DEFPUSHBUTTON,20,200,
    								  150,30,hwnd,(HMENU)ID_UPLOAD,hInstance,NULL);
    		download_button=CreateWindow(TEXT("button"),TEXT("下载"),WS_CHILDWINDOW|WS_VISIBLE|BS_PUSHBUTTON,200,200,
    								  150,30,hwnd,(HMENU)ID_DOWNLOAD,hInstance,NULL);
    		login_button=CreateWindow(TEXT("button"),TEXT("登陆"),WS_CHILDWINDOW|WS_VISIBLE|BS_PUSHBUTTON,400,200,
    								  150,30,hwnd,(HMENU)ID_LOGIN,hInstance,NULL);
    		exit_button=CreateWindow(TEXT("button"),TEXT("退出"),WS_CHILDWINDOW|WS_VISIBLE|BS_PUSHBUTTON,600,200,
    								  150,30,hwnd,(HMENU)ID_EXIT,hInstance,NULL);
    		file_list=CreateWindow(TEXT ("listbox"),NULL,WS_CHILDWINDOW|WS_VISIBLE|LBS_STANDARD,0,0,200,180,
    							  hwnd,NULL,hInstance,NULL);
    		FTP_server_text=CreateWindow(TEXT("static"),TEXT("FTP服务器:"),WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,200,y_char_width,x_char_width*10,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		username_text=CreateWindow(TEXT("static"),TEXT("用户名:"),WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,200,y_char_width*3,x_char_width*7,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		password_text=CreateWindow(TEXT("static"),TEXT("密码:"),WS_CHILDWINDOW|WS_VISIBLE|SS_LEFT,200,y_char_width*5,x_char_width*5,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		FTP_server=CreateWindow(TEXT("edit"),NULL,WS_CHILD|WS_VISIBLE|ES_LEFT,200+x_char_width*10,y_char_width,x_width-200-x_char_width*10-10,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		username=CreateWindow(TEXT("edit"),NULL,WS_CHILD|WS_VISIBLE|ES_LEFT,200+x_char_width*7,y_char_width*3,x_width-200-x_char_width*7-10,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		password=CreateWindow(TEXT("edit"),NULL,WS_CHILD|WS_VISIBLE|ES_LEFT,200+x_char_width*5,y_char_width*5,x_width-200-x_char_width*5-10,y_char_width,
    								hwnd,NULL,hInstance,NULL);
    		return 0 ;
    	case WM_SIZE:
    		x_width=LOWORD(lParam);
    		y_width=HIWORD(lParam);
    		MoveWindow(upload_button,x_width/15,y_width/1.3,x_width/5,y_width/8,TRUE);
    		MoveWindow(download_button,x_width/15+x_width/5+10,y_width/1.3,x_width/5,y_width/8,TRUE);
    		MoveWindow(login_button,x_width/15+x_width/5*2+20,y_width/1.3,x_width/5,y_width/8,TRUE);
    		MoveWindow(exit_button,x_width/15+x_width/5*3+30,y_width/1.3,x_width/5,y_width/8,TRUE);
    		MoveWindow(file_list,0,0,x_width/2,y_width/1.4,TRUE);
    		MoveWindow(FTP_server_text,x_width/2+10,y_char_width,x_char_width*10,y_char_width,TRUE);
    		MoveWindow(username_text,x_width/2+10,y_char_width*4,x_char_width*7,y_char_width,TRUE);
    		MoveWindow(password_text,x_width/2+10,y_char_width*7,x_char_width*5,y_char_width,TRUE);
    		MoveWindow(FTP_server,x_width/2+10,y_char_width*2+10,x_width-x_width/2-20,y_char_width,TRUE);
    		MoveWindow(username,x_width/2+10,y_char_width*5+10,x_width-x_width/2-20,y_char_width,TRUE);
    		MoveWindow(password,x_width/2+10,y_char_width*8+10,x_width-x_width/2-20,y_char_width,TRUE);
    		break;
    	case WM_COMMAND:
    		if (lParam!=0)//子窗口控件消息
    		{
    			switch(LOWORD(wParam))
    			{
    			case ID_UPLOAD:
    			case ID_DOWNLOAD:
    				MessageBeep(3);
    				MessageBox(hwnd,"未完成",NULL,MB_OK);
    				break;
    			case ID_LOGIN:
    				FTP_server_str[SendMessage(FTP_server,EM_GETLINE,0,(LPARAM)FTP_server_str)]='\0';
    				username_str[SendMessage(username,EM_GETLINE,0,(LPARAM)username_str)]='\0';
    				password_str[SendMessage(password,EM_GETLINE,0,(LPARAM)password_str)]='\0';
    				if ((Internet_session=InternetOpen("teethFTP",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,INTERNET_FLAG_ASYNC))==NULL)
    				{
    					MessageBox(hwnd,TEXT("无法打开Internet连接"),NULL,MB_OK);
    					break;
    				}
    				if ((Ftp_session=InternetConnect(Internet_session,FTP_server_str,INTERNET_DEFAULT_FTP_PORT,username_str,password_str,INTERNET_SERVICE_FTP,0,0))==NULL)
    				{
    					MessageBox(hwnd,TEXT("无法连接到FTP服务器"),NULL,MB_OK);
    					break;
    				}
    				if (FtpGetCurrentDirectory(Ftp_session,path_str,&i)==FALSE)
    				{
    					MessageBox(hwnd,TEXT("无法打开FTP服务器根目录"),NULL,MB_OK);
    					break;
    				}
    				path_str[i]='\0';
    				FtpSetCurrentDirectory(Ftp_session,path_str);
    				SendMessage(file_list,LB_DIR,0,0);
    				break;
    			case ID_EXIT:
    				SendMessage(hwnd,WM_CLOSE,0,0);
    				break;
    			}
    		}
    		else//菜单消息
    		{
    			switch(LOWORD(wParam))
    			{
    			case IDM_FILE_EXIT:
    				SendMessage(hwnd,WM_CLOSE,0,0);
    				break;
    			case IDM_EDIT_UPLOAD:
    				SendMessage(hwnd,WM_COMMAND,ID_UPLOAD,(LPARAM)upload_button);
    				break;
    			case IDM_EDIT_DOWNLOAD:
    				SendMessage(hwnd,WM_COMMAND,ID_DOWNLOAD,(LPARAM)download_button);
    				break;
    			case IDM_EDIT_LOGIN:
    				SendMessage(hwnd,WM_COMMAND,ID_LOGIN,(LPARAM)login_button);
    				break;
    			case IDM_HELP_ABOUT:
    				DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG_ABOUT),hwnd,AboutDlgProc);
    				break;
    			}
    		}
    		return 0;
    	case WM_PAINT:
    		PAINTSTRUCT ps ;
    		hdc = BeginPaint (hwnd, &ps) ;
    		EndPaint (hwnd, &ps) ;
    		return 0 ;
         
    	case WM_DESTROY:
    		InternetCloseHandle(Internet_session);
    		InternetCloseHandle(Ftp_session);
    		PostQuitMessage (0) ;
    		return 0 ;
    	}
    	return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    

    求解……

    GetLastError()返回997

    2011年1月27日 14:48

答案