registering for device notifications





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















so iv'e been searching for a way to get notifications when a USB device is connected to the pc. i found this code here: https://docs.microsoft.com/en-us/windows/desktop/devio/registering-for-device-notification

now i have a few problems with this code(visual c++).
I tried putting it in my visual c++ 2017 but it won't compile. there are 6 errors in 2 types:
lines 330, 344, 495: error E0167.
'argument of type "PTSTR" is incompatible with parameter of type "LPCWSTR" '
https://www.bing.com/search?q=C%2B%2B%20argument+of+type+%22PTSTR%22+is+incompatible+with+parameter+of+type+%22LPCWSTR%22
lines 330, 350, 495: error C2664.
"'LPWSTR *CommandLineToArgvW(LPCWSTR,int *)': cannot convert argument 1/3 from 'PTSTR' to 'LPCWSTR'"
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2664)%26rd%3Dtrue&view=vs-2017



before line 330 there is a comment that says to add Windows to the project. i did that but I'm still getting these errors, and searching them in the web didn't help since i do understand the error but have no idea how to fix it. I would highly appreciate it if you could help me compile this code. thanks in advance!










share|improve this question

























  • You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

    – Jim Rhodes
    Nov 23 '18 at 19:08


















0















so iv'e been searching for a way to get notifications when a USB device is connected to the pc. i found this code here: https://docs.microsoft.com/en-us/windows/desktop/devio/registering-for-device-notification

now i have a few problems with this code(visual c++).
I tried putting it in my visual c++ 2017 but it won't compile. there are 6 errors in 2 types:
lines 330, 344, 495: error E0167.
'argument of type "PTSTR" is incompatible with parameter of type "LPCWSTR" '
https://www.bing.com/search?q=C%2B%2B%20argument+of+type+%22PTSTR%22+is+incompatible+with+parameter+of+type+%22LPCWSTR%22
lines 330, 350, 495: error C2664.
"'LPWSTR *CommandLineToArgvW(LPCWSTR,int *)': cannot convert argument 1/3 from 'PTSTR' to 'LPCWSTR'"
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2664)%26rd%3Dtrue&view=vs-2017



before line 330 there is a comment that says to add Windows to the project. i did that but I'm still getting these errors, and searching them in the web didn't help since i do understand the error but have no idea how to fix it. I would highly appreciate it if you could help me compile this code. thanks in advance!










share|improve this question

























  • You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

    – Jim Rhodes
    Nov 23 '18 at 19:08














0












0








0








so iv'e been searching for a way to get notifications when a USB device is connected to the pc. i found this code here: https://docs.microsoft.com/en-us/windows/desktop/devio/registering-for-device-notification

now i have a few problems with this code(visual c++).
I tried putting it in my visual c++ 2017 but it won't compile. there are 6 errors in 2 types:
lines 330, 344, 495: error E0167.
'argument of type "PTSTR" is incompatible with parameter of type "LPCWSTR" '
https://www.bing.com/search?q=C%2B%2B%20argument+of+type+%22PTSTR%22+is+incompatible+with+parameter+of+type+%22LPCWSTR%22
lines 330, 350, 495: error C2664.
"'LPWSTR *CommandLineToArgvW(LPCWSTR,int *)': cannot convert argument 1/3 from 'PTSTR' to 'LPCWSTR'"
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2664)%26rd%3Dtrue&view=vs-2017



before line 330 there is a comment that says to add Windows to the project. i did that but I'm still getting these errors, and searching them in the web didn't help since i do understand the error but have no idea how to fix it. I would highly appreciate it if you could help me compile this code. thanks in advance!










share|improve this question
















so iv'e been searching for a way to get notifications when a USB device is connected to the pc. i found this code here: https://docs.microsoft.com/en-us/windows/desktop/devio/registering-for-device-notification

now i have a few problems with this code(visual c++).
I tried putting it in my visual c++ 2017 but it won't compile. there are 6 errors in 2 types:
lines 330, 344, 495: error E0167.
'argument of type "PTSTR" is incompatible with parameter of type "LPCWSTR" '
https://www.bing.com/search?q=C%2B%2B%20argument+of+type+%22PTSTR%22+is+incompatible+with+parameter+of+type+%22LPCWSTR%22
lines 330, 350, 495: error C2664.
"'LPWSTR *CommandLineToArgvW(LPCWSTR,int *)': cannot convert argument 1/3 from 'PTSTR' to 'LPCWSTR'"
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2664)%26rd%3Dtrue&view=vs-2017



