|
You're testing the handle value in the wrong place. You should test it immediately after the CreateFile call (failure), otherwise you'll not get meaningful info by GetLastError (other function calls reset last error). Moreover it doesn't make any sense calling GetCommState with an invalid handle as argument.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks for your advice. I wrote the function as you said and GetLastError function returned 5 (ACCESS DENIED), how I solve this error?
:
/************************************************************************************************/
void CDlgComPortConnectTest::OpenPort()
{
//if (serial_handle!=INVALID_HANDLE_VALUE)
// CloseHandle(serial_handle);
//serial_handle = INVALID_HANDLE_VALUE;
serial_handle = CreateFile( m_sCOM /*"COM1"*/,
GENERIC_READ | GENERIC_WRITE,
0, /* comm devices must be opened w/exclusive-access */
NULL, /* no security attrs */
OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
NULL, /* not overlapped I/O */
NULL /* hTemplate must be NULL for comm devices */ );
if (serial_handle == INVALID_HANDLE_VALUE)
{
B_commopen = FALSE;
char sMsg[512];
DWORD dwError = GetLastError();
sprintf(sMsg, "Error=%d ",
dwError);
AfxMessageBox(sMsg);
ASSERT(FALSE);
// error opening port; abort
}
if (GetCommState(serial_handle,&dcb) == 0)
{
char sMsg[512];
DWORD dwError = GetLastError();
sprintf(sMsg, "Error=%d ",dwError);
AfxMessageBox(sMsg);
AfxMessageBox(GetLastError());
AfxMessageBox("Get configuration port has problem.");
return;
}
FillMemory(&dcb, sizeof(dcb), 0);
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate=(unsigned long)atol(m_sBaudRate);//(unsigned long)(9600);
if ( m_sParity.Compare("None") == 0 )
dcb.Parity = NOPARITY;
else
if ( m_sParity.Compare("Even") == 0 )
dcb.Parity = EVENPARITY;
else
if ( m_sParity.Compare("Odd") == 0 )
dcb.Parity = ODDPARITY;
else
dcb.Parity = NOPARITY;
if ( m_sStopBits.Compare("1") == 0 )
dcb.StopBits = ONESTOPBIT;
else
if ( m_sStopBits.Compare("1.5") == 0 )
dcb.StopBits = ONE5STOPBITS;
else
if ( m_sStopBits.Compare("2") == 0 )
dcb.StopBits = TWOSTOPBITS;
else
dcb.StopBits = ONESTOPBIT;
if ( m_sDataBits.Compare("7") == 0 )
dcb.ByteSize = 7;
else
if( m_sDataBits.Compare("8") == 0 )
dcb.ByteSize = 8;
else
dcb.ByteSize = 8;
dcb.fAbortOnError = TRUE;
B_PortReady = SetupComm(serial_handle, 128, 128); // set buffer sizes
B_commopen = TRUE;
}
Read(m_sResults);
}
|
|
|
|
|
That means the serial port is currently owned by another application.
Have you closed the hyperterminal?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
No, I didn't open hyperterminal. Is there any reason for this error?
|
|
|
|
|
As I suggested before, probably there is another application that owns the serial port; the latter cannot be shared and hence the error. You may try to open indeed the hyperterminal on the same port and see if it succeeds.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
You're right. I tried to open and connect COM1 port with Hyper Terminal program but I got "Another program is using.." warning. I restarted computer and I will try again. Thank you for your all advices and helps.
|
|
|
|
|
You're welcome.
BTW: remember to call CloseHandle when you've done with the serial port.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
See does this[^] helpful for you?
|
|
|
|
|
Hi,
Quick question; im a developer currently working on a win32 project in C/C++/ASM that utilizes a lot of debugging theory in order to work. However, at this point, i cannot seem to find a way to list all process memory maps running in a win32 process. I can extract a full list of modules, and mappings, but i cannot find anything that isn't loaded as an executable module (e.g. Stacks, Heaps, other Maps).
What i really need is a way to extract a list of all process memory maps in a similar fashion to how ollydbg displays them, so i can use the list of maps for internal program calculations.
Any help would be appreciated as i've spent hours scouring the web for an answer.
~Jason
|
|
|
|
|
|
Perhaps something like this is what you're after:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
char *pMin = (char*)si.lpMinimumApplicationAddress;
char *pMax = (char*)si.lpMaximumApplicationAddress;
for (char* pAddress = pMin; pAddress<pMax; )
{
MEMORY_BASIC_INFORMATION mbi;
DWORD res = VirtualQuery(pAddress, &mbi, sizeof(mbi));
if (res != sizeof(mbi))
{
cerr << "VirtualQuery failed!" << endl;
return -1;
}
if (mbi.State == MEM_COMMIT)
{
DWORD base = (DWORD)mbi.BaseAddress;
cout << hex << showbase << base << " - " << base + mbi.RegionSize-1 << endl;
}
pAddress += mbi.RegionSize;
}
return 0;
}
Steve
|
|
|
|
|
Yes, that is almost exactly what i need to do, except not from within the process itself. I need to break into the application remotely using the OpenProcess/Thread functions and utilizing the debug libraries, and enumerate address space from there. Looks like i can just use VirtualQueryEx and enumerate that way. I'm gonna go give it a try, thanks for the insight.
~jason
|
|
|
|
|
how to compress/decompress image using lzw algorithm???
is there anyone know?
please send me a sample code , related links , some demo program ,
and many other that can help my project
thanks a lot...
|
|
|
|
|
dev_buzz wrote: how to compress/decompress image using lzw algorithm???
For such a broad question as that, all I can suggest is to use an LZW library.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
|
I have a situation--
CString str = "37.62";
double d, d1;
d = atof(str);
d1 = strtod(str, NULL);
The results of both d and d1 are 37.619999999999997 (unexpected)
what do i do to get d=37.62 and d1=37.62
|
|
|
|
|
Member 3611002 wrote: what do i do...
Read here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Looks like it will take weeks to get through that doc [ ] Can you please explain in simple words what is the cause and resolution of this behavior if I may request so ?
|
|
|
|
|
cagespear wrote: Looks like it will take weeks to get through that doc
So just search for another one. They're plentiful. Here for example.
cagespear wrote: Can you please explain in simple words what is the cause...
Computers are binary (i.e., base-2) machines, thus they cannot exactly represent floating-point numbers as you might think.
cagespear wrote: ...and resolution of this behavior if I may request so ?
Epsilon.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
There are two problems with real numbers on computers.
1. Not every real number have an exact binary representation. For example 0.1 when represented in binary is 0.0001100110011001100110011001100110011001100110011001101 now when you convert it back to real number you will get 0.10000000000000001. Note you can try this calculation by hand and this inaccuracy has got nothing to do with how we represent real numbers in computer.
2. There are uncountably infinite real numbers but computers can only represent and manipulate finite numbers (Well at least in hardware). This means that not every real number can be expressed in computer.
Hope this makes it clear.
-Saurabh
|
|
|
|
|
Simply, this is related with binary representation of floating point numbers.
Member 3611002 wrote: The results of both d and d1 are 37.619999999999997 (unexpected)
what do i do to get d=37.62 and d1=37.62
This is normal and there is nothing to do for a double type. if you format that number back using format string %.2f, you will get 37.62 again.
I'll try to comment on, shortly.
As you may know, double is a 64 bit floating point number. There are some special formats (standards defined by IEEE in this case) to store it in memory. It consists of 3 parts; sign (1), exponent (11), significand (52 bits). There are also special rules for storing exponent and significand. Most important one, exponent part is two's exponent, not ten's. Moreover, some operations (i.e. rounding and normalization) have been applied to a floating point number after every operation. After all, it is stored as nearest possible value fitting into these rules.
|
|
|
|
|
This is what I am doin...
string filename; //filename contains "c:\\new folder\\file1.txt"
....
....
ofstream myfile;
myfile.open (filename, ios::app);
When I compile or built this I get
error C2664: 'void __thiscall std::basic_ofstream<char,struct std::char_traits<char=""> >::open(const char *,int)' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_tr<br="" mode="hold">aits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
Please help me get rid of this or any suggestion to make changes to this. THANKS
|
|
|
|
|
pl_kode wrote: myfile.open (filename, ios::app);
Change to
myfile.open (filename.c_str(), ios::app);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|