查找符号链接指向的位置(Windows)

时间:2015-09-11 14:04:17

标签: c++ c winapi symlink

我使用FindFirstFile()和共同功能来浏览C:\example\dir的内容。我知道通过检查是否d.dwAttributes & FILE_ATTRIBUTE_REPARSE_POINT != 0,文件读取可以是符号链接,交汇点等。但是,我还没有找到一种方法来关注链接并查看它指向的位置。这甚至可能吗?

1 个答案:

答案 0 :(得分:4)

要查找符号链接的目标,您必须打开符号链接。对象管理器取消引用链接并返回目标位置的句柄。在该句柄上调用GetFinalPathNameByHandle将返回目标的路径名。

以下实现返回目标位置,给定符号链接:

<body>
  <div id="floating-panel" >
      <strong>Start:</strong>
      <input id="start" value="<%postcode1%>"/>
      <br>
      <strong>End:</strong>
      <input id="end" value="<%postcode2%>"/>
    </div>
    <div id="right-panel"></div>
    <div id="map"></div>
<script>

    function initMap() {
        var directionsDisplay = new google.maps.DirectionsRenderer;
        var directionsService = new google.maps.DirectionsService;
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 7,
            center: { lat: 41.85, lng: -87.65 } //don't want to always use these co-ordinates
        });
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById('right-panel'));

        var control = document.getElementById('floating-panel');
        control.style.display = 'block';
        map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);

        var onChangeHandler = function () {
            calculateAndDisplayRoute(directionsService, directionsDisplay);
        };
        document.getElementById('start').addEventListener('change', onChangeHandler);
        document.getElementById('end').addEventListener('change', onChangeHandler);
    }

    function calculateAndDisplayRoute(directionsService, directionsDisplay) {
        var start = document.getElementById('start').value;
        var end = document.getElementById('end').value;
        directionsService.route({
            origin: start,
            destination: end,
            travelMode: google.maps.TravelMode.DRIVING
        }, function (response, status) {
            if (status === google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            } else {
                window.alert('Directions request failed due to ' + status);
            }
        });
    }

</script>
<script src="https://maps.googleapis.com/maps/api/js?key=<%=mapkey %>&signed_in=true&callback=initMap"
    async defer></script>

<小时/> 注意:有关基于std::unique_ptr的RAII包装器的详细信息,请参阅std::unique_ptr, deleters and the Win32 API