|
|
i have a program to connect the system with mobile via bluetooth serial connection and when it comes to read method it just stops.
and the read methos is
<br />
bool ReadPort()<br />
{<br />
long int dwSize = 0;<br />
bool hResult = false;<br />
std::string sb = "";<br />
DWORD dwEventMask;<br />
<br />
if(!SetCommMask(hComm, EV_RXCHAR)) <br />
{ <br />
return hResult;<br />
}<br />
<br />
if(WaitCommEvent(hComm, &dwEventMask, NULL)) <br />
{<br />
char szBuf[1024];<br />
DWORD dwIncommingReadSize;<br />
<br />
do<br />
{<br />
if(ReadFile(hComm, &szBuf, 1024, &dwIncommingReadSize, NULL) != 0)<br />
{<br />
if(dwIncommingReadSize > 0)<br />
{<br />
dwSize += dwIncommingReadSize;<br />
sb.append(szBuf);<br />
}<br />
hResult = true;<br />
}<br />
<br />
else<br />
{<br />
unsigned long error = ::GetLastError();<br />
hResult = false;<br />
printf("the error while reading error is %dl\n", error);<br />
break;<br />
}<br />
} while(dwIncommingReadSize > 0);<br />
<br />
*readData = new char[dwSize];<br />
strcpy(*readData, sb.c_str());<br />
return hResult;<br />
}<br />
else<br />
{<br />
return hResult;<br />
}<br />
<br />
}<br />
the program just goes to wait mode in the WaitCommEvent function, even when i send a file via bluetooth from my mobile it does'nt reads and while iam sending the file the bluetooth pops the message that PIM transfer is happining, how to send file serial so that my read function should read the data and store in a file......
|
|
|
|
|
Hi,
I am developing a VC++ 6 (MFC) project in which i need to print reports with the data from sqlserver.
As a first go, I taught of using CrystalReprts. I had found many C++/VC++ samples on how to display a existing report on the dialog, but i am not able to find any C++/VC++ samples on how to print the report by using the data from sql server.
If any one has a sample or document, Please share with me.
Thanks,
Krish
|
|
|
|
|
CrystalReports comes with a number of useful functions to deal with reports. Try to search help on it. Although I did some reports in VS2003 and 2008, I'm sure there is such a possibility in VC++6 provided you have CR properly installed.
|
|
|
|
|
Hi All,
I am using a thread to do a work that is to write a file from a device. After the writing reaches to 100 MB I want to close the window and stop the thread. Stopping thread seems to be working but the window is not closed and it is showing error sometimes. But while using a button event the same code works.
void TestDlg::CloseRecord()
{
m_staGradient12.SetWindowTextA("Status:Stopped");
if(hRecording)
{
SuspendThread(hRecording);
DWORD lpExitCode;
GetExitCodeThread(hRecording,&lpExitCode);
TerminateThread(hRecording,lpExitCode);
CloseHandle(hRecording);
CloseHandle(file_rec);
hRecording = NULL;
file_rec = NULL;
OnCancel();
}
}
DWORD WINAPI Recording(LPVOID pParam)
{
TestDlg* pTSRecording = (TestDlg*)pParam;
fptr1 = fopen(def_filename,"w");
while(::WaitForSingleObject(pTSRecording->file_rec,0)==WAIT_TIMEOUT)
{
pTSRecording->ReceiveData(pbuff);
fwrite(pbuff,1,sizeof(pbuff),fptr1);
CFile file(def_filename,CFile::shareDenyNone|CFile::modeRead);
int x = file.GetLength();
file.Close();
if(x>=a)
{
fclose(fptr1);
a=0;
pTSRecording->CloseDevice();
break;
}
}
pTSRecording->CloseRecord();
return 0;
}
|
|
|
|
|
bhanu_8509 wrote: CFile file(def_filename,CFile::shareDenyNone|CFile::modeRead);
int x = file.GetLength();//for getting the length of the file after every succesive write
file.Close();
Doing this just to get the file's size is awfully expensive in terms of disk I/O. Why not just keep track of how much data is written, like:
x += fwrite(pbuff, 1, sizeof(pbuff), fptr1);
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Why are you using TerminateThread when you already appear to have a signalling mechanism in place with pTSRecording->file_rec ? To quote MSDN:
TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
Since you have an event already and your thread's while loop is testing the event's state, simply signal the event in your CloseRecord function and then WaitForSingleObject (hRecording) . This will neatly and completely and correctly shut down your thread. TerminateThread can mess up a system so much, it could be the reason your window won't close since the window and thread are interacting with each other.
Judy
|
|
|
|
|
Thanks for your advice Judy.
JudyL_FL wrote: Since you have an event already and your thread's while loop is testing the event's state, simply signal the event in your CloseRecord function and then WaitForSingleObject (hRecording). This will neatly and completely and correctly shut down your thread
Please kindly tell me how to proceed the above. I am new to threads. Please...
|
|
|
|
|
|
In addition to David's and JudyL_FL's replies...
bhanu_8509 wrote:
OnCancel();
I'm surprised you even get that far...
You probably have more than one thread started so the first one is able to suspend the second and continue, or something like that.
You're calling CloseRecord() inside the context of your thread and the first thing you do is suspend the thread.
The thread stops its execution right there and cannot continue if the handle provided is the one of the thread and it looks like you believe it is.
If you manage to get further you kill the thread inside the context of your thread by calling TerminateThread() , which is always a bad call.
And so on...
bhanu_8509 wrote:
while(::WaitForSingleObject(pTSRecording->file_rec,0)==WAIT_TIMEOUT)
This doesn't make any sense at all. This assumes the pTSRecording->file_rec is a valid handle, otherwise you'll get WAIT_FAILED as return value and exit the while-loop.
If it is a valid handle you check whether the handle is in a signalled state and if it isn't you continue immediately. It would be the same to have while(bContinue) instead, where bContinue would be a volatile declared boolean set to false when the thread should stop.
Think real hard whether you need a worker thread at all.
Consider overlapped I/O.
If you still think you need a secondary thread, read this[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all,
I have any string in given format:: "string1-string2 string3"
i want to fetch string1 that is comes before sign "-",so please tell me how can i do this?
is solve when i use findstring function.
please help me.
if possible please explain with example.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
CString::Tokenize
CAtlString str( "%First Second#Third" );
CAtlString resToken;
int curPos= 0;
resToken= str.Tokenize("% #",curPos);
while (resToken != "")
{
printf("Resulting token: %s\n", resToken);
resToken= str.Tokenize("% #",curPos);
};
By the way don't you have MSDN installed?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: By the way don't you have MSDN installed?
why installed ?
it is online, and I doubt the poster writes here by telepathy...
|
|
|
|
|
The MSDN site may be blocked LOL
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
If you're not using a string class, there's always _tcstok()
|
|
|
|
|
or sscanf() ... He did say the string always had the exact same format ...
|
|
|
|
|
Hello everyone,
In the MSDN document for uuid, it is mentioned "The compiler attaches a GUID to a class or structure declared or defined (full COM object definitions only) with the uuid attribute.". I am very confused about this statement, the input is a string format of GUID -- it is clear, but my question is what is the output and what means "attach" here?
thanks in advance,
George
|
|
|
|
|
Every COM object needs to be identified uniquely on a machine. For this the compiler generates a UUID (Universally Unique Identier) to distinguish one interface from another.
For eg: how would the system identify the uniqueness of IUnknown. For this it binds a structure having the GUID with IUnknown
[
uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45),
version(1.0)
]
interface INTERFACENAME
{
}
so if you have an interface call IMyIUnknown replace IMyIUnknown with INTERFACENAME and now this interface has a attached UUID with it so that it can be uniquely identified.
Hope I helped...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks AnShUmAn,
I think uuid is used to uniquely identifies an interface or coclass, but I am quite confused why you give an interface name replace sample here? Does uuid have some special usage in the situation of interface name replacement?
regards,
George
|
|
|
|
|
This is specific to MS and COM, it is not general C++.
By 'attach' they mean the compiler generates the COM specific code needed to associate the generated uuid with the class as a type.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Thanks cmk,
cmk wrote: By 'attach' they mean the compiler generates the COM specific code needed to associate the generated uuid with the class as a type.
Could you provide more information about what do you mean the generated code which does the association please?
regards,
George
|
|
|
|
|
Im trying to convert a string to a Const Char* How do I do that? Im using Dev and this is ther error i get:
cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `const char*' for argument `1' to `int system(const char*)'
(Im new to C++)
Y*Live Long And Prosper*Y
|
|
|
|
|
False Chicken wrote: Im trying to convert a string to a Const Char* How do I do that? Im using Dev and this is ther error i get:
cannot convert `std::basic_string<char,>, std::allocator<char> >' to `const char*' for argument `1' to `int system(const char*)'
This way!
string StrSysCommand = "cls";
system( StrSysCommand.c_str() );
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
False Chicken wrote: Im new to C++
that doesn't forbids you to interrogate the documentation...
the std::string class (which is a specialization of the std::basic_string template class) has a c_str()[^] member function...
|
|
|
|