NO

Author Topic: Problem: COM2 access from Pelles-IDE  (Read 3447 times)

Diddl

  • Guest
Problem: COM2 access from Pelles-IDE
« on: April 22, 2011, 08:50:02 AM »
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 ...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Problem: COM2 access from Pelles-IDE
« Reply #1 on: April 22, 2011, 09:23:12 AM »
This example works in Win7 as normal user:
Code: [Select]
#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);
}
May the source be with you