|
It is safe as long the main window is not recreated.
--
Ich bin der böse Mann von Schweden.
|
|
|
|
|
To use all afx functions do you need MFC linked applications?
|
|
|
|
|
yes
a two cent stamp short of going postal.
|
|
|
|
|
ok, im using this com port enumarator:
http://www.codeproject.com/system/listports.asp
and im haveing trouble using it to list the ports in a list box using MFC. Can someone send me a simple example doing that with this, using VC++ 6 preferably?
thank you, This stupid thing is frustrating me beyond belief lol
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
In stdafx.h put:
#include <afxext.h>
#include <afxtempl.h>
In EnumerSer.h put:
#ifndef __AFXTEMPL_H__
#pragma message("EnumerateSerialPorts function requires afxtempl.h in your PCH")
#endif
void EnumerateSerialPorts(CUIntArray& ports);
...
Demo.cpp:
#include "stdafx.h"
#include <stdio.h>
#include "EnumerSer.h"
void main()
{
CUIntArray ports;
EnumerateSerialPorts(ports);
_tprintf(_T("The following serial ports are installed on this machine\n"));
for (int i=0; i
|
|
|
|
|
Sorry I forget:
///////////////////////////// Implementation //////////////////////////////////
void EnumerateSerialPorts(CUIntArray& ports)
{
//Make sure we clear out any elements which may already be in the array
ports.RemoveAll();
//Determine what OS we are running on
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
BOOL bGetVer = GetVersionEx(&osvi);
//On NT use the QueryDosDevice API
if (bGetVer && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT))
{
//Use QueryDosDevice to look for all devices of the form COMx. This is a better
//solution as it means that no ports have to be opened at all.
TCHAR szDevices[65535];
DWORD dwChars = QueryDosDevice(NULL, szDevices, 65535);
if (dwChars)
{
int i=0;
for (;;)
{
//Get the current device name
TCHAR* pszCurrentDevice = &szDevices[i];
//If it looks like "COMX" then
//add it to the array which will be returned
int nLen = _tcslen(pszCurrentDevice);
if (nLen > 3 && _tcsnicmp(pszCurrentDevice, _T("COM"), 3) == 0)
{
//Work out the port number
int nPort = _ttoi(&pszCurrentDevice[3]);
ports.Add(nPort);
}
// Go to next NULL character
while(szDevices[i] != _T('\0'))
i++;
// Bump pointer to the next string
i++;
// The list is double-NULL terminated, so if the character is
// now NULL, we're at the end
if (szDevices[i] == _T('\0'))
break;
}
}
else
TRACE(_T("Failed in call to QueryDosDevice, GetLastError:%d\n"), GetLastError());
}
else
{
//On 95/98 open up each port to determine their existence
//Up to 255 COM ports are supported so we iterate through all of them seeing
//if we can open them or if we fail to open them, get an access denied or general error error.
//Both of these cases indicate that there is a COM port at that number.
for (UINT i=1; i<256; i++)
{
//Form the Raw device name
CString sPort;
sPort.Format(_T("\\\\.\\COM%d"), i);
//Try to open the port
BOOL bSuccess = FALSE;
HANDLE hPort = ::CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (hPort == INVALID_HANDLE_VALUE)
{
DWORD dwError = GetLastError();
//Check to see if the error was because some other app had the port open or a general failure
if (dwError == ERROR_ACCESS_DENIED || dwError == ERROR_GEN_FAILURE)
bSuccess = TRUE;
}
else
{
//The port was opened successfully
bSuccess = TRUE;
//Don't forget to close the port, since we are going to do nothing with it anyway
CloseHandle(hPort);
}
//Add the port number to the array which will be returned
if (bSuccess)
ports.Add(i);
}
}
}
|
|
|
|
|
umm u have a few includes there with nothing after them, what do i include?
ty
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
Sorry I did not check "Do not treat <'s as HTML tags."
In Stdafx.h should be:
#include <afxext.h>
#include <afxtempl.h>
In Demo.cpp missed
#include <stdio.h>
|
|
|
|
|
im about to shove a stick of dynomite into my comps serial port, lol
i get this error:
cannot convert parameter 1 from 'unsigned int' to 'const char *'
for this line of code:
m_port.AddString(ports.ElementAt(i));
how do i fix that?
thank you
|
|
|
|
|
You have to convert this integer into string such as:
char str[7];
sprintf(str, "COM%d", ports.ElementAt(i));
m_port.AddString(str);
|
|
|
|
|
|
Being only a beginner, I have a very basic question to ask:
to input names, what is the best to use: strings or char format?
|
|
|
|
|
Char can store only one charecter.
String can store any number of charecters.
So as name contain multi chars, use Strings.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
When I try to spawn a thread i get an error. Here is my code:
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
char szMsg[80];
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
cliThread, // thread function
&_param, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
}
else
{
}
The error was that the memory couldnt be read. Is there a quick solution to my problems? Thanks
|
|
|
|
|
There must be something in the thread that you are trying to do that is causing the exception.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi everyone!
Does anyone of you know where i can get a good linux compiler and linker ??? It doesn't have to be freeware !
MFG
TheProgrammer
MSN: reddragon2kx@hotmail.com
ICQ: 308616675
www.theprogrammer.de.vu[^]
|
|
|
|
|
|
|
I luuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuv gcc!
|
|
|
|
|
Borland C++ BuilderX
www.borland.com
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
All linux distributions comes with a GCC compiler suite. (unless they've been stripped down for use in embedded systems or something like that)
Just type g++ in a shell command prompt and see what response you get.
--
Ich bin der böse Mann von Schweden.
|
|
|
|
|
I believe Intel has the best C++ compiler for Linux.
|
|
|
|
|
Nemanja Trifunovic wrote:
I believe Intel has the best C++ compiler for Linux.
Only if you are running its product on INTEL processors.
If you are only remotely thinking of value (e.g. price per speed) you would never do that, ans the Intel compiler is wasted money.
Especially, as it is (outside of special laboratories) unable to compile your Linux system.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Hi all!
I've done a Visual C++ application and it works perfectly, but when I have done another similar one using the same include statements and in the same order, I get these errors:
<br />
C:\Archivos de programa\Microsoft Visual Studio\MyProjects\imevo_versiones\ejemplo ivocom 1\ventana\speech.h(468) : error C2146: syntax error : missing ';' before identifier 'FAR'<br />
C:\Archivos de programa\Microsoft Visual Studio\MyProjects\imevo_versiones\ejemplo ivocom 1\ventana\speech.h(468) : fatal error C1004: unexpected end of file found<br />
I never got these errors before and the changes that I've done doesn't matter this header "speech.h" (I think so at least).
Any ideas?
Thank you in advance!
|
|
|
|
|
If memory serves me you are missing a semicolon at the end of the class prototyped in speech.h
|
|
|
|