|
I fixed the problem using the other reply. Thanks for your attention.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi, I think that Keith Rule's Debugging Release Mode Problems[^] article could help you. Please have a look into it. You maybe trying to access an unallocated pointer.
Regards,
Mihai Moga
|
|
|
|
|
Thanks a lot !!!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
As you know there is no API to get thread current working state (Suspended, running, etc)
I need to check a thread working state. I have ThreadId and ThreadHandle.
I know there is a way to get thread state, but i don't know what it is!
Can anybody help?
http://www.softprojects.org/
modified on Sunday, June 29, 2008 12:45 AM
|
|
|
|
|
|
GetExitCodeThread() will check if the thread is active or not.
You shouldn't be suspending threads so that shouldn't be an issue,
unless you're writing a debugger.
There's no reliable way to get the suspended state - that state
can change at any time. You could use SuspenfThread() and check the
return value. If it returns >= 1 then the thread was already suspended.
Don't forget to call ResumeThread().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: GetExitCodeThread() will check if the thread is active or not.
Thanks, this can help.
Mark Salsbery wrote: There's no reliable way to get the suspended state - that state
can change at any time. You could use SuspenfThread() and check the
return value. If it returns >= 1 then the thread was already suspended.
Don't forget to call ResumeThread().
Good idea , but I don't want to change thread state, and the thread shouldn't suspend even a millisecond.
http://www.softprojects.org/
|
|
|
|
|
If found how to check thread suspended state.
With ResumeThread.
Here MSDN help:
The ResumeThread function checks the suspend count of the subject thread. If the suspend count is zero, the thread is not currently suspended. Otherwise, the subject thread's suspend count is decremented. If the resulting value is zero, then the execution of the subject thread is resumed.
If the return value is zero, the specified thread was not suspended. If the return value is 1, the specified thread was suspended but was restarted. If the return value is greater than 1, the specified thread is still suspended.
|
|
|
|
|
I am having a conceptual problem with a program I want to create. The application will be a galactic simulator. The user will be able to edit and create some number of stars giving them arbitrary values for mass, position, and velocity. The application will calculate how the stars orbit each other and display them on the screen in a 3D format.
The number of stars can vary. I plan to use a linked list to hold all the stars. In this manner, each star object can traverse the entire list and calculate how each other star affects it. Then each star object can calculate where it will be at the end of each simulation step.
I start off by creating a basic dialog driven application using Visual Studio, C++, and static linked MFC. (I am open to suggestions) Then I need to have a place to anchor the linked list of stars. I envision a class whose entire purpose is just to provide the linked list. It will contain the methods to link items into the list and remove them. I can use STL, but the exact implementation is not important.
My problem is: Where and how should I declare and instantiate the object of that list?
Windows applications does not have a main() that sticks around for the life of the application.
For ease of discussion, let us say the list class is named:
CLinkedList
and the object instantiated will be:
ListAnchor.
The objects contained in the list will be of class:
CStar
and will be created thusly:
CStar new_star = new( CStar );
To put the new star in the list I envision writing a line of code that looks something like:
ListAnchor.LinkNewStar( new_star );
Or maybe
ListAnchor->LinkNewStar( new_star );
When I create my new Windows dialog application the name will be StarSimulator and Windows will create StarSimulator.h, StarSimulator.cpp, StarSimulatorDlg.h, StarSimulatorDlg.cpp and a host of other support files. I don't think anyone wants me to post any of those files. Assume the standard environment for Visual Studio 2008 running on Windows XP and using C++.
Where and how should I declare and instantiate this object ListAnchor?
If my entire approach is wrong, please advise.
Thanks for your time
|
|
|
|
|
Hint, see MFC 's theApp variable of your application.
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]
|
|
|
|
|
Hello Pallini,
I think I am working now.
I went into the .h file and just below theApp added:
extern Ctest1App theApp;
extern CGalacticEndPoints ListAnchor;
Note: I am on another version trying to get things working and changed some names)
Then in the .cpp file, again just under theApp I added:
Ctest1App theApp;
CGalacticEndPoints ListAnchor;
And finally, in the class that creates the new star objects I added:
CGalacticBody *new_body = new( CGalacticBody);
ListAnchor.Link_New_Body( new_body );
And to my joy, it not only compiled, it linked, then when I stepped through the debugger, it put my new object in the list.
That just did not strike me as the right place.
Thank you for your help.
Thanks for your time
|
|
|
|
|
That's two global variables.
I personally prefer to only have the one app global variable.
Any other object that is application-wide ("global") can be added to the
app class and accessed through the one global app object instead of adding
another global variable.
Just a thought
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark said: That's two global variables.
I am not understanding that.
If I comment out the line in the .h file, then the functions that reference this object don’t know about it and compile with an undeclared identifier.
If I comment out the line in the cpp file, the link fails with unresolved external symbol.
If the code in my previous post generates two global variables, what is the full name of each? What lines of code would you write?
Thanks for your time
|
|
|
|
|
bkelly13 wrote: If the code in my previous post generates two global variables, what is the full name of each?
theApp and ListAnchor.
bkelly13 wrote: What lines of code would you write?
I meant something like the following - one global variable (theApp):
#pragme once
#include "GalacticEndPoints.h"
class Ctest1App : public CWinApp
{
protected:
CGalacticEndPoints ListAnchor;
public:
CGalacticEndPoints &GetListAnchor() {return ListAnchor;}
};
extern Ctest1App theApp;
#include "stdafx.h"
#include "test1App.h"
Ctest1App theApp;
...
#include "stdafx.h"
#include "somemodule.h"
#include "test1App.h"
...
CGalacticBody *new_body = new( CGalacticBody);
theApp.GetListAnchor().Link_New_Body( new_body );
...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello friends~
I have some questions about MFC.
During I wrote the code, the error was occuring about this.
I use Visual studio 2005. I found many imformation. It's not occur at Visual studio 6.0.
And I use UNICODE.
Plz, help me. I didn't resolve this for 1 hour.
I found MSDN, and Search many sites, but I didn't resolve.
It doesn't not work.
fp = fopen(pDlg.GetPathName(), _T("r"));
fp = fopen(pDlg.GetPathName(), _T("rb"));
//////////////////////////////////////////
FILE *fp;
fp = fopen(pDlg.GetPathName(), "r");
//////////////////////////////////////////
FILE *fp;
fp = fopen(pDlg.GetPathName(), "w");
//////////////////////////////////////////
------ Build started: Project: MFC_4_2, Configuration: Debug Win32 ------
Compiling...
MFC_4_2Dlg.cpp
d:\data\programing\c++\sc\mfc\mfc_4_2\mfc_4_2dlg.cpp(238) : error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
d:\data\programing\c++\sc\mfc\mfc_4_2\mfc_4_2dlg.cpp(261) : error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Build log was saved at "file://d:\Data\Programing\C++\sc\MFC\MFC_4_2\Debug\BuildLog.htm"
MFC_4_2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Use _tfopen , for instance:
FILE *fp;
fp = _tfopen(pDlg.GetPathName(), _T("r"));
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]
|
|
|
|
|
Thanks for your help...
But Another error is occured.
I don't know why this error was occured.
Actually, I found the solution but this error was occured.
Do you know why this error occur ??
------ Build started: Project: MFC_4_2, Configuration: Debug Win32 ------
Linking...
MFC_4_2Dlg.obj : error LNK2001: unresolved external symbol "protected: virtual struct AFX_MSGMAP const * __thiscall CAboutDlg::GetMessageMap(void)const " (?GetMessageMap@CAboutDlg@@MBEPBUAFX_MSGMAP@@XZ)
D:\Data\Programing\C++\sc\MFC\MFC_4_2\Debug\MFC_4_2.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://d:\Data\Programing\C++\sc\MFC\MFC_4_2\Debug\BuildLog.htm"
MFC_4_2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Hi, this is a linking problem. You are trying to access CAboutDlg::GetMessageMap witch is not have been implemented. Try defined it and you will get reed of this compiler error message.
Regards,
Mihai Moga
|
|
|
|
|
Thanks for your help...
but I didn't understand your message.
How to define it ??
My CAboutDlg source is added.
plz check this.
i'm spend time for 2 days about this. help me.
//////////////////////////////////////////////////////////////////////////////////
// MFC_4_2Dlg.cpp
//
#include "stdafx.h"
#include "MFC_4_2.h"
#include "MFC_4_2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV
protected:
DECLARE_MESSAGE_MAP()
public:
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
// CMFC_4_2Dlg
CMFC_4_2Dlg::CMFC_4_2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMFC_4_2Dlg::IDD, pParent)
, m_strProdName(_T(""))
, m_strProdCode(_T(""))
, m_UnitCost(0)
, m_nQuantity(0)
, m_nTotalCost(0)
, m_strInfo(_T(""))
, m_bCodeViewed(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bCodeViewed = FALSE;
}
void CMFC_4_2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_NAME, m_strProdName);
DDX_Text(pDX, IDC_EDIT_CODE, m_strProdCode);
DDX_Text(pDX, IDC_EDIT_UNIT_COST, m_UnitCost);
DDX_Text(pDX, IDC_EDIT_QUANTITY, m_nQuantity);
DDX_Text(pDX, IDC_EDIT_TOTAL_COST, m_nTotalCost);
DDX_Text(pDX, IDC_EDIT_INFO, m_strInfo);
}
BEGIN_MESSAGE_MAP(CMFC_4_2Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT_NAME, &CMFC_4_2Dlg::OnEnChangeEditName)
ON_EN_CHANGE(IDC_EDIT_CODE, &CMFC_4_2Dlg::OnEnChangeEditCode)
ON_EN_CHANGE(IDC_EDIT_UNIT_COST, &CMFC_4_2Dlg::OnEnChangeEditUnitCost)
ON_EN_CHANGE(IDC_EDIT_QUANTITY, &CMFC_4_2Dlg::OnEnChangeEditQuantity)
ON_BN_CLICKED(IDC_SAVE, &CMFC_4_2Dlg::OnBnClickedSave)
ON_BN_CLICKED(IDC_OPEN, &CMFC_4_2Dlg::OnBnClickedOpen)
ON_BN_CLICKED(IDC_VIEW, &CMFC_4_2Dlg::OnBnClickedView)
END_MESSAGE_MAP()
// CMFC_4_2Dlg
BOOL CMFC_4_2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMFC_4_2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMFC_4_2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CMFC_4_2Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMFC_4_2Dlg::UpdateStockInfo(void)
{
UpdateData(TRUE);
m_nTotalCost = m_UnitCost * m_nQuantity;
m_strInfo.Format(_T("name : %s \r\n\r\n code : %s \r\n\r\n price : %d \r\n\r\n amount : %d \r\n\r\n total : %d \r\n\r\n"),m_strProdName, m_strProdCode, m_UnitCost, m_nQuantity, m_nTotalCost);
UpdateData(FALSE);
}
void CMFC_4_2Dlg::OnEnChangeEditName()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateStockInfo();
}
void CMFC_4_2Dlg::OnEnChangeEditCode()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateStockInfo();
}
void CMFC_4_2Dlg::OnEnChangeEditUnitCost()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateStockInfo();
}
void CMFC_4_2Dlg::OnEnChangeEditQuantity()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateStockInfo();
}
void CMFC_4_2Dlg::OnBnClickedSave()
{
// TODO: Add your control notification handler code here
char Filter[] = "p42 File(*.p42) | *.p42 | All(*.*) | *.* |";
CFileDialog pDlg(FALSE, _T("p42 file(*.p42)"), _T("*.p42"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, (LPCTSTR)Filter, NULL);
UpdateData(TRUE);
if(!m_strProdName.IsEmpty() && !m_strProdCode.IsEmpty() && (m_UnitCost >0) && (m_nQuantity > 0) && (m_nTotalCost > 0))
{
if(pDlg.DoModal() == IDOK)
{
FILE *fp;
// fp = _tfopen(pDlg.GetPathName(), _T("w"));
fp = fopen(pDlg.GetPathName(), _T("w"));
fprintf(fp, "%s\n%s\n%d\n%d\n%d", m_strProdName, m_strProdCode, m_UnitCost, m_nQuantity, m_nTotalCost);
fclose(fp);
}
}
else
{
AfxMessageBox(_T("input your imformation : "));
}
}
void CMFC_4_2Dlg::OnBnClickedOpen()
{
// TODO: Add your control notification handler code here
char Filter[] = "p42 File(*.p42) | *.p42 | All(*.*) | *.* |";
CFileDialog pDlg(TRUE, _T("p42 file(*.p42)"), _T("*.p42"), OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, (LPCTSTR)Filter, NULL);
if(pDlg.DoModal() == IDOK)
{
FILE *fp;
// fp = _tfopen(pDlg.GetPathName(), _T("r"));
fp = fopen(pDlg.GetPathName(), _T("r"));
fscanf(fp, "%s\n", m_strProdName);
fscanf(fp, "%s\n", m_strProdCode);
fscanf(fp, "%d\n%d\n%d", &m_UnitCost, &m_nQuantity, &m_nTotalCost);
UpdateData(FALSE);
UpdateStockInfo();
fclose(fp);
}
}
void CMFC_4_2Dlg::OnBnClickedView()
{
// TODO: Add your control notification handler code here
if(!m_bCodeViewed)
{
m_dlgCodeTable.Create(IDD_DIALOG_CODETABLE, this);
CRect rectMain, rectCodeTable;
GetWindowRect(&rectMain);
m_dlgCodeTable.GetWindowRect(&rectCodeTable);
m_dlgCodeTable.MoveWindow(rectMain.right, rectMain.top, rectMain.Width(), rectMain.Height());
m_dlgCodeTable.ShowWindow(SW_SHOW);
m_bCodeViewed = TRUE;
}
else
{
m_dlgCodeTable.ShowWindow(SW_HIDE);
m_dlgCodeTable.DestroyWindow();
m_bCodeViewed = FALSE;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
Hi!
I'm developing an app that should capture stream from a webcam, capture audio, mux it in a FLV(maybe other container, e.g. mp4) and then stream it over a network. As I found in MS SDK, I can do it using a DirectShow, but the only option I have is to write a muxed stream to a file. So is there any options to write it to a memory buffer for furhter writing to a socket?
Ofcourse there are some tricks like a continuous reading from a muxed file, but it looks too ugly.
Another question is - can I split icoming muxed stream into frames? I mean if I have a 24 fps live source, is it possible to capture a muxed frame (audio + video), so I could drop some frames in case there is a really bad latency.
Thanks in advance!
|
|
|
|
|
If you want to write your own communication code, you can use custom DirectShow filters to
access the streams.
Real time multimedia streaming is no simple task. The most difficult issues IMO are dealing
with jitter and clock drift.
The Windows Media Format SDK has the ability to stream over a network and it integrates with
DirectShow relatively easily. There are some issues there. First, by definition, it works
mostly with Windows Media Format (ASF) streams. Second, there's no low-latency audio codecs
suitable for real-time communications (low latency/low bandwidth).
Ethemind wrote: can I split icoming muxed stream into frames? I mean if I have a 24 fps live source, is it possible to capture a muxed frame (audio + video), so I could drop some frames in case there is a really bad latency.
You have no choice. To deal with jitter and clock drift, you'll HAVE to add/remove samples in realtime to keep
everything in sync.
Just my 2 cents,
Mark
|
|
|
|
|
Hi,
I am createing new ListBox on dialog box at runtime.
it's creating fine but I want to handle the events over that.
I want to Handle event as
ON_LBN_SELCHANGE(IDC_PREVIEW_LIST, OnSelchangeList)
in message map.
but id IDC_PREVIEW_LIST is passed by me at run time in as
CListBox m_PreviewList;
m_PreviewList.Create(WS_CHILD|LVS_ICON|WS_VISIBLE|WS_BORDER|LBS_OWNERDRAWFIXED|LBS_MULTICOLUMN, rect, this, IDC_PREVIEW_LIST);
and it's not know in messge map.
So please guid me how to handle dynamically created window events.
|
|
|
|
|
|
Please can you explain with simple code?
|
|
|
|
|
Handling events of dynamically created controls are not that hard. It should work. Please ensure that IDC_PREVIEW_LIST is #define-d in some header file and included in this source file.
Do more work
Make more mistakes
Learn more things
|
|
|
|
|