LPSTR - LVPSTR ...

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
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
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
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.

thanks so much
Topic archived. No new replies allowed.