|
From: Jessica C. <jes...@gm...> - 2007-12-19 20:10:48
|
Hi, Per,
for your second method, i modified like this. i doesn't solve the
problem. the result is the same as before.
for the first method, i tried to change strSerialList[i] =
(char*)(szPortName); to strSerialList[i] = strdup((char*)(szPortName));, but
it seems doesn't work too. :-(
Regards,
Jessica
do
{
Status = RegEnumValue(hKey, dwIndex++, Name, &dwName, NULL, &Type,
szPortName, &dwSizeofPortName);
if((Status == ERROR_SUCCESS) || (Status == ERROR_MORE_DATA))
{
strSerialList[i] = (char*)(szPortName);
printf("%s\n",strSerialList[i]);
i++;
}
} while((Status == ERROR_SUCCESS) || (Status == ERROR_MORE_DATA));
RegCloseKey(hKey);
On Dec 19, 2007 2:44 PM, Per Westermark <pw...@ia...> wrote:
> The test code is buggy. It uses the same buffer to retrieve the device
> names, which means that the name will be overwritten.
>
> A quicky (with a memory leak that doesn't matter here) is to do
> strSerialList[i] = strdup((char*)szPortName);
>
> Another alternative is to print the devices one-by-one directly when they
> are found.
>
> /pwm
>
> On Wed, 19 Dec 2007, Jessica Chen wrote:
>
> > Name Type Data
> > (Default) REG_SZ (value not set)
> > \Device\Serial0 REG_SZ COM1
> > \Device\U2SPORT1 REG_SZ COM7
> >
> > if i used on my computer, i can see:
> > COM1
> > COM1
> >
> > when i used my .exe on my colleagues computer.
> > he has 2 serial port and 1 usb->serial.
> > but we can only see "COM4" for 3 times.
> >
> > so at least, the code can recognize how many COM on computer, whatever
> real
> > com port or usb-com.
> > but cannot read right com port number.
> >
> >
> > On Dec 19, 2007 1:57 PM, Rafael Menezes <so...@gm...> wrote:
> >
> > > Hi Jessica.
> > >
> > > Can you, for start, list what is on "HARDWARE\\DEVICEMAP\\SERIALCOMM"
> in
> > > your computer?
> > >
> > > Regards
> > > Rafael
> > >
> > >
> > > On 19/12/2007, Jessica Chen <jes...@gm...> wrote:
> > > >
> > > > Hi, thanks for ur email, Rafael.
> > > >
> > > > I researched myself.
> > > > I wrote a code. I will list it as follows.
> > > > The problem seems it can recognize the real serial com port (Com 1
> in my
> > > > computer, registry).
> > > > But on my computer, I have a USB->serial com port (Com 7 in my
> > > > computer, registry).
> > > > The code cannot recognize the USB->serial com port.
> > > > Is there any experienced persons can give any idea about that?
> > > >
> > > > #include <windows.h>
> > > > #include <stdio.h>
> > > > #include <tchar.h>
> > > >
> > > > int main(void)
> > > > {
> > > > char *strSerialList[256];
> > > > HKEY hKey;
> > > >
> > > > if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> > > > TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
> > > > 0,
> > > > KEY_READ,
> > > > &hKey) != ERROR_SUCCESS)
> > > > {
> > > > return -1;
> > > > }
> > > >
> > > > int i=0;
> > > > CHAR Name[25];
> > > > UCHAR szPortName[25];
> > > > LONG Status;
> > > > DWORD dwIndex = 0;
> > > > DWORD dwName;
> > > > DWORD dwSizeofPortName;
> > > > DWORD Type;
> > > > dwName = sizeof(Name);
> > > > dwSizeofPortName = sizeof(szPortName);
> > > >
> > > > do
> > > > {
> > > > Status = RegEnumValue(hKey, dwIndex++, Name, &dwName, NULL,
> > > > &Type,
> > > > szPortName, &dwSizeofPortName);
> > > > if((Status == ERROR_SUCCESS) || (Status == ERROR_MORE_DATA))
> > > > {
> > > > strSerialList[i] = (char*)(szPortName);
> > > > i++;
> > > > }
> > > > } while((Status == ERROR_SUCCESS) || (Status ==
> ERROR_MORE_DATA));
> > > > RegCloseKey(hKey);
> > > >
> > > > for(int j=0;j<i;j++)
> > > > {
> > > > printf("%s\n",strSerialList[j]);
> > > > }
> > > >
> > > > return 0;
> > > > }
> > > >
> > > >
> > > > On Dec 19, 2007 12:34 PM, Rafael Menezes <so...@gm...> wrote:
> > > >
> > > > > You can send mails. Can you search on google?
> > > > >
> > > > > http://www.google.com.br/search?hl=pt-BR&q=c%2B%2B+com+port&meta =
> > > > >
> > > > >
> http://www.google.com.br/search?num=30&hl=pt-BR&q=c%2B%2B+serial+port&meta
> > > > > =
> > > > >
> > > > >
> > > > > On 19/12/2007, Jessica Chen <jes...@gm... > wrote:
> > > > >
> > > > > > is there anyone have the experience for writing code of getting
> the
> > > > > > serial port info from windows?
> > > > > > can u give me an sample code?
> > > > > >
> > > > > >
> > > > > >
> -------------------------------------------------------------------------
> > > > > >
> > > > > > SF.Net email is sponsored by:
> > > > > > Check out the new SourceForge.net Marketplace.
> > > > > > It's the best place to buy or sell services
> > > > > > for just about anything Open Source.
> > > > > >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > > > > >
> > > > > > _______________________________________________
> > > > > > Dev-cpp-users mailing list
> > > > > > Dev...@li...
> > > > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Regards
> > > > > Rafael Menezes
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Regards
> > > Rafael Menezes
> >
>
>
|