|
This is the current code that is used before access to any data.
<big>bool CTestGUI1Dlg::WaitForMutex(void)<br />
{<br />
<br />
<br />
m_hMutex = ::CreateMutex( NULL,<br />
FALSE,<br />
"CSLSharedMemLock"<br />
);<br />
<br />
if(m_hMutex)<br />
{<br />
if (::WaitForSingleObject(m_hMutex,INFINITE) == WAIT_OBJECT_0)<br />
{<br />
ReleaseMutex(m_hMutex);<br />
return true;<br />
}<br />
}<br />
return false;<br />
}</big>
Note that currently I create it each time. If I dont then I never return.
If I now create the Mutex in the InitDialog() section of the program and modify the WaitForMutex as follows I get error = 6
<big><br />
bool CTestGUI1Dlg::WaitForMutex(void)<br />
{<br />
<br />
<br />
<br />
if(m_hMutex)<br />
{<br />
if (::WaitForSingleObject(m_hMutex,300) == WAIT_OBJECT_0)<br />
{<br />
ReleaseMutex(m_hMutex);<br />
return true;<br />
}<br />
}<br />
int error = GetLastError();<br />
return false;<br />
}</big>
|
|
|
|
|
Yeah that error indicates an invalid handle. Try creating (openning of already exist) the mutex in the constructor.
Kuphryn
|
|
|
|
|
I create the Mutex in the InitDialog() function, where do you suggest Create/Open the Mutex.
Also in the libray (DLL) is a native C library with no constructor.
One other thought, do I need Mutex to protect the shared memory as the EXE is single threaded and only one will ever exist.
grahamfff
|
|
|
|
|
I need to browse a folder only for rtf files, i'm not interested in other files like image,etc.How can i do this?and also i need to search for a specific folder, not file like My Documents,in order to get the path.SHGetFolderLocation( or something like this) doesn't work.How can i do this?Thanks a lot.
|
|
|
|
|
I need to browse a folder only for rtf files, i'm not interested in other files like image,etc.
>
static char BASED_CODE szFilter[] = "RTF Files (*.rtf)|*.rtf||";<br />
CFileDialog BrowseDlg(TRUE,NULL,NULL,OFN_FILEMUSTEXIST,szFilter,NULL); <br />
BrowseDlg.DoModal();
|
|
|
|
|
Add before DoModal something like this:
BrowseDlg.m_ofn.lpstrInitialDir = "c:\\windows"; // choice your path
|
|
|
|
|
I'm sorry.I have forgotten to say that i need this in SHBrowseForFolder.I need to browse only for rtf files.
|
|
|
|
|
Hi all, i dont get it, heres some "sample" code to explain my problem:
const int SOME_INT = 100; // notice the "const" at the start
int num=0;
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
// whatever
};
gives me: error C2051: case expression not constant.
BUT:
#define SOME_INT 100; // using define instead
int num=0;
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
// whatever
};
Gives me no trouble! WTF???? "case expression not constant"???? isnt SOME_INT clearly defined as constant in the first case??
|
|
|
|
|
shouldn't this be:
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
};
Cheers,
Andy
|
|
|
|
|
Sorry, the ":" after case is a mistake i made while writting the post ( edited the post and corrected it now), but even without it, if you try to compile the code you wrote, and assuming you declared SOME_INT as
const int SOME_INT = 0;
it will give you the error, but if you declare it like:
#define SOME_INT 0
then it will work fine.
any idea why?
|
|
|
|
|
AndyQ wrote:
still classed as a variable (albeit a const).
Contradictory statement.
A variable cannot be constant and neither can a contant be variable.
Bikram Singh
|
|
|
|
|
Are you using VC6? Because it compiles just fine in VC.NET2003 (once the default case is filled in).
According to the standards, it should work, so either your compiler is breaking the standards, or what you've posted isn't quite the same as what you've been trying to compile.
|
|
|
|
|
Curi0us_George wrote:
According to the standards, it should work
Yes it should, but with Microsoft, there's no more standard... they implement their compiler how they like...
TOXCCT >>> GEII power
|
|
|
|
|
Actually, I'm pretty sure that VC.NET2003 is as compliant with the standards as GCC.
|
|
|
|
|
As much as I hate quoting Joan Rivers, oh grow up.
Software Zen: delete this;
|
|
|
|
|
Heres the REAL deal
in a file (appconsts.cpp)
#include "appconsts.h"<br />
const int COLID_PLV_NAME = 0<br />
const int COLID_PLV_PHONE = 1<br />
const int COLID_PLV_REP = 2
and in another file (appconsts.h) wich is included everywhere...
extern const int COLID_PLV_NAME;<br />
extern const int COLID_PLV_PHONE;<br />
extern const int COLID_PLV_REP;
and finally, in the LVN_COLUMNCLICK handler of one of my views (appconsts.h included here of course)...
switch(ColIdx)<br />
{<br />
case COLID_PLV_NAME:<br />
break;<br />
case COLID_PLV_PHONE:<br />
break;<br />
case COLID_PLV_REP:<br />
break;<br />
default:<br />
return 0;
} Looks right no?, but it gives me...
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(204) : error C2051: case expression not constant
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(207) : error C2051: case expression not constant
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(210) : error C2051: case expression not constant
i just dont get it!
|
|
|
|
|
The case expression must be constant at compile time. The circumstances you've described do not let the compiler know the value of the case expressions until link time.
Software Zen: delete this;
|
|
|
|
|
how do i get the text from a combobox ?
i.e. not in drop down list / what the user types in
(and it is not m_combo.GetLBText(-1, strTemp); )
|
|
|
|
|
nevermind all,
got it done thru:
<br />
GetDlgItemText(IDC_MYCOMBO, strTemp);<br />
|
|
|
|
|
go to Class Wizard and associate the control with category of Value and of Type CString,
then through the DDX, you can:
UpdateData();
m_strCombo1;
|
|
|
|
|
I'm trying to new a struct, which works fine, but if I view the members of that struct in the watch window the values appear as
I've also tryed a malloc on the struct, but that has the same effect.
Any one got any ideas?
Cheers.
James.
|
|
|
|
|
Hello!! I need some help from you.
Is there any unic number that identify a PC (server or workstation?
In this case, how can I get it from my VC++ app? and is posible execute this function in a PC #1 and get it from a PC #2.
Many thanks in advance
Xavier
|
|
|
|
|
The obvious choice would be the IP address.
If you know the name of the machine then just call:
gethostbyname
Here's the link to MSDN
Hope this helps,
Andy
|
|
|
|
|
As to sending and receiving ip address or hostname - you need to use sockets.
(just see MSDN. You can find it by socket, recv, send, connect, listen etc. functions)
However, that requires a server part of your program running remotely.
|
|
|
|
|
Sorry for reposting this, but I thought I may get some help now that it's the weekend...
I have now undertaken rewriting the serial portion of my code to use CreateFile and the like. It's all a bit complicated though, and being new to this, I have a few questions. It starts with overlapping, and also involves WaitCommEvent and GetCommMask. I did a search on the topics and read a few articles that were found, but while they cleared a few things up, they still left me with a few questions unanswered.
First, I understand that SetCommMask allows you to screen for only a few of the events. But after calling SetCommMask to look for only what you want, how does one screen for these events and process them appropriately? I know you can use WaitCommEvent, but in that case, why would you even need GetCommMask? I also need to use overlapping for this program, but I'm not sure how to implement it or even what it actually is (do I need to use the overlapped structure at all?).
I was able to find this piece of example code on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring_communications_events.asp
I do not fully understand how it operates, though.
Also, this article was very helpful, to a point: http://www.codeproject.com/system/serial_com.asp
Where I got lost was the huge block of code where he uses the OVERLAPPED structure and the Threadfn function, after which he writes "If you understood the above code , you will understand the whole of this article and the source code provided." Gulp. Basically, I have trouble understanding what he does there and where that overlapped structure comes into play.
As always, the help is very much appreciated.
|
|
|
|