|
Only if you hang mistletoe over it and twirl a dead cat three times at midnight.
Yes a global instance of a class that stores that stuff is just fine. Globals are a bad idea, only when misused. That is, when they are used simply to avoid keeping track of the scope of variables.
Your application is exactly what globals are invented for.
|
|
|
|
|
Ahh, ok, I have not created a 'resource holder' class that holds objects for all my resource. I then call a function on this class when I want a handle to whatever bitmap. It now seems to work quite well.
One thing I did notice though it I can't load the resources until my Application class has contructed, so I have to put a small check in their to load the resource the first time I access one. I suppose I could call a 'create' type function from the Application class, but this way I benefit from delaying the loading of resources until I need them.
|
|
|
|
|
Hello,
In my application, it would be most convenient for a CDocument method to send a message to a DialogBar to update it's UI with the latest Document values (Document values are updated by a second DialogBar). My question is (A) Although this may not be the best OO design, is this "OK"? and (B) What's the best way to implement this? (detailed code not necessary).
Thanks!
JennyP
|
|
|
|
|
You may consider overriding CDialogBar::OnUpdateCmdUI or adding UPDATE_CMD_UI for particular controls.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz is right! Just use UPDATE_CMD_UI macro, you won't have to send message to your dialog
bar. The document needs to update only its view(s). The frame window should take care about
updating the dialog bar, menus, etc..
VOTD:"5. The Lord loves righteousness and justice;
the Earth is full of his unfailing love. "-Psalm 33:5
|
|
|
|
|
I have a handful of applications that I am working with, and depending on which of them has created a named mutex, that application is brought to the front when another application is run. The named mutex is shared amoungst all applications.
So, if application A is running and creates a named mutex 'my_mutex', when application is started is checks to see if there is already a named mutex of 'my_mutex'. If there is, then application B brings A to the front, and application B is terminated.
What I am having a hard time with is finding a way to get a handle to the application that has created the mutex - sometimes it is B that is running and has created the mutex, and A is the one that gets terminated. I had been using CWnd::FindWindow(), but that implies I know the name of the application with the mutex, which I do not know.
Any ideas on how to tackle this problem?
: Dean 'Karnatos' Michaud
|
|
|
|
|
See MSDN article Q109175. It has two points that may help you:
1) Using Window class to search for window
2) Activating the window in other application.
|
|
|
|
|
I've got a thread to receive data from the network using Winsock 1.1. In the thread is a while loop which waits for single object for the thread exit event which is used to shut down all threads in the app. That works fine for the other threads.
Of course, I do a WaitForSingleObject with timeout set to zero so that I don't take significant time in waiting for a thread exit (stop) event. Then this WaitFor is followed by a recvfrom() which of course is blocking.
I know what is happening. I am sending the terminate event when the thread is waiting/blocking for data to be received from the network and so it doesn't see it.
I think I know one solution but was wondering if you guys knew another. The solution I know would be to use Winsock 2.0 and set socket options via setsockopt() with the SO_RCVTIMEO (receive timeout set to zero or non-blocking). Actually, I now noticed that using "select" you can pass a timeval structure for timeouts too. Is that the only ways I can accomplish this or is there another way to shutdown this thread gracefully for Winsock 1.1? I'm also not sure that if I go that route whether I have to worry about some sort of overlapped programming or not.
|
|
|
|
|
If your thread is waiting on a socket. You may want to close the socket in question, this will force the function to fail but don't kill a thread unless this is really necessary.
Try with the following function:
DWORD ReadSocket(SOCKET s, LPBYTE lpBuffer, DWORD dwMaxSize, DWORD dwTimeout , SOCKADDR_IN* pAddrIn )
{
fd_set fdRead = { 0 };
TIMEVAL stTime;
TIMEVAL *pstTime = NULL;
if ( INFINITE != dwTimeout ) {
stTime.tv_sec = 0;
stTime.tv_usec = dwTimeout*1000;
pstTime = &stTime;
}
if ( !FD_ISSET( s, &fdRead ) )
FD_SET( s, &fdRead );
DWORD dwBytesRead = 0L;
int res = select( s+1, &fdRead, NULL, NULL, pstTime );
if ( res > 0)
{
res = recvfrom( s, (LPSTR)lpBuffer, dwMaxSize, 0, pAddrIn, sizeof(SOCKADDR_IN));
dwBytesRead = (DWORD)((res > 0)?(res) : (-1));
}
return dwBytesRead;
}
VOTD:"5. The Lord loves righteousness and justice;
the Earth is full of his unfailing love. "-Psalm 33:5
|
|
|
|
|
When you want to shut down, have one of your other threads (the main thread, for instance) close the socket. This will cause the blocked recv() to fail, and unblock.
|
|
|
|
|
Thanks for the suggestions, guys! I'll give the "closesocket" a try. That appears to be a neat trick.
|
|
|
|
|
Hi,
do you have an idea what is wrong?
MyProj error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::ConvertStringToBSTR(char const *)" (?ConvertStringToBSTR@_com_util@@YGPA_WPBD@Z) referenced in function "public: __thiscall _bstr_t::Data_t::Data_t(char const *)" (??0Data_t@_bstr_t@@QAE@PBD@Z)
MyProj error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)" (?ConvertBSTRToString@_com_util@@YGPADPA_W@Z) referenced in function "public: char const * __thiscall _bstr_t::Data_t::GetString(void)const " (?GetString@Data_t@_bstr_t@@QBEPBDXZ)
Thanks
R.
|
|
|
|
|
Add comsupp.lib in the linker tab of project settings dialog.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
On
Project/Properties/Linker/Input/Additional dependencies
I added comsupp.lib but the same error persists
Actually, I am brand new to VS.NET, so I might be wrong.
R.
|
|
|
|
|
Have no idea where can you set the libraries in VS.NET - I'm still using VC6. Look for a field with number of other .libs, like kernel32.lib.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Originally I successfully compiled this code with the .NET default settings, among others with the default char set MBCS. Then I played with the settings, switched to UNICODE, after which I got a ton of linker errors, and then returned to MBCS. And these two errors came.
I have no idea...
R.
|
|
|
|
|
I want to display the 2 fields of all records in a table in listbox.
my program is crshing. i dont know why. can someone help me?
here is the code snippets..
BOOL CMgen1Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
if(m_mgen1Set == NULL) {
m_mgen1Set = new CMgen1Set(&m_database);
CString strConnect = m_mgen1Set->GetDefaultConnect();
m_database.Open(NULL, FALSE, FALSE, strConnect, FALSE);
}
return TRUE;
}
void CMgen1View::OnInitialUpdate()
{
m_pSet = GetDocument()->m_mgen1Set;
CRecordView::OnInitialUpdate();
LoadListbox();
}
void CMgen1View::LoadListbox()
{
CMgen1Doc* pDoc = GetDocument();
CListBox* pLB = (CListBox*) GetDlgItem(IDC_LIST1);
CMgen1Set sect(&pDoc->m_database);
sect.Open();
while(!sect.IsEOF()) {
pLB->AddString(sect.m_CourseID + " " + sect.m_SectionNo);
sect.MoveNext();
}
}
|
|
|
|
|
Usual questions:
What do you mean by crashing? (e.g. Asserting in DEBUG mode, Gets Access violation etc.)
Where is the program crashing? (Stepping through your code, what line is it executing when it "crashes"
Are there any error indications? (ASSERT dialog, TRACE output, GPF dialog etc.)
I don't see anything wrong with the code you presented off hand, but I won't look at it very closely until I know what I am looking for.
|
|
|
|
|
This is the message in the box:
This program has performed an illegal operation and will be shutdown.
If the problem persists contact the vendor.
If I click the Details button i see the following msg:
MGEN1 caused an invalid page fault in
module <unknown> at 00f9:000615c9.
When I step through the code, I am getting an 'Unhandled exception' in this CRecordView::OnInitialUpdate(); line of code.
void CMgen1View::OnInitialUpdate()
{
m_pSet = GetDocument()->m_mgen1Set;
CRecordView::OnInitialUpdate();
LoadListbox();
}
|
|
|
|
|
Hello!
You cannot call the 'GetDocument()' function of a view before you call 'CRecordView::OnInitialUpdate()'. Your program crashes because GetDocument() does not know what to return.
Let me quickly explain. The CRecordView::OnInitialUpdate function hooks your view into the document, so that you can always retreive the associated document with GetDocument(). If you try and call GetDocument() before that, it will probably return NULL, giving you an 'Unhandled exception' (trying to access something in a NULL pointer).
So, you code should look something like this (minus the comments, of course, which just explain what I'm doing):
void CMgen1View::OnInitialUpdate()
{
CRecordView::OnInitialUpdate();
m_pSet = GetDocument()->m_mgen1Set;
LoadListbox();
}
Hope that helps!
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
Hi All,
Can anyone tell me what should be done to provide the resize option to user for modeless dialog
Thanks in advance
Uday
|
|
|
|
|
|
I'm trying to enumerate all the different formats of a specific driver but acmFormatEnum keeps returning MMSYSERR_INVALPARAM (At least one parameter is invalid.). Anyone have an example of how to do this? Here's my code (id is a valid driver identifier of a driver):
ACMFORMATTAGDETAILS acmTagDetails;
<br>
void StartEnum()
{
HACMDRIVER hAcm;
acmDriverOpen(&hAcm, id, 0);
acmTagDetails.cbStruct = sizeof(ACMFORMATTAGDETAILS);
acmFormatTagEnum(hAcm, &acmTagDetails, acmTagCallback, NULL, 0);
acmDriverClose(hAcm, 0);
}
<br>
BOOL WINAPI acmTagCallback(HACMDRIVERID hadid, LPACMFORMATTAGDETAILS paftd, DWORD dwInstance,DWORD fdwSupport)
{
ACMFORMATDETAILS acmFormat;
HACMDRIVER hAcm;
memset(&acmFormat, 0, sizeof acmFormat);
acmFormat.cbStruct = sizeof(ACMFORMATDETAILS);
acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &acmFormat.cbwfx);
acmFormat.pwfx = (WAVEFORMATEX *)malloc(acmFormat.cbwfx);
acmDriverOpen(&hAcm, hadid, 0);
acmFormatEnum(hAcm, &acmFormat, formatCallback, NULL, ACM_FORMATENUMF_WFORMATTAG);
acmDriverClose(hAcm, 0);
return TRUE;
}
<br>
BOOL WINAPI formatCallback(HACMDRIVERID hadid, LPACMFORMATDETAILS pafd, DWORD dwInstance, DWORD fdwSupport)
{
ACMDRIVERDETAILS details;
details.cbStruct = sizeof(details);
acmDriverDetails(hadid, &details, NULL);
SendMessage(GetDlgItem(ghWnd, IDC_FORMATS), LB_INSERTSTRING, 0, (LPARAM)details.szLongName);
return TRUE;
}
Thanks for your help!
-Rune Svendsen
|
|
|
|
|
You have to many members not initialized in acmTagCallback. MSDN says that for ACM_FORMATENUMF_WFORMATTAG , you must initialized dwFormatTag member of the ACMFORMATDETAILS structure must be equal to the wFormatTag member of WAVEFORMATEX. By the way, you need to free the memory you allocate with malloc or you may want to use a local variable : WAVEFORMATEX waveFormat = { 0 } ; and assign it to acmFormat.pwfx = &wafeFormat ; You still need to initialize wafeFormat with the format that you are looking
for. An 8Khz, 8-bit, 1 channel may be your starting point. Sorry if I don't have code to show you right now!
Good luck
VOTD:"5. The Lord loves righteousness and justice;
the Earth is full of his unfailing love. "-Psalm 33:5
|
|
|
|
|
Try to initialize your WAVEFORMATEX struct with this function:
void InitFormat(LPWAVEFORMATEX pwfx, WORD wChannel, DWORD dwSamplesPerSec, WORD wBitsPerSample)
{
_ASSERTE( NULL != pwfx );
pwfx->cbSize = sizeof(WAVEFORMATEX);
pwfx->wFormatTag = WAVE_FORMAT_PCM;
pwfx->nChannels = wChannel;
pwfx->nSamplesPerSec = dwSamplesPerSec;
pwfx->nAvgBytesPerSec = dwSamplesPerSec * wChannel * (wBitsPerSample>>3);
pwfx->wBitsPerSample = wBitsPerSample;
pwfx->nBlockAlign = wChannel * (wBitsPerSample>>3);
}
VOTD:"5 I know that the Lord is great, that our Lord is greater than all gods.
6 The Lord does whatever pleases him, in the heavens and on the earth, in the seas and all their depths."- Psalm 135:5-6
|
|
|
|
|