|
More than meets the eye !!!
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
|
Anyone know of a utility which will let me compare two compiled libraries (not DLLs) and tell me if there are any differences in the actual code (not time stamps, etc.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
Problem with fc is that it catches the changed time stamps inside the library. My kludged solution is to build the entire huge project after the changes and use fc to compare the old and the new executable. This generally works.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I have my fields in a set and I call insertColumn in a loop:
for (int j = 0 ;j < pDoc->m_keySet.size(); j++ , it++)
{
CString& field = *it;
headingWidth = field.GetLength() * 10;
myList.InsertColumn( j,field, LVCFMT_CENTER, headingWidth )
but this isnt good enough because a 3 letter field is only 30 pixels wide --- its not enough, and a 11 letter field with width 110 actually comes out looking good. So short of testing to see if the length is under some minimum, and defaulting to a reasonable width, is there a smarter way to set widths according to field length?
thanks,ns
|
|
|
|
|
Have you tried LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER with SetColumnWidth() ? Another alternative is to call GetStringWidth() and add 10-15 pixels to it.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Ah! Thanks so much! I didnt know there was such a function GetStringWidth! I will use it!\ns
|
|
|
|
|
ANd armed with this info:
I now have a dialog with 5 labels with differing lengths of some CStrings populating them (at runtime). I want to size the dialog to be just as wide as the longest string. SO I am going to put an invisible listCtrl on the dialog and use the getsstringwidth to figure out the largest number of pixels I need and movewindow it... I didnt see anything in CString that would help me......
I wonder if this is the simplest way........it just occurred to me in light of your response ....
Thanks,
ns
|
|
|
|
|
See if the text-related functions of the CDC class help:
GetTextExtent()<br />
GetTabbedTextExtent()<br />
GetOutputTextExtent()<br />
GetOutputTabbedTextExtent()
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
What is the advantage of using a reference over the variable.
Can't you just pass the variable name instead of passing a reference to the variable.
KAI_YPO
|
|
|
|
|
When you pass a variable, a copy of that variable is made. When you pass a reference, the original variable is passed in. This means two things:
1. If the variable is big, you save some effort in making a copy
2. Anything you do to the variable in your function will effect the variable that was passed in
so if you have two functions:
void Inc(int i)
{
++i;
}
and
void IncRef(int & i)
{
++i;
}
In your main code you can do this:
int i = 0;
Inc(i); // i still = 0, because only the i in the function was incremented
IncRef(i); // i now = 1, as this i is the same one that was incremented in the function. Note, the variable names do not need to be the same.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Here's a question though...
Which is more efficient...
void IncRef(int & i)
{
++i;
}
or this...
void IncRef(int i)
{
++i;
}
The way I think about it is we are still passing pointer to another variable in a previous stack frame. Therefore in this case would it make any difference performance wise since we are still just dealing with a number whether it be a memory location or an integer. I know that if this was a pointer I would be correct in this case but I'm not sure about references. Please feedback though I may be wrong.
|
|
|
|
|
In this case, it would only be barely more efficient to pass a reference. It's not just passing a number, it's also allocating and deallocating the memory. But your app won't hang on this, it's more if you have huge data structures that you want to pass into a function to be read ( and this is what keyword 'const' is for ), that you can make some serious gains in efficiency by using references.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'm testing it out and it seems that order of inserting is preserved but I wanted to confirm this:
If I do insertColumn in a CListCtrl, the columns get named in the sequence they were put in. So its more like an addcolumn -- I thought insertcolumn would put it in a certain position -- amybe even sorted somehow. I need 2 columns to always be #1 and 2, and want to be sure that if I just do inserColumn (heading1), then heading2, they will come out in order, regardless of the headings of the rest of the columns..
Also what exactly is a subitem in this context?
int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );
If we are inserting a column number ncol, then what is its subitem? I had thought that the first col was a 'real' column and the rest were subitems. But in InsertColumn i dont know what subitem is. i put in a subitem number nsub = 3 etc in my call:
if( InsertColumn( m_iNumColumns++, strHeading, LVCFMT_CENTER, iWidth ) == -1, nsub )
return FALSE;
but it acted the same as:
if( InsertColumn( m_iNumColumns++, strHeading, LVCFMT_CENTER, iWidth ) == -1 )
return FALSE;
Thanks for the help,
ns
|
|
|
|
|
ns wrote:
I need 2 columns to always be #1 and 2...
Then add them after all other columns have been added.
ns wrote:
...but it acted the same as:
Probably because they are both the same! Notice the placement of nsub . The parameters passed to InsertColumn() are the same, while the condition in the if statement is different.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi, i'm trying to write a multithreaded TCP server and it seemed to work ok now but suddenly i got this assertion error! The thing is, to test the server i connect with the windows 98 telnet application to my server. The clienthandler threads of my server continously check with select() if there is something to read on the socket. This gives me the oportunity to also check if the socket handle is not INVALID_SOCKET, since we might set it to this from somewhere else if we would like to "boot" the client and make sure the thread terminates. I get the assertion error in a number of particular cases, these are the two most common:
When i connect via telnet, type some text, then connect another one, also type some text, and then i close the first one without disconnecting properly, also the server does not see it is disconnected.
Or, when i connect, type some text, close telnet without disconnecting, and reconnect.
After these two situations it always gives me the error "Debug Assertion failed" in dbgheap.c.
This is part of my code:
DWORD WINAPI ClientHandler(void* prms)
{
ClientInfo * clinfo = (struct ClientInfo*)prms;
SOCKET sd = (SOCKET)clinfo->SocketHandle;
char buffer[1024];
int nRead = 0;
BOOL abort = FALSE;
do
{
if(sd!=INVALID_SOCKET && IsSocketReadyToRead(sd,50))
{
nRead = recv(sd, buffer, sizeof(buffer), 0);
if(nRead==0)
{
abort = TRUE;
}
}
}
while(!abort);
RemoveConnection(sd);
return 0;
}
ClientInfo is just a struct with some information about each client (socket handle, thread handle, etc..)
This is what IsSocketReadyToRead() looks like:
BOOL IsSocketReadyToRead(SOCKET s, int timeout)
{
int retval;
fd_set* socketset;
socketset = new fd_set;
FD_ZERO(socketset);
FD_SET(s, socketset);
if( timeout!=0 )
{
struct timeval time;
memset(&time,0,sizeof(struct timeval));
time.tv_sec = 0;
time.tv_usec = (long)timeout;
retval = select( 0, socketset, NULL, NULL, &time );
}
else
{
struct timeval time = { 0, 0 };
retval = select( 0, socketset, NULL, NULL, &time );
}
delete socketset;
switch(retval)
{
case 1:
return TRUE;
break;
case 0:
return FALSE;
break;
case SOCKET_ERROR:
return FALSE;
break;
default:
return FALSE;
}
}
The RemoveConnection function does not matter seeings in neither of the situations it is called.
Does anyone have any idea what might be causing this?
Oh yes btw, i also, at other times, in the same situation, did not get the assertion error, but a memory error where it gave me that "the memory could not be written." and the contents of a pointer. But i don't know if its my app or the underlying framework. Thanks for any help, if you would like to see more code, just ask.
Kuniva
--------------------------------------------
|
|
|
|
|
I'm attempting to load a .jpg file into an MFC project which uses the CRichEditView class. I can use InsertFileAsObject to load a bitmap fine, but when I attempt to load a jpg file it draws a box with the filename instead of embedding the picture itself. Any suggestions?
|
|
|
|
|
It has to do with what program is associated with jpgs. If the associated program does provide OLE containers then all you get is an icon. You can either associate it to a differnt program (IE comes to mind) or convert the jpg to a bitmap and then insert.
--
Joel Lucsy
|
|
|
|
|
Hello all
I coded a window service which creates a lot of tmp files in the course of its operation. I wanted to delete these files once service is stopped. I'm using the following code to do so in destructor function ...
SHFILEOPSTRUCT fs ;
char buff[255];
char tmp[]="\\*\0\0";
sprintf(buff,"%s%s",sWorkingDir,tmp);
int len=strlen(buff);
buff[++len]=NULL;
buff[++len]=NULL;
fs.hwnd = NULL;
fs.wFunc = FO_DELETE ;
fs.pFrom = ( LPCSTR ) buff ;
fs.pTo = NULL;
fs.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
if(SHFileOperation ( &fs ) ==0)
WriteLogData('I',5,"DST","Successfully deleted tmp files");
else
WriteLogData('E',5,"DST","Unable to delete tmp files");
but the above code is not working within windows service. When I used the same code in a standalone application it is working. When I use GetLastError() in service I'm getting value 6( stands for INVALID_HANDLE). Can any one help me in this
Thanks for your help
Hari.
|
|
|
|
|
Could it be that SHFileOperation is considered "interactive" and your service is not allowed to interact with the desktop?
--
Talk to the hand!
|
|
|
|
|
Hello Jorgen
I already selected "interact with desktop" option from service control window.
but it's not working ..
Thanks for the help
Hari.
|
|
|
|
|
Have you also tried running the service as different users? I know the LSA (Local System Account) can be tricky. Especially if you're copying files to/from a non-local drive/shares. IIRC, the LSA account can only operate on local/physical devices.
--
Talk to the hand!
|
|
|
|
|
hi
how can i Transfer a PictureBox picture to an array of bytes?
thanks
|
|
|
|