|
I need to allow users to run more than one instance of my app. Unfortunately I have to use Netbios functions. I have found that my app locks up the entire machine if one instance is deleting the name from the name table at the same time the other one resetting the lanas or adding the name. So I thought I could use a mutex to have the second one wait if the first one is deleting the name. Unfortunately it doesn't seem to work. Here is the code:
CMutex mutex(TRUE, "application name - Stopping or starting network stuff");
CSingleLock lock(&mutex);
lock.Lock();
The first one exectutes this and has not exited the function (so the mutex has not been deleted) when the second one executes this. The second one does not wait.
What am I doing wrong?
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Are you checking the return state of the Lock ?
You might want to have a look at the MUTEXES sample app from MSDN to see how to use CMutex correctly.
|
|
|
|
|
Thanks. I will look at the return value to see if it failed and look at the MSDN sample. The documentation sounded pretty straitforward. I read someone's comments somewhere saying the first version of MFC's critical section class was buggy. So I thought maybe this one is too. So I was hoping to hear from someone who had used it before and could tell me whether or not it worked.
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Actually, my first attempts with it were not successful so I just wrote my own little thing using the Win32 mutex functions. They seemed a bit more straight forward to me. The API functions used are CreateMutex, WaitForSingleObject, ReleaseMutex, and CloseHandle. They are invoked in that order.
My jokes page
|
|
|
|
|
Thanks. I will use that instead.
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
This is one of the strangest things i've seen happen. For some reason my arrays of chars seem to be holding random data that appears out of nowhere time and again..I can't explain it.
for example:
char buff[10];
char obuff[20];
memset(buff, '\0', 10);
memset(obugg, '\0', 20);
mysock.recv(buff, 10);
memcpy(obuff, buff, 10);
What does it all mean?
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
Have you checked if recv() succeeds? I'm not sure what class type your mysock object is, but you should probably be checking a return value. Also, break at the mysock.recv and make sure you arrays are being initialized to 0.
Are you sure your recv isn't succeeding? Just that that's the data you are getting from the socket?
cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
I'm not really sure, but I think it's because you've not reserved any bytes for the null-terminator. If you create 'buff' with a size of 11 bytes (and memset all 11 bytes to zero too), I think it will all work out just fine :]
Sprudling
|
|
|
|
|
Sprudling wrote:
I'm not really sure, but I think it's because you've not reserved any bytes for the null-terminator
That was the problem, thanks Sprudling.
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
Sprudling is close to being right.
C/C++ uses NULL terminated strings. So when you look at a character array in the debugger or printing, if the NULL isn't there, then trash at the end of the string will be displayed.
Like Sprudling said, if you want to use the read data as a C/C++ string, then you need to add an 11th byte and then terminate it. For example:
char buff [11];
char obuff [21];
int n = mysock.recv(buff,10);
buff [n] = 0;
strcpy (obuff,buff);
No if you aren't using the data as real strings, then the NULL isn't at all required and the extra trash is just an annoyance caused by the debugger trying to display the data as a string.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Is there a good way to get the contents of another window?
i.e. Get the handle and BitBlt the contents into a buffer?
Anyhow, we do this, but are looking for more reliable ways to do this.
Specifically, here are some requirements:
1) The "window" is part of another app (any app window)
2) App window may not always be the top window or even completely on-screen.
When the window moves away from being the top window, we start losing part of it's contents due the the clipping regions from other windows or the screen edge....
any clues out there?
Thanks in advance.
|
|
|
|
|
Try giving the window in question focus, then BitBlt.
If it is off the screen get the screen dimension, the x,y, the height and width of the window and check if the window extends beyond the screen then move it and BitBlt.
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
I want to create one function that will be called when ever 1 of 5 static box's are clicked. I also want the ID of which ever static box was clicked to be sent over to that function. I think this would clean up my code instead of having 5 functions, 1 for each static box, that do basically the same thing. I think i have to use a WM_COMMAND thing but i dont really know how to do use it to get the desired effect. Should i just stick with five separate functions or can this be done fairly eaisly?
-Raffi
The truth about C++
|
|
|
|
|
If you the check boxes (I assume that's what you mean by "static" box) have consecutive ids, you can use the ON_COMMAND_RANGE() macro to call the same handler. The handler is passed the id of the control for which it was called. See the doc for details.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
I am trying to create an extended stored procedure using C++ and following the MS guidelines. Within the function GetXpVersion which is recommended by Microsoft to be implemented, the following item is returned:
__declspec(dllexport) ULONG __GetXpVersion()
{
return ODS_VERSION;
}
I have been trying to compile my version and also the sample extended stored proc at CodeProject at http://www.codeproject.com/database/mssqltutorial.asp
but both return the same error:
error C2065: 'ODS_VERSION' : undeclared identifier
Both have the srv.h in their headers and also link with Opends60.lib. They both haveDevtools Lib and Include directories in their path as well. Where is this ODS_VERSION defined?
thanks
|
|
|
|
|
It appears that I have one more trouble.
My code is unable to link with this srv_paraminfo function. when I go through srv.h and its various codes, this function is not there either.
Is there a versioning issue here?
|
|
|
|
|
New version at my website.
This should fix the resource leaks that some people have been reporting.
I'm in the middle of rewriting the help as a compiled help file so that I can reduce the size of the web page (and help everyone with a better reference document ).
When I've finished the doc.s I'll update the article here as well.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
I wrote a program that works fine under 9x, but under NT2, 2k it has font display issues.
When I refresh some on screen data, I set the text of some static windows, and it loses it's font. For instance, I'll have "some text" which I'll SetWindowText() to "some other text" and it comes out in the system font (not "arial" or the parent window's font, but "system") This doesn't happen in 9x - it retains the old font.
How can I go about getting win9x's behavior where it says the same font it was before I set it?
I've tried going back through and setting the font later, but there is noticible flicker. I'm attempting to send WM_SETFONT before changing the text, but I'm getting mixed results.
Many, many thanks in advance.
|
|
|
|
|
hi all
i need to store character strings in two-dimensional array. i have to allocate memory dynamically so can't say char array[10][10][20] if i need to reserve 10X10 matrix for strings of 20 characters each. can someon eplease tell me how to do this using pointers? thanks.
i just know that my strings will be 20 characters. i don't know the number of rows and columns, and that will be provided on runtime.
imran.
|
|
|
|
|
Well guess what... to the compiler it's just a chunk of memory. You'll have to do the math yourself. I suggest drawing a picture (a cube) and figuring out the math yourself. If you work with the linux framebuffer, it's very much the same.
If you still need help, think of what [1][0][0] means, [0][1][0] means, and [0][0][1] means. I forget wich way exactly C lays stuff out (but it is easy to find out yourself)
you'll need to malloc(xdim*ydim*length)
It's the same as a 2 dimentional array, but with one more dimention (the word length)
You can also imagine a long text string. Every 20 chars is a start of a new word. every y of them is a new x row.
I hope that helps.
Oh I almost forgot. You'll calculate something called and offset, then you can do
chunk=malloc(x*y*l);
offset=// left as an excersize for the reader
chunk+offset= (address of a particular character, could be the start of a word too)
*(chunk+offset) = (the character)
printf("%c", *(chunk+offset); //char
or
printf("%s", chunk+offset); // word
|
|
|
|
|
I'll tell you how to do it using STL and the C++ standard library. Much easier than pointers.
#include <vector>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
// create the matrix
const int MAX = 100;
typedef vector<string> StrVec;
vector<StrVec> vv(MAX);
int i, j;
for (i=0; i<MAX; i++)
{
StrVec v(MAX);
vv[i] = v;
}
// store "Foo" in all strings of the matrix
for (i=0; i<MAX; i++)
for (j=0; j<MAX; j++)
vv[i][j] = "Foo";
return 0;
}
CodeGuy
The WTL newsgroup: over 1100 members! Be a part of it. http://groups.yahoo.com/group/wtl
|
|
|
|
|
I was wondering if any knew what these programs that adjust windows to be faster on the net do to your system.
I believe they change registry settings, but I would like to know which ones, can anyone out there help me?
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
Basically they try to tune a TCP parameter called MTU (Maximum Transmission Unit), which has a significant impact on performance under low bandwith conditions. This parameter is stored somewhere in the registry (depends on the platform).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Do you by any chance have any idea what the registry key or value may be called, i tried searching for mtu and didnt get anything.
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
There are a lot of new controls in .Net (like LinkLable,CheckListBox or Panel and ...)
Can I use these controls in VC.Net?
How?
Thanks
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|