|
ifstream::seekg() works. If you are reseting to the beginning of the file, you can just close and open the file again.
Danny
|
|
|
|
|
Ok, now i have that, i have changed things that u told me, but now i think it is in a infinitive loop. Im new in c++ but a simple comparation to see if for example 2 elements from one file are in other file with 10 is difficult right now because i can't do a breakpoints to see where is the error. I dont know if u have any ideas for this code that i show here but the idea is that i described. thank u for all the help.
char data[128];
char data2[128];
bool salida2 = false;
ifstream fileusb;
ifstream database;
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);
fileusb.getline(data,128);
while (!fileusb.eof())
{
database.getline(data2,128);
while ((!database.eof())||(salida2!=true))
{
if (strcmp(data,data2) == 0){
salida2=true;
//database.clear();
database.seekg(0,ios::beg);
database.close();
database.open("USBDevices.txt", ios::in);
database.getline(data2,128);
fileusb.getline(data,128);
}
else{
database.getline(data,128);
}
}
salida2 = false;
}
fileusb.close();
database.close();
|
|
|
|
|
How about:
fileusb.getline(data, 128);
while (! fileusb.eof())
{
database.getline(data2, 128);
while (! database.eof() && salida2 != true)
{
if (strcmp(data, data2) == 0)
salida2 = true;
else
database.getline(data, 128);
}
database.seekg(0, ios::beg);
fileusb.getline(data, 128);
}
database.close();
fileusb.close();
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Ok, think i solved that, but when i find the first elemente and i change for the second in the first file i see a messagebox without nothing and later i start again good and when for example the second element is founded in the file i can't show USB registered i only show nothing but with the first i see USB registered,Maybe is the buffer??
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);//
while (! fileusb.eof())
{
fileusb.getline(data, 500);
AfxMessageBox(data);
database.getline(data2, 500);
AfxMessageBox(data2);
while (! database.eof() )
{
if (strcmp(data, data2) == 0){
//salida2 = true;
AfxMessageBox("USB registered");
break;
}
else if (strcmp(data,data2) != 0){
database.getline(data2, 500);
AfxMessageBox("USB NOT registered");
AfxMessageBox(data2);
}
}
database.seekg(0, ios::beg);
fileusb.getline(data, 500);
AfxMessageBox(data);
}
database.close();
fileusb.close();
|
|
|
|
|
Too many calls to getline() . Try:
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);
while (! fileusb.eof())
{
fileusb.getline(data, 500);
AfxMessageBox(data);
while (! database.eof())
{
database.getline(data2, 500);
AfxMessageBox(data2);
if (strcmp(data, data2) == 0)
{
AfxMessageBox("USB registered");
break;
}
}
database.seekg(0, ios::beg);
}
database.close();
fileusb.close();
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
And don't forget to put a check for the existence of the files after the open statement!
<br />
fileusb.open("GUIDs_found.txt", ios::in);<br />
database.open("USBDevices.txt", ios::in);<br />
if(!fileusb){<br />
return;<br />
}<br />
if(!database){<br />
return;<br />
}<br />
Even though it adds many lines of code, you should always check for errors... usually.
Danny
|
|
|
|
|
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;
}
|
|
|
|
|