|
Thanks, Paul! That may just be the ticket! I need to create a separate exe anyhow, to automate serial number creation in the first place, so this should work nicely.
Thanks again!
|
|
|
|
|
I am writing an application that needs the mac address of a remote computer. I have tried the SendArp function, but it does not return the whole mac address when I try to retrieve it for any computer other than my own local ip. For example, I use the SendArp function with my local computer ip and it returns 00-00-83-44-60-79. If I use it with a remote computer on the domain, it returns 10-40-00-00-83-44, which 00-00-83-44 is the correct start of the mac address, but it is missing the end of it. I think that might have to do with the fact that it is a token-ring network. However, if I run nbtstat -a {Computer Name} at the command prompt, I get the correct mac address. I have also tried the following:
LPSTR cmp_name = {Computer Name};
WKSTA_TRANSPORT_INFO_0 *pwkti;
DWORD dwEntriesRead;
DWORD dwTotalEntries;
LPWKSTA_USER_INFO_0 pbBuffer;
NET_API_STATUS dwStatus = NetWkstaTransportEnum(cmp_name, 0, (LPBYTE *)&pbBuffer, buffer,
MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, NULL);
If I set cmp_name = NULL, it returns the correct mac address for my local computer. But if I set cmp_name to a valid computer name, pbBuffer becomes an invalid pointer.
Does anyone know how I can get the correct mac address on a token-ring network? Thanks a lot.
|
|
|
|
|
See my reply here.
smbecker wrote:
But if I set cmp_name to a valid computer name, pbBuffer becomes an invalid pointer.
And the return value is what?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I've been looking through Win api can't find anything. I'm looking through WMI - might have some luck. Does anyone know anything about a way of getting the lid closed event on a laptop computer?
|
|
|
|
|
Unless a power scheme is in use, I don't know of a way. Take a look at the GLOBAL_USER_POWER_POLICY and SYSTEM_POWER_POLICY structures. They both have a POWER_ACTION_POLICY member that defines the action to take when the system's lid is closed.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Do I pay a penalty for having many mutexes? I am designing a C++ class library and want to set a lock on each object. That is, one CMutex per object and several hundreds of objects (potentially), where only a small number of mutexes will be locked at the same time.
I somehow think this might not be a good idea, but maybe I am too pessimistic. Will this work, or will the sheer presence of a large number of mutexes bring Windows to a grainding hold?
TIA,
Bernd
|
|
|
|
|
A mutex has some kernel data structure associated, so you are "eating up" some ressources. However, if this comes from the nonpaged pool (which is limited) I don't know.
But from my understanding, just habving them "hanging around" will not cost you addditional CPU time.
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
Thanks for your input. I am not so worried about CPU time as I am about system resources. I might be able to use critical sections instead of mutexes (don't need inter-process locking), that should be better in terms of system burden, right?
|
|
|
|
|
Not only lighter, but faster. Mutexes are kernel objects, while CS are user-level objects. This means that each operation on a mutex need a costly trip to the kernel, while an operation on a CS doesn't.
[stupid-disclaimer]
You are hereby notified that any unauthorized disclosure, dissemination, distribution, copying or the taking of any action in reliance on the information herein is strictly prohibited.
If you have received this communication in error, please immediately notify the sender and delete this message.
No addressee should forward, print, copy, or otherwise reproduce this message in any manner that would allow it to be viewed by any individual not originally listed as a recipient.
|
|
|
|
|
that is not completly right peterchen... it will coast you cpu time because a mutex is an object of the windows object manager. that means that every additional object "fills" the list so looking up another object will take more time!
Don't try it, just do it!
|
|
|
|
|
That isn't correct. An object handle maps directly into the process' object table. It is an O(1) lookup.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
If you don't need the overhead of a mutex, don't use it. Better yet use one of the libraries that provide a lock interface to both objects. That way you can change them easily at a later date.
If it is at all possible structure your objects so you can use copies of data instead of sharing, or other approaches to avoid locking as much as possible. Each mutex or critical section you add increases the risk of deadlock and they are very difficult to reproduce and troubleshoot.
Also, check out the Objects\Mutexes performance counter object, it will show you a count of all active mutexes. For example I currently have 551 total mutexes on my system.
If you don't kill me you will only make me stronger
That and a cup of coffee will get you 2 cups of coffee
|
|
|
|
|
i don't think that this is a good idea at all!
what kind of c++ classes are you talking about?
how to redesign the code so you don't need mutexes?
use one mutex for many similar procedures...
there are much better solutions for that!
Don't try it, just do it!
|
|
|
|
|
As already pointed out, using mutexes is an overkill unless the locks are shared between processes. Use a critical section which is much faster but it still creates system objects (an event flag is created when a lock request is blocked.)
Having many critical sections can hurt system performance, but not by much. It isn't like NT maintains a link list of system objects and has to cycle though them to locate the system object. I probably uses a O(1) algorithm that is very fast.
The question is why do you need many locks instead of one. To answer that, you really need to know how your program is handling threading. If you don't have many threads, what is the chance that two threads will be needing the lock at one time? How long is the lock being held? Will one thread need to acquire more than one lock at a time?
The more threads you have accessing these objects and the longer the lock needs to remain locked, the more you need a more granular locking system. Instead of locking the whole object pool, you lock individual objects. Thus greatly reducing the chance of two threads locking the same lock. However, this really only works if the distribution of your objects needing to be locked is spread out. If you have just one or two objects that are being locked all the time while all the others are rarely locked, then this won't help much.
As far as needing to have multiple objects locked at one time, if you have this requirement you must start to consider deadlocks. A deadlock happens when thread A locks lock 1. Then thread B locks lock 2. Then thread A requests lock 2 while thread B requests lock 1. Neither thread can continue because each is waiting on a lock already acquired by the other thread. There are multiple ways to handle this. However, dealing with this type of problem is generally nasty.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks to everybody for mostly constructive input. FYI, I settled on using critical sections, as there is no forseeable need for inter-process locking. I also plan to reduce the number of locks, down from a lock per object to a medium granularity, probably using one lock per class.
Again, thanks for input.
Bernd
|
|
|
|
|
Can anyone tell me if I can get the time zone info for a computer on a local network?
Please tell me if this is possible.
Thanks,
~LizardWiz()
|
|
|
|
|
Is NetRemoteTOD() of any help?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hmmmmm. It is a start I guess. But the structure only seems to return the current bias of the time zone from GMT time, I don't really know if I am daylight savings time or not. I guess I can get the current date of the machine in GMT time (which is what that function seems to return), then convert it to a local time for my machine, then determine if its daylight savings time or not, then determine the appropriate time zone based on that bias amount...
I am lucky I guess that we are only looking at Time Zones in the US...
But won't Arizona get messed up in daylight savings time?
Anyhow thanks for your help. If you have a better idea please let me know.
~LizardWiz()
|
|
|
|
|
LizardWiz wrote:
It is a start I guess. But the structure only seems to return the current bias of the time zone from GMT time...
Which is what you initially asked for. Determining DST on a remote computer is a different issue.
Do you have access to the remote server? If so, could you create a little application (two dozen lines of code) that listened to a particular port, and when a request came in on that port, send back a reply indicating whether DST is in effect?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I have a named pipe client that is using overlapped I/O on a handle
registered with an I/O completion port. There was a bug in the server that
was causing it to never read the named pipe, which in turn caused me to
notice that the overlapped WriteFile call in the client was getting blocked.
My overlapped ReadFile calls are not being blocked.
After fixing the server bug, it appears that the WriteFile calls are always
completing before WriteFile returns. I never seem to get ERROR_IO_PENDING
back on a write. The write completion events ARE being properly posted to
the IOCP.
I did open the named pipe with FILE_FLAG_OVERLAPPED. (If I hadn't, I don't
think the overlapped reads would be working properly.)
Any suggestions?
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
I've got a string, and i want to transform it into a CString.
string s="hello";
CString cs;
I can't do the following:
cs=s:
any ideas?
thanks
|
|
|
|
|
cs = s.c_str(); should work.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
Hi!
I've got a listbox (MFC app), and when i doubleclick on it i'd like to open a popupmenu.
I've got the CMenu popupMenu in my view class as a private atribute
this is the function:
void CJmnView::OnDblclkListContactos() <br />
{<br />
popupMenu.CreateMenu();<br />
popupMenu.LoadMenu(IDR_MENU_POPUP_CTACTOS);<br />
popupMenu.TrackPopupMenu(0, 100, 100,this);<br />
}
when i doubleclick on an item of the list i've got a Debug Assertion Failed! error.
any ideas?
another thing, there aren't many events for the listbox... for example, there is no onrightmousebuttonclick or something like that.
thanks!
|
|
|
|
|
kfaday wrote:
when i doubleclick on an item of the list i've got a Debug Assertion Failed! error.
any ideas?
And that assertion would be?? Have you looked at the line of code in question to see why the assertion is firing?
Is there a design reason why double clicking, instead of a right-click, brings up a menu?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|