我有一段MS C ++(非托管)代码,只要USB设备插入或移入我的计算机就会运行。在Windows 7上,此代码运行正常。在Windows 10上,它会引发错误。当USB驱动器或任何其他USB设备插入我的计算机时,OnMyDeviceChange例程被调用3次;它只在Windows 7上被称为两次(正确)次。无论如何,在Windows 10上,前两次,例程运行正常。第三次在这一行失败:type.Format("%d",pHdr-> dbch_devicetype);.有谁知道为什么?
注意:我们现在知道,对于失败的代码,pHdr为空。
这是我的代码:
public static Map<String, String> getFacebookFriends(AccessToken accessToken, Profile profile) throws InterruptedException, ExecutionException {
final Map<String, String> friendsMap = new HashMap<>();
GraphRequest.Callback gCallback = new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject jGraphObj = response.getJSONObject();
try {
JSONArray friendsData = jGraphObj.getJSONArray("data");
for (int i = 0; i < friendsData.length(); i++) {
JSONObject friend = friendsData.getJSONObject(i);
String friendId = friend.getString("id");
String friendName = friend.getString("name");
friendsMap.put(friendId, friendName);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
final GraphRequest graphRequest = new GraphRequest(accessToken, "/me/friends", null, HttpMethod.GET, gCallback);
// Run facebook graphRequest.
Thread t = new Thread(new Runnable() {
@Override
public void run() {
GraphResponse gResponse = graphRequest.executeAndWait();
}
});
t.start();
t.join();
return friendsMap;
}