before line 330 there is a comment that says to add Windows to the project. i did that but I'm still getting these errors, and searching them in the web didn't help since i do understand the error but have no idea how to fix it. I would highly appreciate it if you could help me compile this code. thanks in advance!







visual-c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 21:12







user10696838

















asked Nov 23 '18 at 18:54









user10696838user10696838

12




12













  • You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

    – Jim Rhodes
    Nov 23 '18 at 19:08



















  • You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

    – Jim Rhodes
    Nov 23 '18 at 19:08

















You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

– Jim Rhodes
Nov 23 '18 at 19:08





You need to post the lines of code giving the errors and the exact text of the errors not just the error numbers.

– Jim Rhodes
Nov 23 '18 at 19:08












1 Answer
1






active

oldest

votes


















1














Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.



Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.



EDIT: To answer your comment.



The problem you are having is primarily due to line 13:



PWSTR g_pszAppName;


This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:



Change line 13 to:



PTSTR g_pszAppName = _T("MyApp");   // Put your app name here


Remove these 2 lines (330 and 331):



PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];


You may also want to change Project->Properties->General->Character Set back to what it was originally.






share|improve this answer


























  • Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

    – user10696838
    Nov 23 '18 at 20:59











  • THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

    – user10696838
    Nov 26 '18 at 18:08












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451720%2fregistering-for-device-notifications%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.



Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.



EDIT: To answer your comment.



The problem you are having is primarily due to line 13:



PWSTR g_pszAppName;


This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:



Change line 13 to:



PTSTR g_pszAppName = _T("MyApp");   // Put your app name here


Remove these 2 lines (330 and 331):



PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];


You may also want to change Project->Properties->General->Character Set back to what it was originally.






share|improve this answer


























  • Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

    – user10696838
    Nov 23 '18 at 20:59











  • THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

    – user10696838
    Nov 26 '18 at 18:08
















1














Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.



Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.



EDIT: To answer your comment.



The problem you are having is primarily due to line 13:



PWSTR g_pszAppName;


This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:



Change line 13 to:



PTSTR g_pszAppName = _T("MyApp");   // Put your app name here


Remove these 2 lines (330 and 331):



PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];


You may also want to change Project->Properties->General->Character Set back to what it was originally.






share|improve this answer


























  • Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

    – user10696838
    Nov 23 '18 at 20:59











  • THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

    – user10696838
    Nov 26 '18 at 18:08














1












1








1







Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.



Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.



EDIT: To answer your comment.



The problem you are having is primarily due to line 13:



PWSTR g_pszAppName;


This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:



Change line 13 to:



PTSTR g_pszAppName = _T("MyApp");   // Put your app name here


Remove these 2 lines (330 and 331):



PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];


You may also want to change Project->Properties->General->Character Set back to what it was originally.






share|improve this answer















Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.



Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.



EDIT: To answer your comment.



The problem you are having is primarily due to line 13:



PWSTR g_pszAppName;


This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:



Change line 13 to:



PTSTR g_pszAppName = _T("MyApp");   // Put your app name here


Remove these 2 lines (330 and 331):



PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];


You may also want to change Project->Properties->General->Character Set back to what it was originally.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 15:06

























answered Nov 23 '18 at 19:35









Jim RhodesJim Rhodes

3,59611832




3,59611832













  • Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

    – user10696838
    Nov 23 '18 at 20:59











  • THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

    – user10696838
    Nov 26 '18 at 18:08



















  • Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

    – user10696838
    Nov 23 '18 at 20:59











  • THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

    – user10696838
    Nov 26 '18 at 18:08

















Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

– user10696838
Nov 23 '18 at 20:59





Jim Rhodes, first of all thanks for the help. I tried doing as you said but unfortunately it did not fix any of the errores. about the code being poorly written, is there a better source where i can learn from how to do this? I'm trying to make a code that can catch all kinds of events from windows, but the basics for me are managing USB devices. After quite a long search this is the best code source that i could find on the internet. thx again, shon ;)

– user10696838
Nov 23 '18 at 20:59













THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

– user10696838
Nov 26 '18 at 18:08





THANKS A LOT! PROBLEM SOLVED! one last question, where did u learn winapi? would be awesome if u could send a link or something. thx for everything, -shon ;)

– user10696838
Nov 26 '18 at 18:08




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451720%2fregistering-for-device-notifications%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini