Hi
Yesterday I tried to make a small programm, which does make a communication over COM2. I tried to open COM2 with CreateFile("\\\\.\\COM2", GENERIC_READ | GENERIC_WRITE, ...) as usual.
I used this code many times in XP systems. But it won't work! I couldn't solve the problem first. I thought maybe it is a problem caus Vista or maybe it is cause COM2 isn't a real IO port but an USB-COM bridge.
But I tried this program on my XP Netbook and it worked fine. I sent it to a fellow and he could start it on his Vista PC.
The solution is simple, looking at it afterwards:
I started my WIN32 console program using Pelles IDE (Ctrl+F5). It is not possible. It seems for me, Pelles IDE locks all COM ports on my Vista PC!
Starting the EXE from a shell (CMD.EXE) works fine, also on my VISTA PC with USB-COM2.
Hoping this helps anyone and maybe someone find the reason for this ...
This example works in Win7 as normal user:
#define WIN32_DEFAULT_LIBS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int __cdecl WinMainCRTStartup(void)
{
HANDLE hCom;
TCHAR szCom[] = TEXT("\\\\.\\COM2");
if ((hCom = CreateFile(szCom, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE) {
CloseHandle(hCom);
MessageBox(0, TEXT("Open"), szCom, MB_OK);
} else {
MessageBox(0, TEXT("Error"), szCom, MB_OK);
}
ExitProcess(0);
}