|
Member 2883067 wrote: From Ole Server Application do we have to call this (WM_QUERYENDSESSION)
What you precisely mean with this sentence? The WM_QUERYENDSESSION message is sent by Windows in the initial steps of a shutdown.
If you want to shutdown the operating system (turn-off, reboot, ...) you should use the ExitWindowsEx Function (Windows)[^], that logs off the interactive user, shuts down the system, or shuts down and restarts the system. It sends the WM_QUERYENDSESSION message to all applications to determine if they can be terminated.
For an example on how to use that API, see How to Shut Down the System (Windows)[^]
|
|
|
|
|
I am working on a database application, developed in 'C' programming language, which talks to database through the odbc drivers. What is the best way to track/troubleshoot the 'crash' errors like NULL pointers, memory crashes, etc? As the application is a huge code base, I am looking for one smart way to track the application crashes. Please suggest, if any?
|
|
|
|
|
If you are not already using it, then the best first step is to use your debugger. You cannot do any advanced debugging without a debugger.
|
|
|
|
|
coder21k wrote: What is the best way to track/troubleshoot the 'crash' errors like NULL pointers, memory crashes, etc? As the application is a huge code base, I am looking for one smart way to track the application crashes.
Write a crash report to identify application version, environment, registers, calling stack etc. Then assign each maintainer time to investigate and fix crashes, for a huge code base you probably have multiple teams/maintainers. If you have a ticket systems for defects the teams can create individual bug tickets after investigation and narrowing down the cause of a crash, marked as important. Application crashes are not only annoying for end users, they should be handled with high priority because they could be a sign for quality/security/development weaknesses. As an alternative you could add stress and penetration tests to your test strategy.
Hope it helps
/M
|
|
|
|
|
hi,
i'm working on a project that capture real time temperature.I managed to capture the real time temperature but when i tried to send the captured values to another device it displayed weird characters eg' ?.After which i did some research again on the codings.I found out that the software i'm using doesn't support %f and i'm required to do some conversion to it.I came up with the codes but its unable to work.Please advice.
my original codes:
void loop(){
float tmpVALUE=0; char dataToSend[100];
if(!BT.createConnection("0003190D102D","02"))
{
USB.println("");
USB.print("--- CONNECTION -- MTU: ");
USB.print(BT.connection_mtu[0],BYTE);
USB.print(BT.connection_mtu[1],BYTE);
USB.println(BT.connection_mtu[2],BYTE);
}
else USB.println("Connection failed");
tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
if(tmpVALUE>0.5)
{
tmpVALUE=((tmpVALUE-0.5)/0.01);
}
else
{
tmpVALUE=tmpVALUE/0.01;
}
delay(100);
XBee.print("Temperature: ");
XBee.println(tmpVALUE);
delay(5000);
sprintf(dataToSend,"%f",tmpVALUE);
if(!BT.sendData(dataToSend)) USB.println("Data sent OK");
else USB.println("Error while sending data");
modifed
void loop()
{
float testVal=7.3812849; char dataToSend[100];
char converttmpVALUE[100];
if(!BT.createConnection("0003190D102D","02"))
{
USB.println("");
USB.print("--- CONNECTION -- MTU: ");
USB.print(BT.connection_mtu[0],BYTE);
USB.print(BT.connection_mtu[1],BYTE);
USB.println(BT.connection_mtu[2],BYTE);
}
else USB.println("Connection failed");
tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
if(tmpVALUE>0.5)
{
tmpVALUE=((tmpVALUE-0.500)/0.010);
}
else
{
tmpVALUE=tmpVALUE/0.010;
}
delay(100);
XBee.print("Temperature: ");
XBee.println(tmpVALUE);
delay(5000);
sprintf(dataToSend,"%s",ftoa(converttmpVALUE,testVal,4));
char *ftoa(char *a, double f, int precision)
{
long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
long heiltal = (long)f;
itoa(heiltal, a, 10);
while (*a != '\0') a++;
*a++ = '.';
long decimal = abs((long)((f - heiltal) * p[precision]));
itoa(decimal, a, 10);
return ret;
}
if(!BT.sendData(dataToSend)) USB.println("Data sent OK");
else USB.println("Error while sending data");
|
|
|
|
|
Check what kind of character encoding is supported by the target device.
|
|
|
|
|
[Warning]
Bound-checkings (and any other check) are left to the reader...
[/Warning]
void ftoa(char *buf, float f, int p)
{
int i, n;
unsigned long l
for (n=0; n<p; n++)
f *= 10;
l = (long) (f + .5);
for (n=0; l>0; n++, l/=10)
{
if (n==p)
{
buf[n]='.';
n++;
}
buf[n]= (l % 10) + '0';
}
for(i=0; i<n/2;i++)
{
char c;
c = buf[i];
buf[i] = buf[n-1-i];
buf[n-1-i]= c;
}
buf[n]='\0';
}
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
[My articles]
|
|
|
|
|
hi,
thanks for replying.The solution you gave me doesn't work as my editor gave me an error:(In function 'void loop()':
error: expected primary-expression before 'char').Maybe you would like to take a look at the whole code as I've been trying several methods but it still doesn't work.I'm just a beginner in c++ so do bear with me.Thanks
float tmpVALUE=0;
int n=0;
void setup(){
SensorEvent.setBoardMode(SENS_ON);
XBee.setMode(XBEE_ON);
delay(50);
USB.begin();
USB.println("USB port started...");
USB.close();
BT.ON();
if( BT.flag & BT_ERROR_ON ) USB.println("Error, 'ROK' not received");
else USB.println("BT module ready...");
if(!BT.init()) USB.println("Init OK");
}
void loop()
{
float tmpVALUE=0; char dataToSend[100];
char converttmpVALUE=0;
if(!BT.createConnection("0003190D102D","02"))
{
USB.println("");
USB.print("--- CONNECTION -- MTU: ");
USB.print(BT.connection_mtu[0],BYTE);
USB.print(BT.connection_mtu[1],BYTE);
USB.println(BT.connection_mtu[2],BYTE);
}
else USB.println("Connection failed");
tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
if(tmpVALUE>0.5)
{
tmpVALUE=((tmpVALUE-0.5)/0.01);
}
else
{
tmpVALUE=tmpVALUE/0.01;
}
delay(100);
XBee.print("Temperature: ");
XBee.println(tmpVALUE);
delay(5000);
sprintf(dataToSend,"%s",converttmpVALUE);
ftoa(char* buf,float f,int p);
{
int i, n;
unsigned long l
for (n=0; n<p; n++)
f *= 10;
l = (long) (f + .5);
for (n=0; l>0; n++, l/=10)
{
if (n==p)
{
buf[n]='.';
n++;
}
buf[n]= (l % 10) + '0';
}
for(i=0; i<n/2;i++)
{
char c;
c = buf[i];
buf[i] = buf[n-1-i];
buf[n-1-i]= c;
}
buf[n]='\0';
}
if(!BT.sendData(dataToSend)) USB.println("Data sent OK");
else USB.println("Error while sending data");
if(!BT.removeConnection()) USB.println("Connection removed");
else USB.println("Error while removing connection");
if(!BT.removeTrustedDevice("0003190D102D")) USB.println("Trusted Device removed");
else USB.println("Error while removing trusted device");
delay(5000);
}
|
|
|
|
|
Hello people!
I have the following (simplified) code:
OVERLAPPED Overlap = {0};
Overlap.hEvent = event_reader_with_CreateEvent;
if (ReadFile(handle_for_com_port, pBuffer, buffer_size, &bytes_read, &Overlap)) ...data read, go on happily...
else if (GetLastError() == ERROR_IO_PENDING)
{
if (WaitForMultipleObjects(1, &Overlap.hEvent, FALSE, dwTimeOut) == WAIT_OBJECT_0)
{
if (GetOverlappedResult(handle_for_com_port, &Overlap, &bytes_read, FALSE)) ...data read, go on happily ...
else if (GetLastError() == ERROR_IO_INCOMPLETE)
{
What to do here???
} else ...IO error, report and go on not so happily...
}
}
So what to do in case of ERROR_IO_INCOMPLETE? Googling around i found code sniplts where they simply try GetOverlappedResult again and again for a while until it succeeds OR some timeout or somesuch occurs. However, time to time i run into the following confusing situation:
1. ReadFile called resulting in ERROR_IO_PENDING
2. Waiting on the event returns with WAIT_OBJECT_0, the event is signalled
3. GetOverlappedResult returns FALSE and the last error code is ERROR_IO_INCOMPLETE, however, if i check the buffer (pBuffer) with the debugger i see that the data is already fully in it, however, bytes_read is 0 and it remains zero and repeatedly calling GetOverlappedResult will always result in ERROR_IO_INCOMPLETE for all ethernity (or at least as long as i was willing to wait).
Anyone knows why this is happening and what i can do to solve it? Another thing that turned up is that if i try to "timeout" from this, i mean, call GetOverlappedResult a few times giving up after a while and continuing will result in "damaged memory block", maybe because the buffer pointed at pBuffer goes out of scope but someone, somewhere still tries to write into it (just a guess)? Anyways, timeouting still can't be a solution because i lose the data that was actually read into the buffer, confusing confusing confusing...help!!!
p.s: if i call GetOverlappedResult with TRUE as the last parameter than it just seem to hang...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
modified on Monday, November 8, 2010 3:13 PM
|
|
|
|
|
|
Thank you for the link but i did set up the port using the DCB structure, SetCommState and SetCommTimeouts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
That's strange.
Could you try giving TRUE for the third parameter of WaitForMultipleObjects or use WaitForSingleObject !!!
|
|
|
|
|
In the actual code there are more then one event i am waiting for that is why you see WaitForMultipleObjects , i just simplified the code for simplicity. And yes, i am sure that the event signalling the overlapped operation completion is fired, it is the very first event handle inside the array passed to the wait function and i get WAIT_OBJECT_0 from it. Most of the time this seems to be working ok but time to time...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
Oh... I've so forgotten the usage of character arrays!
for example:
char * Func (char * sT)
{
char sRet [MAX_STR_SIZE] = "";
strcpy (sRet, sT);
return sRet;
}
And when compiling I get a warning returning address of local variable or temporary
I think I know why it tells me this, but not completely sure... Would it be more reasonable to do void Func (char * sT, char * sRet) ?
|
|
|
|
|
You should really stop home cooked memory handling and write std::string sRet(sT) , or (MFC) CString sRet(sT) , or ATL::CString sRet(sT) ... other string classes omitted.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Err... well, I know that and agree with you, but my boss does not think the same. I have mentioned him several times that it is more secure to use std::string or any other, but apparently it is best to use char * and home cooked functions for the system the application will run in.
I understand your worries, I will make sure someone checks my code before it goes on the system.
|
|
|
|
|
piul wrote: my boss does not think the same. I have mentioned him several times that it is more secure to use std::string or any other, but apparently it is best to use char * and home cooked functions for the system the application will run in. I sympathize Try find another job or another boss
Meanwhile: piul wrote:
char * Func (char * sT)
{
char sRet [MAX_STR_SIZE] = "";
strcpy (sRet, sT);
return sRet;
} And when compiling I get a warning returning address of local variable or temporary
Your nice compiler warns you that sRet points to deallocated memory when returned.
A solution is to make sRet static: static char sRet [MAX_STR_SIZE] = {0}; .
It will be overwritten on each call but valid on return.
For safety use strncpy(sRet, sT, MAX_STR_SIZE - 1) .
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
You have a buffer that is local - it exists on the stack.
When you exit the routine the stack, for that routine, will no longer exist.
As for the best way to do it it depends on what you are doing. But at a minimum the calling routine would need to pass its local buffer for the copy operation. Or manage it on the heap and make sure to delete it when done.
|
|
|
|
|
piul wrote: I think I know why it tells me this, but not completely sure...
Because sRet ceases to exist once Func() goes out of scope.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
The problem is that you are returning a pointer to a buffer that will go out of scope after your function exit: then then returned pointer is no longer valid and what you find there is going to be pseudo-random.
To fix the problem you can:
- allocate the output buffer out from the function
- allocate the output buffer using
new or malloc (but you should remember to deallocate it when it is no more needed)
However, as Alan said, the very best way is to stop using C-style strings and use std::string instead: the STL is one of the better solutions because all its classes are inlined and highly optimized. This will give you very good performances with a minimal footprint (the unused classes and methods simply are not compiled and don't affect the executable size).
|
|
|
|
|
You should look up to the signature of strcpy as a reference.
The first parameter to strcpy is the out parameter and the second is the in parameter.
So change your function to be something similar even though it really doesn't make sense in this context -
int Func(char* sRet, const char* sT)
{
return strcpy(sRet, sT);
}
Also, if you're not able to use std::string , at least use the secure versions of the C runtime functions like strcpy_s .
|
|
|
|
|
sRet is a local variable allocated on the stack and as such the memory it uses will be reclaimed when Func returns. That means the stuff it points to will probably not contain what you think it does at some point in the future.
So you have essentially 2 choices:
1. Use void Func (char * sT, char * sRet) as you suggest. Func would then copy the string into the memory supplied by the caller. That memory of course has its own lifecycle.
2. Allocate memory in Func(). For example in C++:
char * Func (char * sT)
{
char * sRet = NULL;
sRet = new char[MAX_STR_SIZE];
if (sRet)
strcpy (sRet, sT);
return sRet;
}
In this case someone has to deallocate the newed up memory later. So for example:
void Foo(void)
{
char *mystr = Func("test");
DoSomethingInteresting(mystr);
delete mystr [];
}
|
|
|
|
|
Hi,
I've created a dialog box from within the activex control and it contained a edit control.
But that edit control doesn't accept text when it is displayed..What might be the prob?
|
|
|
|
|
lakshman rao wrote: But that edit control doesn't accept text...
You can't type into it? You can't paste into it? You can't set its text via code?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: You can't type into it? You can't paste into it? You can't set its text via code?
I can't type into it.
|
|
|
|
|