Mar 16, 2020 at 10:04pm Mar 16, 2020 at 10:04pm UTC
hey im new at c++ and i need help about LPSTR-LVPSTR
Error :
a value of type "LPSTR" cannot be assigned to an entity of type "char"
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
char A = 'A' ;
cout << A;
char B;
B = CharLowerA(A);
cout << b;
}
Last edited on Mar 16, 2020 at 10:04pm Mar 16, 2020 at 10:04pm UTC
Mar 16, 2020 at 11:07pm Mar 16, 2020 at 11:07pm UTC
I highly advise you to learn standard c++ before trying to use the windows only extensions to it. Which you could be doing by accident ;)
you can use std::tolower(A) here. You are trying to use microsoft's special to lower function, which expects microsoft's special string junk.
the standard one is defined in header <cctype>
Last edited on Mar 16, 2020 at 11:09pm Mar 16, 2020 at 11:09pm UTC
Mar 16, 2020 at 11:11pm Mar 16, 2020 at 11:11pm UTC
That's a wacky function.
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-charlowera
It looks like you need to cast the result. It's basically returning a char*, but you need to interpret it as a char. You could try:
char B = char (CharLowerA(A));
Or you could pass it a string, which is converted to lowercase in place (the return value is just the argument). Strange they made a function like this. I haven't tested this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <cctype>
#include <windows.h>
using namespace std;
int main()
{
char a[] = "ABCDEFG" ;
cout << a << '\n' ;
CharLowerA( a );
cout << a << '\n' ; // "abcdefg"
char ch = 'A' ;
cout << ch << '\n' ;
ch = char (CharLowerA( ch ));
cout << ch << '\n' ;
ch = 'A' ;
cout << ch << '\n' ;
ch = std::tolower( ch ); // C++ (and C) library function (header: <cctype>)
cout << ch << '\n' ;
}
Last edited on Mar 16, 2020 at 11:20pm Mar 16, 2020 at 11:20pm UTC
Mar 16, 2020 at 11:26pm Mar 16, 2020 at 11:26pm UTC
The Windows API is full of functions like this. Lots of nasty casts and tagged pointers.
Fundamentally it's a legacy C codebase that's supposed to be backward-compatibile. Not much can be done to change it, I guess.