How to open COM port whit CreateFileA inside of a class method?

__joy__ 0 Reputation points
2025-04-18T23:15:34.5466667+00:00

I am using winapi to create a serial connexion with an arduino, I used:

HANDLE hSerial = CreateFileA("COM3", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

To open serial port and it returns a valid handle but when i put this snippet on a class method like this:

SerialConnexion::open() {
	HANDLE hSerial = CreateFileA("COM3", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 	FILE_ATTRIBUTE_NORMAL, 0);
}

It returns a **ERROR_ACCESS_DENIED **why is this happening? I think that is due

LPSECURITY_ATTRIBUTES attribute but I am not sure, I would appreciate it if someone could guide me.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,912 questions
{count} votes