다음을 통해 공유


네트워크 연결 추가

NETRESOURCE 구조에서 설명하는 네트워크 리소스에 연결하기 위해 애플리케이션은 WNetAddConnection2, WNetAddConnection3 또는 WNetUseConnection 함수를 호출할 수 있습니다. 다음 예제에서는 WNetAddConnection2 함수를 사용하는 방법을 보여 줍니다.

코드 샘플은 WNetAddConnection2 함수를 호출하여 시스템에서 사용자 프로필을 정보로 업데이트해야 하므로 "기억됨" 또는 영구 연결을 만듭니다. 샘플은 애플리케이션 정의 오류 처리기를 호출하여 오류를 처리하고 인쇄를 위한 TextOut 함수를 호출합니다.

DWORD dwResult; 
NETRESOURCE nr; 
//
// Call the WNetAddConnection2 function to make the connection,
//   specifying a persistent connection.
//
dwResult = WNetAddConnection2(&nr, // NETRESOURCE from enumeration 
    (LPSTR) NULL,                  // no password 
    (LPSTR) NULL,                  // logged-in user 
    CONNECT_UPDATE_PROFILE);       // update profile with connect information 
 
// Process errors.
//  The local device is already connected to a network resource.
//
if (dwResult == ERROR_ALREADY_ASSIGNED) 
{ 
    printf("Already connected to specified resource.\n"); 
    return dwResult; 
} 
 
//  An entry for the local device already exists in the user profile.
//
else if (dwResult == ERROR_DEVICE_ALREADY_REMEMBERED) 
{ 
    printf("Attempted reassignment of remembered device.\n"); 
    return dwResult; 
} 
else if(dwResult != NO_ERROR) 
{ 
    //
    // Call an application-defined error handler.
    //
    printf("WNetAddConnection2 failed.\n"); 
    return dwResult; 
} 
 
//
// Otherwise, report a successful connection.
//
printf("Connected to the specified resource.\n"); 

WNetAddConnection 함수는 이전 버전의 작업 그룹용 Windows와의 호환성을 위해 지원됩니다. 새 애플리케이션은 WNetAddConnection2 함수 또는 WNetAddConnection3 함수를 호출해야 합니다.

애플리케이션 정의 오류 처리기를 사용하는 방법에 대한 자세한 내용은 네트워크 오류 검색을 참조하세요.