|
bugDanny wrote:
Even though it adds many lines of code, you should always check for errors... usually.
Of course, but that's not related to the problem(s) that densitet is having.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-- modified at 17:07 Wednesday 14th September, 2005
|
|
|
|
|
DavidCrow wrote:
Of course, but that's not related to the problem(s) that densitet is having.
Unless, of course, sometime (now or in the future) one of those files (for some unknown reason) does not exist where they were expected to be. In which case, the program would be stuck in an infinite loop, since it will never find eof() of the missing file. And an infinite loop is exactly the problem densitet was having.
Danny
|
|
|
|
|
bugDanny wrote:
And an infinite loop is exactly the problem densitet was having.
At one point in time, yes, but it was not because of a non-existent file.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Can any one help me. I have one problem in my MFC application. After an hour the application gets slowed down.That is after continuous use of the application about an hour it slows down itself and other applications too.
The CPU usage also seems to be good. It takes just 20 to 30%.
Checked with memory leak procedure. Seems to be okay. Is there any other methods by which the application can be monitored for memory leak and other things.
This is first time ever I see the problem.
Reply will be highly appreciable.
NSS
|
|
|
|
|
plz tell
what type of app is this ?
r u constantly adding variable dynamic stack of you application
|
|
|
|
|
The application is for PLC system. The PLC system keeps sending information about the status of control equipment. similarly the user can send request and commands to PLC.
If commands are sent frequently,the application gets slowed down. The application is well designed. There will two threads for PLC one thread for executing boolean equations.
What I suspect is, if commands are given during execution of other task, it delays the commands.
|
|
|
|
|
nss_75 wrote:
After an hour the application gets slowed down.
What are you using to gauge this?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Your program is eating up all the memory resourses. It can do this without leaking any memory at all, if it is not losing track of what resourses it allocated. To test for this, simply close the program and see if the other applications return to thier normal operating speed.
The CPU usage suggest that you are not (stuck) in an infinite loop some where, that is all. (If you where, you probably could not close the program)
There are multiple ways to figure out what the problem is:
1) Start with examining the code.
2) Profile (Build->Profile...) over a short run.
3) Override the global new() and delete() (to avoid modifying the main code itself and assuming that you are using new/delete instead of some other Windows specific allocation routines) to output meaningful data. The meaningful data can the output via the TRACE() macro or sent to a file.
4) Add TRACE() calls every where you allocate/release resourses or duplicate the TRACE() macro to write to a file instead.
Well, that the short list, ecept that 3 and 4 are inter-chagable if you wrote all the code yourself.
INTP
|
|
|
|
|
i'm using dialog based application as my own gui. i'm facing problem in button. i want a button with two function. that means the button can resemble start recording and stop recording. what are the source code for that? thx a lot for your help.
|
|
|
|
|
You can implement both the logic in the same function.
Eg:
Create a state member varible, which will identify it is recording or not.
Initialize the state to STOP
CYourClass::OnButton()<br />
{<br />
if(STATE_STOP == m_enState)<br />
{<br />
m_enState = STATE_REC;<br />
}<br />
else if(STATE_REC == m_enState)<br />
{<br />
m_enState = STATE_STOP;<br />
}<br />
}
|
|
|
|
|
is it i jst copy this code into the programming and no need right click the button and set its properties anymore? i'm newbie, hope you can help. thx.
|
|
|
|
|
You have to add the message handler for the buton first.
Double click on the button, a message handler for "BN_CLICKED" will be created.
Inside the function you can use the logic that i have specified.
For that you have to create a State member varible.
Go to the header file and declare
int m_State;
Declare the states also....
#define STATE_REC 1
#define STATE_STOP 0
then proceed with your coding.....
|
|
|
|
|
just declare a flag to check which function you want to call
|
|
|
|
|
just create two buttons perfectly overlapping, but being hidden once at a time. this way, you have once handler per button, and just have to ShowWindow(SW_HIDE) or ShowWindow(SW_SHOW) the buttons
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
hi i want to calculate execution time of the function
how should i go about it ?
is it possible (as it is done in winrunner)
Also if i have to calculate logical time(by calculatin frequencies of statements) which algorithm should i use
plz help
sagar
love is photogenic, it requires a dark to develope
|
|
|
|
|
You can use GetTickCount function to retrieve the number of miliseconds elapsed.
|
|
|
|
|
Main Menue->Build->Profile...
It should point you in the right direction for profiling. You'll need to lookup the details in the MSDN.
Lookup QueryPerformanceFrequency().
There is also the multi-media timers.
There is also also a timer class article at CP (call CDurration, I think).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
No what i want is an application which calculates execution time of other codes
e.g.
Input to my application will be abc.c
abc.c contains 5 functions
then my output sould be execution tim of these 5 functions
as done in winrunner
Is it possible
plz help
Sagar
Love Is photogenic,It require a dark to develope
|
|
|
|
|
I use WMI to set Ip Address for my local computer.
every function works well. but nothing changed.
Why?? I use vc6,xp OS. For some header files,you can found them from vc7, just copy them to the Include directory for vc6.
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
for a test,the above line must be modified.replace "MyComputerName" with your own computer name.
I paste all the code here. A win32 console app.
Thank you everyone.
#define _WIN32_DCOM
#include
#pragma comment(lib,"Wbemuuid.lib")
#include
//#include "wbemcli.h"
#include "objbase.h"
#include
#include
#pragma comment(lib, "comsupp.lib")
void CreateOneElementBstrArray(VARIANT* v, LPCWSTR s)
{
SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
// Determine number of bytes to be allocated for ANSI string. An
// ANSI string can have at most 2 bytes per character (for Double
// Byte Character Strings.)
cbAnsi = cCharacters*2;
// Use of the OLE allocator is not required because the resultant
// ANSI string will never be passed to another COM component. You
// can use your own allocator.
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
// Convert to ANSI.
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
void PrintWMIError(HRESULT hr)
{
IWbemStatusCodeText * pStatus = NULL;
HRESULT hres = CoCreateInstance(CLSID_WbemStatusCodeText, 0,
CLSCTX_INPROC_SERVER,IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
if(S_OK == hres)
{
BSTR bstrError;
hres = pStatus->GetErrorCodeText(hr, 0, 0, &bstrError);
if(S_OK != hres)
bstrError = SysAllocString(L"Get last error failed");
LPSTR pszStatusTextA;
UnicodeToAnsi(bstrError, &pszStatusTextA);
printf("%s\n",pszStatusTextA);
CoTaskMemFree(pszStatusTextA);
pStatus->Release();
SysFreeString(bstrError);
}
}
HRESULT ConfigNet()
{
IWbemLocator *pLocator=NULL;
IWbemServices *pNamespace=NULL;
IWbemClassObject *pClass=NULL;
IWbemClassObject *pInputParamClass=NULL;
IWbemClassObject *pInputParamInstance=NULL;
IWbemClassObject * pOutInst = NULL;
BSTR InstancePath = SysAllocString(L"Win32_NetworkAdapterConfiguration=2");
HRESULT hr;
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IPAddress";
VARIANT var1;
LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
__try
{
CreateOneElementBstrArray(&var1, L"10.0.0.101");
CreateOneElementBstrArray(&var2, L"255.255.255.0");
CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLocator);
hr = pLocator->ConnectServer(Path,NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
hr = CoSetProxyBlanket( pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pClass->GetMethod(MethodName, 0, &pInputParamClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamClass->SpawnInstance(0, &pInputParamInstance);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg1Name, 0, &var1, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg2Name, 0, &var2, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL,
pInputParamInstance, &pOutInst, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
}
__finally
{
if(pInputParamInstance)
pInputParamInstance->Release();
if(pInputParamClass)
pInputParamClass->Release();
if(pClass)
pClass->Release();
if(pNamespace)
pNamespace->Release();
if(pLocator)
pLocator->Release();
}
return hr;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ConfigNet();
CoUninitialize();
printf("Program end\n");
return 0;
}
|
|
|
|
|
I got runtime error when I am moving toolbars in my program. Please can any one solve my problem.
The steps to reproduce are:
1) Start application eithor in Release mode or Debug mode.
2) Select the Com port to communicate.
3) Select start polling. (In this option the polling function will be
called repeatedly for every 2 seconds.
In that function we are getting details of hardware. Be cause if
we need the current details of hardware we need to do eithor refresh, or start polling. then we can get the current details of HW. )
4) Move tool bars 3 or 4 times.
( I have 4 tool bars in my program. they are 1. Standard toolbar,
2. CDialogBar m_wndPolling;//will be created through dialog design.
3. CToolBar m_wndToolBar; // will be created through dialog design
4. CToolBar m_tlbAlarms; ) // will be created completely at runtime.
5) Got Runtime error.
(If I am not moving tool bars then I am not getting any crash.)
The error has occured for me eithor in debugging mode or in relealse mode.
If any thing not clear please let me know.
When i got error in debugging mode, the call stack in my program is follows:
CDockContext::InitLoop() line 427 + 31 bytes
CDockContext::StartDrag(CPoint {x=0x00000145 y=0x00000144}) line 84
CControlBar::OnLButtonDown(unsigned int 0x00000001, CPoint {x=0x00000145 y=0x00000144}) line 645
CWnd::OnWndMsg(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6, long * 0x0012eb54) line 1964
CWnd::WindowProc(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 1585 + 30 bytes
CControlBar::WindowProc(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 480 + 20 bytes
AfxCallWndProc(CWnd * 0x00324ea4 {CToolBar hWnd=0x007904ba}, HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 368
AfxWndProcBase(HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 220 + 21 bytes
Any help will be great. Thank you
Nice talking to you.
|
|
|
|
|
Hello..
I'm a beginner with Visual C++.. (have only done very very basic C++ programming).. I'm trying to communicate with a microcontroller using serial communication.. I tried to do it from scratch using the Windows functions..this is what my code looks like..
#include "stdafx.h"<br />
<br />
int _tmain()<br />
{<br />
<br />
HANDLE h = CreateFile("COM3", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);<br />
if (h == 0)<br />
{<br />
printf("Can't open com port (1)\n");<br />
return 1;<br />
}<br />
DCB dcb;<br />
memset(&dcb, 0, sizeof(DCB));<br />
dcb.DCBlength = sizeof(DCB);<br />
dcb.BaudRate = 19200;<br />
dcb.fBinary = TRUE;<br />
dcb.fParity = FALSE;<br />
dcb.ByteSize = 8;<br />
dcb.Parity = NOPARITY;<br />
dcb.StopBits = ONESTOPBIT;<br />
BOOL result = SetCommState(h, &dcb);<br />
if (!result)<br />
{<br />
printf("Can't set com port state(2)\n");<br />
return 1;<br />
}<br />
<br />
if (result)<br />
printf("Have Set com port state\n");<br />
<br />
char buffer[100];<br />
DWORD bytesRead = 0;<br />
while (true)<br />
{<br />
printf("In while\n"); <br />
<br />
memset(buffer, 0, sizeof(buffer));<br />
if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
{<br />
printf("Read file has a result\n"); <br />
if (bytesRead != 0)<br />
{<br />
printf("Got some bytes\n"); <br />
printf ("%s", buffer);<br />
}<br />
<br />
else {<br />
printf("No bytes read\n"); <br />
}<br />
}<br />
<br />
else {<br />
printf("Readfile didnt give proper result \n"); <br />
}<br />
Sleep(200);<br />
}<br />
<br />
CloseHandle(h);<br />
<br />
return 0;
he micro is continously sending characters to the serial port.. when i run the program.. the port does gets initialized properly (debug statement printed ) then some characters are recieved but they are unintelligble.. i've checked the speed and all other settings for the com port and they are the same as the micro and the micro's usart is working fine.. can anyone see why i'm getting garbage..
Thank you for the help..
|
|
|
|
|
Hi,
Can you check this with Hyperterminal tool provided along with the operating systems?. If hyperterminal prints the right characters send by the microcontroller then we can dig into your code... Could you please do this??
And also check whether the characters sent by the microcontroller are ascii or unicode complaint..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Hello..
Thanks for your reply.. I've checked with Hyper Terminal.. the characters are receieved properly.. the micro is sending ASCII characters..
Regards,
Aditi
|
|
|
|
|
We need more beginners like you. You have good instincts as to how to figure out what the problem is. (You also have the option of using the TRACE() marcos, as well as printf(), in order to print debugging resutls).
Unfortunaley your code is good enough that it should probably be working. It does need improvement, but that's not the problem. What the problem is I do not know and I've written severial serial communications programs. In otherwords, I'd have to be degugging it.
SOME COMMENTS:
1) CreateFile() doesn't return 0 on failure, it returns INVALID_HANDLE_VALUE (which is equal to -1). All this tells us it that even thou your code does not know if it failed to open a port, it has succeded because you are receiving data. (Oh, if it did fail you code would report that it fail to open port 1 not 3).
2) Use: if(result) {...} else {...}. Not: if(result) {...} if(!resutl) {...}
3) If ReadFile() succededs then bytesRead should not be 0, so checking for it makes no since.
GARBAGE IS A RELITIVE TERM:
1) Your code implies that you are expecting to receive (ASCII) text. If that is not what the microcontroller is returning, then it will look like garbage.
2) What are you expecting to receive from the microcontroller?
FYI:
I assume you know that you are writting C code and not C++ code.
(It has no effect on your problem or its solution).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
There are two things at the top of my head: flow control and timeouts.
In most cases when you are beginning to communicate with a MC or similar you don't need any flow control and you would select "None" in Hyperterminal.
In your code this would mean the following setting that you have omitted:
<br />
dcb.fDtrControl = DTR_CONTROL_ENABLE;<br />
dcb.fRtsControl = RTS_CONTROL_ENABLE;<br />
Since you have fillled the DCB struct with zeros, the HW signals DataTerminalReady and RequestToSend will be inactive. Depending on connected hardware this could have various results from no communication to no impact at all.
Regarding timeouts you may want to read about it in MSDN under the documentation for the ::SetCommTimeouts function.
Tip of the day: use PortMon!
I have found PortMon to be extremely helpful in situations like the one you are describing. PortMon is freeware and can be downloaded at http://www.sysinternals.com/utilities/portmon.html[^]
With PortMon it's easy to determine how the port is setup and see what is sent and received in either hex or ASCII.
Make sure that the setup sequence looks the same for both your app and HT since HT seems to be working.
Hope this helps
--
Roger
|
|
|
|
|