|
Thank you,that puts my mind at rest
|
|
|
|
|
Hello,
I have an application that calls functions in a static library, which internally does something with sound card( static library is third party library). I call a function say x(on button click), and after the function call finishes the CPU usage goes to 100% ( on displaying the UI). The function work perfectly if i call the same in a console application and CPU usage is normal. Any help is appreciated.
Thanks
Ganesh.M.Ramaswamy
|
|
|
|
|
Have you tried breaking your program while it is using 100% CPU?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Yeah, i did. after a long struggle it terminates.
Ganesh.M.Ramaswamy
|
|
|
|
|
Do you have a while loop somewhere where you keep looping till a condition is false or true? If that is so, try putting a sleep inside the while loop, and see if it still takes 100% CPU.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
When does exactly the 100% peak occur? After (a) the function returns or (b) while the function is executing?
if (a), what does the function do? Playing a sound? Could it be that the function somehow stuffs many messages on your app message queue and those make the app chokle afterward? If so, you can try executing the function on a separate thread and see what happens.
I think some more info on the scenario would help locate the problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Its occurs after the function returns. OK. I am bit more close. The moment any GUI gets displayed it shoots to 100%. If i didnt show any GUI and put a sleep for a longtime nothing happens. Even if i give a message box after the funtcion CPU usage shoots to 100%. I need to check the sound card message dumping.
Ome more, if i have a Console application doing the same thing then everything works perfectly. Same calls and same libraries. I dont know whats happening.
Thanks for ur time.
Ganesh.M.Ramaswamy
|
|
|
|
|
Do you draw the dialog yourself?
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
The problem is solved. Its because of another infinite while - some where deep in the library. Thanks to u all for ur time and help.
Ganesh.M.Ramaswamy
|
|
|
|
|
Greetings,
I was wondering if there is a way to play resource Avi's using directshow?
I can play an avi with directshow using the file path, but how about using a resource avi?
Thanks in advance.
|
|
|
|
|
... but I stacked
I want same Doc/View to handle 2 (or more) different file types in MDI appication.
The problem is the resource string ID that you pass to CMultiDocTemplate conctructor. As I got it, you can have only on file type in that string (the extension thingy).
Example:
.htm and .html files are the same, so they can be viewed/edited with same Doc/View pair, but I have to create separate CMultiDocTemplate for each, because of that string.... So I have to manage more menus also...
So is there a way to handle 2 and more sile types with same DocTemplate?
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
|
Oh thanx exactly what I needed
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
I have multiple user interface threads. I am trying to post a message using postmessage so that all of the threads (they are all the same class doing the same things) react to the message.
The problem is that only the thread that posts the message receives the message.
What combination of message declarations and message maps should I be using so that all of the threads receive the message?
|
|
|
|
|
Since all your threads are instances of the same class (let's call it CMyUIThread ) the simplest solution is maintaining a static list of all active threads and let a method multiplex message posting to all of them. Scheme follows:
class CMyUIThread: public CWinThread
{
public:
CMyUIThread()
{
activeThreads.insert(this);
}
~CMyUIThread()
{
activeThreads.erase(this);
}
protected:
static void BroadCastMessage(UINT Msg,WPARAM wParam,LPARAM lParam)
{
for(activeThreadsIterator it=activeThreads.begin();it!=activeThreads.end();++it){
it->PostThreadMessage(Msg,wParam,lParam);
}
}
private:
static std::set<CMyUIThread*> activeThreads;
typedef std::set<CMyUIThread*>::iterator activeThreadsIterator;
}; This code is merely an indication (it probably won't even compile), but hopefully you're getting the idea: when a thread wants to broadcast a message, it simply calls BroadCastMessage , which does the dirty job of posting to all threads one by one. Regards.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ok i see the theory. Initially I thought that I was doing something wrong and that was why only my posting thread got the message.
Would a postmessage in say the main application thread reach all of the gui threads?
Thanks for the quick response.
|
|
|
|
|
Would a postmessage in say the main application thread reach all of the gui threads?
No. Each invokation of PostMessage and similar functions will reach only one thread.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello All,
I am trying to delete the IE History completely, I have used the ClearHistory method (below), however, the History deletes, but the links are still present in the Address (dropdown) in IE6.0 ?
For example, I run my program (calling ClearHistory), after program execution completes, I open up a fresh browser (IE6), I click on the History button, and it displays nothing , but I click on the Address dropdown, and the sites visited still exist?? I don't understand how to delete the links in the Address dropdown , any guidance is appreciated. Thanks in Advance!!
================================================================
Method Signature;
================================================================
IUrlHistoryStg2::ClearHistory Method
Clears history on a per-user basis.
Syntax
HRESULT ClearHistory(VOID);
Return Value
Returns S_OK if successful, or an error value otherwise.
================================================================
Code Snippet (from Microsoft docs)
================================================================
include <shlguid.h> // Needed for CLSID_CUrlHistory
#include <urlhist.h> // Needed for IUrlHistoryStg2 and IID_IUrlHistoryStg2
IUrlHistoryStg2* pHistory; // We need this interface for clearing the
history.
HRESULT hr;
DWORD cRef;
CoInitialize(NULL);
// Load the correct Class and request IUrlHistoryStg2
hr = CoCreateInstance(CLSID_CUrlHistory,
NULL, CLSCTX_INPROC_SERVER,
IID_IUrlHistoryStg2,
reinterpret_cast<void **="">(&pHistory));
if (SUCCEEDED(hr))
{
// Clear the IE History
hr = pHistory->ClearHistory();
}
// Release our reference to the
cRef = pHistory->Release();
CoUninitialize();
==================================================
Soliant - soliant@yahoo.com
|
|
|
|
|
I am just learning VC++. I am trying to read from an Excel file using VC++ but I can't find any good help on how to do it. Does anyone have any ideas?
|
|
|
|
|
G'Day Havoc,
You should be able to find enough information in MSDN to get you going. Here is one link to a few articles
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno97ta/html/msoautovc.asp
failing that try searching with the key words 'excel' and 'autmation'
Good luck
Richard.
|
|
|
|
|
#ifndef _EXCELSPACE_H
#define _EXCELSPACE_H
#include "excel9.h"
class CExcelSpace : public CObject
{
public:
CExcelSpace();
~CExcelSpace();
BOOL OpenExcel(LPCTSTR lpszFileName,LPCTSTR lpszSheetName,
BOOL m_bReadOnly = TRUE, BOOL bNewFile = FALSE, BOOL bNewSheet = FALSE );
void Close();
void GetRowColCount(int &row, int &col);
COleVariant GetCellValue(int row, int col);
BOOL SetCellValue(int row, int col,COleVariant var);
BOOL DeleteRow(int row);
CString GetFileName() { return m_szFileName; };
BOOL IsReadOnly() { return m_bReadOnly; };
void PrepareFetchData();
void EndFetchData();
BOOL ActiveSheet(LPCTSTR lpszSheetName);
BOOL IsSheetExist(LPCTSTR lpszSheetName);
BOOL DeleteSheet(LPCTSTR lpszSheetName);
BOOL NewSheet(LPCTSTR lpszSheetName);
_Application GetApplication()
{
return excelApp;
}
protected:
CString m_szFileName;
CString m_szSheetName;
BOOL m_bNewFile;
BOOL m_bReadOnly;
BOOL m_bValidate;
BOOL m_bServiceStarted;
BOOL bPreparedFectch;
CStringArray fldNames;
_Application excelApp;
int rowCount, colCount;
int curRow;
COleSafeArray sa;
BOOL StartExcelService();
CString InnerGetColumnName(int col);
CString GetCellName(int row, int col);
int NameToIndex(LPCTSTR lpszFldName);
// Dataset function
public:
int GetRecordCount() { return rowCount; };
int GetColCount() { return colCount; };
BOOL AddColumn(LPCTSTR lpszColName, int nColType);
CString GetColumnName(int col);
int GetColumnType(int col);
BOOL Delete();
BOOL InsertRow(BOOL bAppend);
BOOL Update();
COleVariant GetFieldValue(int col);
COleVariant GetFieldValue(LPCTSTR lpszFldName);
void SetFieldValue(int col,COleVariant var);
void SetFieldValue(LPCTSTR lpszFldname,COleVariant var);
BOOL MoveFirst();
BOOL MoveNext();
BOOL MoveBefore();
BOOL IsEOF();
BOOL IsBOF();
public:
static BOOL NewExcelSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static BOOL IsSheetExist(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static BOOL DeleteSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static CString OleVariantToStr( const COleVariant & Var);
};
#endif
-------------------------------------
CExcelSpace::CExcelSpace()
{
m_szFileName = "";
m_bReadOnly = TRUE;
m_bValidate = FALSE;
bPreparedFectch = FALSE;
curRow = -1;
rowCount = colCount = 0;
m_bServiceStarted = FALSE;
}
CExcelSpace::~CExcelSpace()
{
fldNames.RemoveAll();
Close();
}
void CExcelSpace::Close()
{
if( m_bServiceStarted )
{
TRY
COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_Workbook workbook = excelApp.GetActiveWorkbook();
workbook.Close(COleVariant((short)FALSE), VOptional, VOptional);
excelApp.Quit();
CATCH_ALL(e)
e->Delete();
END_CATCH_ALL
m_bServiceStarted = FALSE;
}
if( m_bValidate )
{
EndFetchData();
m_bValidate = FALSE;
}
}
CString CExcelSpace::GetCellName(int row, int col)
{
col++;
int count = 0;
char szNum16[32],szTmp[32];
while( col > 0 )
{
int m = (col-1)%26;
col = (col-1)/26;
szTmp[count++] = (char)('A'+m);
}
for(int i=0; i<count; i++)
="" sznum16[i]="szTmp[count-1-i];
" sznum16[count]="0;
"
="" cstring="" s;="" s.format("%s%d",sznum16,row+2);
="" return="" s;
}
int="" cexcelspace::nametoindex(lpctstr="" lpszfldname)
{
="" for(int="" i="0;" i<fldnames.getsize();="" {
="" if(="" fldnames.getat(i).comparenocase(lpszfldname)="=" 0="" )
="" i;
="" }
="" -1;
}
bool="" cexcelspace::addcolumn(lpctstr="" lpszcolname,="" int="" ncoltype)
{
="" colevariant="" var(lpszcolname);
="" setcellvalue(-1,="" colcount-1,="" var)="" szcolname="lpszColName;
" fldnames.add(="" );
="" colcount++;
="" true;
="" else
="" false;
};
cstring="" cexcelspace::innergetcolumnname(int="" col)
{
="" var="GetCellValue(-1,col);
" olevarianttostr(var);
}
cstring="" cexcelspace::getcolumnname(int="" s(_t(""));
="" col="">=0 && col < fldNames.GetSize() )
s = fldNames.GetAt(col);
return s;
}
int CExcelSpace::GetColumnType(int col)
{
return 0;
}
void CExcelSpace::GetRowColCount(int &row, int &col)
{
row = col =0;
if( !m_bValidate )
return;
Range range = excelApp.GetActiveCell();
COleVariant Value((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
range = range.SpecialCells(11,Value);
Value = range.Select();
row = range.GetRow()-1;
col = range.GetColumn();
}
void CExcelSpace::PrepareFetchData()
{
if( !bPreparedFectch )
{
COleVariant cell1( GetCellName(-1,0) );
COleVariant cell2( GetCellName(rowCount,colCount) );
Range range = excelApp.GetRange( cell1,cell2);
VARIANT ret = range.GetValue();
sa.Attach(ret);
bPreparedFectch = TRUE;
}
}
void CExcelSpace::EndFetchData()
{
if( bPreparedFectch )
{
sa.Detach();
bPreparedFectch = FALSE;
}
}
COleVariant CExcelSpace::GetCellValue(int row, int col)
{
COleVariant var;
var.Clear();
if( m_bValidate && row >= -1 && col >= 0 && row < rowCount && col < colCount )
{
TRY
if( bPreparedFectch )
{
long index[2];
index[0] = row+2;
index[1] = col+1;
sa.GetElement(index, &var);
}
else
{
CString cellName = GetCellName(row,col);
COleVariant cell1( cellName );
//COleVariant cell2( cellName );
Range range = excelApp.GetRange( cell1,cell1);
var = range.GetValue();
}
CATCH_ALL(e)
e->ReportError();
e->Delete();
END_CATCH_ALL
}
return var;
}
|
|
|
|
|
I bumped into this sad example while working with a "professional" charting library that I am forced to use. This code (changed to protect the guilty) comes from the drawing code in one of the charting code's base classes
<br />
switch( dwSomeValue )<br />
{<br />
case SOME_CHARTTYPE1:<br />
case SOME_CHARTTYPE2:<br />
case SOME_CHARTTYPE3:<br />
case SOME_CHARTTYPE4:<br />
case SOME_CHARTTYPE5:<br />
{<br />
break;<br />
}<br />
default:<br />
case SOME_CHARTTYPE6:<br />
case SOME_CHARTTYPE7:<br />
case SOME_CHARTTYPE8:<br />
case SOME_CHARTTYPE9:<br />
case SOME_CHARTTYPE10:<br />
{<br />
}<br />
}<br />
So now when a custom value (chart) is added, for example "SOME_NEW_CHARTTYPE11", the "Some Other Code" code block always gets executed, because the "default:" was placed in the middle of the switch statement, with no "break;" after it!
Now, I may be wrong here, but I am pretty sure that this is a bug in the charting class' code. What I really want to know is, can anyone provide me with an example where (mis)using a "default" in the middle of a switch statement like this is a good idea?
Peace!
-=- James.
|
|
|
|
|
I have what I think is an example.
I used it in a PreTranslateMessage for keystrokes. I need only certain keys to get through to the target window, so the default would cover all those unknown keys that M$ would add in the future. I obviously don't want my control to handle them.
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
|
|
|
|
|
(Note that I am not asking about uses for the "default" clause...)
If I understand you correctly, I think your example can be implemented with a "default:" clause at the end of the switch statement, correct? For example:
<br />
switch( uiKey )<br />
{<br />
case VK_A:<br />
{<br />
break;<br />
}<br />
case VK_B:<br />
{<br />
break;<br />
}<br />
default:<br />
{<br />
break;<br />
}<br />
}<br />
My question specifically asks about a "default" clause in the middle of a switch, with no "break;", followed by other "case" values.
Peace!
-=- James.
|
|
|
|
|
That code is definitely an example of bad coding. The thing is that it is equivalent to the code where SOME_CHARTTYPE6, SOME_CHARTTYPE7, SOME_CHARTTYPE8, SOME_CHARTTYPE9, SOME_CHARTTYPE10
are ommited. I.e. the code can easily look like the following:
switch( dwSomeValue )
{
case SOME_CHARTTYPE1:
case SOME_CHARTTYPE2:
case SOME_CHARTTYPE3:
case SOME_CHARTTYPE4:
case SOME_CHARTTYPE5:
{
//
// Some Code...
//
break;
}
default:
{
//
// Some Other Code...
//
}
}
Igor Proskuriakov
|
|
|
|
|