MFC help : code error 0000007B
-
The error message is (you can check it in
WinError.h
)// The filename, directory name, or volume label syntax is incorrect.
What library are you using?
Veni, vidi, vici.
basically i have the console program running fine (means having source file and header files). than i wanted to build GUI for this using MFC in vs2008. now i don't understand how to open serial port in MFC. code below shows how to open serial port in console programming using cmd prompt.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}/\* initialize the serial port \*/ set\_baud\_rate(BaudRate); COMstream = open\_host\_port(COMportName); if ( COMstream == PORT\_NOT\_OPENED ) { printf("\\nSerial Port setup error.\\n"); goto abnormal\_exit; } printf("\\nSerial port %s initialized\\n", COMportName);
-
As CPallini pointed out
CPallini wrote:
The error message is (you can check it in
WinError.h
)// The filename, directory name, or volume label syntax is incorrect.
Are you sure COM3 exists on your machine? Did you try the format \\.\COM3 instead? What happens in set_baud_rate() and in open_host_port()? You have to open the COM-Port before changing the baudrate Cou can find some more hints on serial communication here: Communications Resources[^] [Edit]corrected spelling of memeber name :-O [/Edit]
yes COM3 is available and i have tried \\.COM3 and \\\\.\\COM3 both. basically i'm developing GUI via MFC in vs2008 for my console program. part of the code for opening serial port in console program is given below. i can't understand how to do it in MFC.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}/\* initialize the serial port \*/ set\_baud\_rate(BaudRate); COMstream = open\_host\_port(COMportName); if ( COMstream == PORT\_NOT\_OPENED ) { printf("\\nSerial Port setup error.\\n"); goto abnormal\_exit; } printf("\\nSerial port %s initialized\\n", COMportName);
-
basically i have the console program running fine (means having source file and header files). than i wanted to build GUI for this using MFC in vs2008. now i don't understand how to open serial port in MFC. code below shows how to open serial port in console programming using cmd prompt.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}/\* initialize the serial port \*/ set\_baud\_rate(BaudRate); COMstream = open\_host\_port(COMportName); if ( COMstream == PORT\_NOT\_OPENED ) { printf("\\nSerial Port setup error.\\n"); goto abnormal\_exit; } printf("\\nSerial port %s initialized\\n", COMportName);
-
yes COM3 is available and i have tried \\.COM3 and \\\\.\\COM3 both. basically i'm developing GUI via MFC in vs2008 for my console program. part of the code for opening serial port in console program is given below. i can't understand how to do it in MFC.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}/\* initialize the serial port \*/ set\_baud\_rate(BaudRate); COMstream = open\_host\_port(COMportName); if ( COMstream == PORT\_NOT\_OPENED ) { printf("\\nSerial Port setup error.\\n"); goto abnormal\_exit; } printf("\\nSerial port %s initialized\\n", COMportName);
Does the console programm run? And what's the code inside open_host_port()? Did you step through the code of open_host_port() in the debugger? Examine every return code of Win32 API-calls and check GetLastError(). What happens, if you just do a call to the CreateFile-function to open the COM-port, just like in this article Creating a Serial communication on Win32[^] I dont't think that this is an MFC problem,
-
basically i have the console program running fine (means having source file and header files). than i wanted to build GUI for this using MFC in vs2008. now i don't understand how to open serial port in MFC. code below shows how to open serial port in console programming using cmd prompt.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}/\* initialize the serial port \*/ set\_baud\_rate(BaudRate); COMstream = open\_host\_port(COMportName); if ( COMstream == PORT\_NOT\_OPENED ) { printf("\\nSerial Port setup error.\\n"); goto abnormal\_exit; } printf("\\nSerial port %s initialized\\n", COMportName);
What a mix up of different naming conventions!
-
Does the console programm run? And what's the code inside open_host_port()? Did you step through the code of open_host_port() in the debugger? Examine every return code of Win32 API-calls and check GetLastError(). What happens, if you just do a call to the CreateFile-function to open the COM-port, just like in this article Creating a Serial communication on Win32[^] I dont't think that this is an MFC problem,
Andy411 wrote:
I dont't think that this is an MFC problem,
I agree.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
hi,
i'm developing GUI using MFC in vs2008. i have developed code and it builds fine but when i debug my code, it gives system error 0000007B. part of the code that gives this error is given below + variable initialization.int COMportNum= 3;
portstream_fd COMstream;
portstream_fd pstream;
char COMportPrefix[10] = "COM";
char COMportName[256];sprintf(COMportName, "%s%d", COMportPrefix, COMportNum); // initialize serial port COM3
strng = CString(COMportName);
strng.Format(_T("%0.9s"), strng);
SetDlgItemText(IDC_STAT, strng);set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName); //opens serial port COM3if ( COMstream == PORT_NOT_OPENED ) //conditional check if COM3 is opened
{
stw.Format(_T("%08X"), GetLastError()); //generates error if any
SetDlgItemText(IDC_PTUPORT, stw);
}
else
SetDlgItemText(IDC_PTUPORT, (LPCTSTR) L"Ok");can anyone please help me with this error.
Regards
Jawadjawadali477 wrote:
char COMportPrefix[10] = "COM"; char COMportName[256]; sprintf(COMportName, "%s%d", COMportPrefix, COMportNum); // initialize serial port COM3 strng = CString(COMportName); strng.Format(_T("%0.9s"), strng); SetDlgItemText(IDC_STAT, strng);
I'm thinking you could eliminate some overhead here. Try:
strng.Format(_T("COM%d"), COMportNum);
Note that this likely has nothing to do with why
open_host_port()
is not opening the port."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
hi,
i'm developing GUI using MFC in vs2008. i have developed code and it builds fine but when i debug my code, it gives system error 0000007B. part of the code that gives this error is given below + variable initialization.int COMportNum= 3;
portstream_fd COMstream;
portstream_fd pstream;
char COMportPrefix[10] = "COM";
char COMportName[256];sprintf(COMportName, "%s%d", COMportPrefix, COMportNum); // initialize serial port COM3
strng = CString(COMportName);
strng.Format(_T("%0.9s"), strng);
SetDlgItemText(IDC_STAT, strng);set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName); //opens serial port COM3if ( COMstream == PORT_NOT_OPENED ) //conditional check if COM3 is opened
{
stw.Format(_T("%08X"), GetLastError()); //generates error if any
SetDlgItemText(IDC_PTUPORT, stw);
}
else
SetDlgItemText(IDC_PTUPORT, (LPCTSTR) L"Ok");can anyone please help me with this error.
Regards
JawadI do not recognize the open_host_port function, but it does not really matter. On some systems you need to add a ':' after COMx. Try sprintf(COMportName, "%s%d:", COMportPrefix, COMportNum); to get COM3: Cheers, Henryk
-
jawadali477 wrote:
COMstream = open_host_port(COMportName);
I would use the debugger to watch
COMportName
content in both console and MFC applications.Veni, vidi, vici.
console program is running fine. problem is in MFC program. can you tell how to implement the console program, as mentioned, in MFC??
-
I do not recognize the open_host_port function, but it does not really matter. On some systems you need to add a ':' after COMx. Try sprintf(COMportName, "%s%d:", COMportPrefix, COMportNum); to get COM3: Cheers, Henryk
i did what you suggested and now the error comes out to be 00000002 (i.e The system cannot find the file specified). and the outcome of
SetDlgItemText(IDC_STAT, strng);
is "COM3:".
-
i did what you suggested and now the error comes out to be 00000002 (i.e The system cannot find the file specified). and the outcome of
SetDlgItemText(IDC_STAT, strng);
is "COM3:".
OK, so this means you fixed one problem (I think), but now came up against another. I believe 7B meant that command format was wrong that is why I was suggesting the ':' the 2 means that system cannot find COM3. Are you sure that it exists. On a Windows PC you'd look in device manager. If it really exists then 7B probably means something else. That is about all I can help. Henryk