heh, too many dots - .net 4.0 is exact. We're used here to write it in this short manner .net20, .net30, .net35, .net40. I use it so often - googling, referencing, also can be found in some original microsoft comments so I didn't even realize that it's a way too ahead in time :)
geo_m
Posts
-
Threads in Windows Service -
Display messages, when using windows servicesI'd not reccommend doing so, better is stick with some nlog or something like this. But if you really really need to, use the MessageBox.Show overload that allows you to specify the:
MessageBoxOptions.ServiceNotification
The message box is displayed on the active desktop. The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer. But generally it is considered a bad practice of displaying messagebox directly from the service. I'd stick with some logging solution. -
Threads in Windows ServiceYou can use threads easily in windows services. But if you can use .net 40 I'd suggest you check the new Task Parallel Library before you decide.
-
JOTDreally nice one. That's the life...
-
Named Pipe Implementationcheck around the
NetNamedPipeBinding
. Otherwise it's exactly the same as using any other transportation layer in WCF. -
TypeForwardedToAttributeonly use is when you have some legacy application (no source available, or cannot recompile for any other reason) referencing the type T1 originally located in A1 and for whatever reason you need to move the type out from that assembly. Then you can do that mumbo-jumbo and you'll have your type happily moved out of A1 to A2, legacy binary still referencing the A1, but using type T1 from A2. At least that's the reason for the attribute from my understanding. Modify: Yes! And you need to know it for MS exams (the second reason why this attrib exists ;-) ).
-
Help with DES encryption & decryptionyou're mixing with the base64 encoding. Your sequence is: Encryption: get bytes of plaintext encrypt display base64 encoded ciphertext Decryption: get bytes of ciphertext decrypt display base64 encoded result but better and working solution ought to be Decryption: decode the ciphertext bytes from the base64 (FromBase64String) decrypt get string from bytes
-
ThreadingI'm not sure if I fully understood the question, but if you're using threads from System.Threading the time the threads are running are automatically scheduled and switched by the windows for you.
-
socket.beginrecieve method for UDP. find out who sent you the data?Use
BeginReceiveFrom
specify theremoteEP
parameter asnew IPEndPoint(IPAddress.Any, 0)
. This will allow you to receive from any sending peer (or you can limit it here to receive only from specific address or port). Then useEndReceiveFrom
to find who's sent the packet. (details in documentation) -
How to keep my app from being "killed"I don't know about any easy way how to achieve that. Personally I would prefer to find a non-software solution, but if you insist ;-) I would: 1. limit the account the kids are running under (if not done already). If they are admins, you can do nothing they are not able to overcome. 2. Write a service that is optionally attached to the
WTSRegisterSessionNotification
(WinXP+). This helps you to use their windows logon to measure the time they spend on the computer in total. Also can help to detect who is trying to overcome the security mechanism. 3. Set the service as autorestarted for any case (service settings). 4. Disable the network connectivity on the service startup (e.g. disable the ethernet card). 5. Write the communication application that is on one side communicating with the service, on other side asks for the specific username/password allowing to start the internet session. 6. The application will pass the credentials to the service. 7. Service will enable the ethernet card for use for valid credentials. 8. Logoff from the windows or from the communication application will cause the eth card to be disabled. 9. In cause the service is killed somehow, windows will restart it. Because of 4. the internet connection is disabled. This all will pops-up some questions: 1. what is a Internet spending time - I can download a bunch of pages at all in a few seconds, then read it for a week (offline browsing)? On the other side I can download e.g. a large iso image of my school project from slow school server physically not being at the computer - meanwhile helping at home with some other tasks ;P. 2. How to manage the software solution that someone will not simply bring in a notebook, disconnect the original computer and browse from that notebook? 3. above solution is quite difficult to manage with user-switching (although not impossible, but can be overcomed by another software running on background in suspended account waiting for the connection to be enabled from another account) Another possibilities (solves 2): - custom proxy - measure the time on other computer used as an authenticated proxy server. Set your network that the internet is not accessible in any other way without using this proxy. Lock proxy in secure place. -
RtlFreeHeap Problem in dllDon't know much details about FS, as I never program anything for that, and I just hope this will not be complete OT ;-) My rule for dll programming is: Do not release memory allocated in another module. This means if you allocate something in your dll (eg the malloc/new is called inside your library) the corresponding free/delete should be called also in your code inside the same library. Maybe you have some situation when you passed something you allocate to the fs9.exe and it tries to release it for whatever reason or vice versa - you're releasing something allocated in fs9.exe or another module.
-
Using MAC addressYes, they generally all uses some sort of central server. Problem is that you can't use MAC outside your LAN network segment. Outside of this scope even the MAC address is different (see ARP for details). For connecting over tcp/ip or udp/ip you always need a IP address. You can consider using udp broadcasts in your design - newly started application can send udp broadcast (I'm here and my address is ...) to all interesting parties. But usage of broadcasts are usually limited by the network architecture - usually up to the nearest router.
-
Synchronous Vs asynchronous server connectionWell, it's not exactly 2-3, it's just the range, where it can be acceptable and because if you have 4 clients, you usually have 5 next day, then 6 and after month you'll find yourself having trouble with 100... Problem with synchronous access, is that it needs generally one thread per client behavior and then they became a resource hog, because a lot of time is spent by creating/destructing these threads and by switching between them. Ideal ratio is one thread per one cpu, although this is of course unrealistic, but more threads means more work in the OS, hence less cpu time for application. look here, at the section internet&networks on codeproject for more details and even tutorials: http://www.codeproject.com/internet/[^]
-
What's the diff between ALT and COMOr, in other words than Christian says, the COM is a technology, while the ATL is a tool. COM defines some rules (like that objects are refcounted etc.) while ATL helps you to implement these rules, saving you a time by providing helpers for keeping the rules etc. compare: creating the com object without ATL:
IMyInterface* ipNewObject = NULL; HRESULT hr = CoCreateInstance( clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IMyInterface, &ipNewObject ); if( ipNewObject ) { ipNewObject->SomeFunction(); ipNewObject->Release(); } return;
with ATL:CComPtr<IMyInterface> spNewObject; spNewObject.CreateInstance("objectId"); if( spNewObject ) spNewObject->SomeFunction(); return;
-
CComObjectIt's because of the
IUnknown
'sAddRef
,Release
andQueryInterface
implementation. You have to achieve, that theIUnknown
implementation is one for the whole object, regardless of how many interfaces it consists of (there's usually only one reference counter for the whole object). This means that you need the implementation to be placed in the last object in the hierarchy. Therefore theCComObject
is a neat trick, how to save user the need to write theAddRef/Release
code into every user class. -
Synchronous Vs asynchronous server connectionDoh, synchronous perfoms better, but asynchronous offers much better scalability. Then, it depends on what you want - if you have only one client, then synchronous will be the choice, if the number of clients is unknowns or more than 2-3, async is the choice. Async is much harder to code, because humans usually don't think async.
-
list registered OCX componentsDepends, easiest way is simple to try to create a instance of it, while if succeeded, then it's registered, if failed, it's not registered. Or you can scan registry for the registration info (see e.g.
HKCR\CLSID\{classId of your component}
) You have to have the com model already initialized (CoInitialize
called). -
Application crash due to change in compiler settingsHi, it seems to me, that you have some weird problem with thread synchronization somewhere. By changing the optimalization switch, the compiler changed the order/amount of instructions that can changed the order/timing of some operation. This can lead to the situation, where with speed optimalization the thread initialization finishes before other thread uses it, but with optimalization off the initialization is not finished yet, so the second thread uses something uninitialized. By introducing the
Sleep(0)
you changed the order of the instructions stream, so it could 'fix' your issue at the moment. But if the synchronization problem is in your application, it will pop-up somewhere else, so definitiellySleep(0)
is not a conceptual solution for such a problem. By using the event synchronization, you can fix the problem usually (or a part of it). But from the description you gave, it seems that effectivelly you only introduced the 500ms sleep to the start of the application, so just postponing the problem. Only idea I can get is that either the event is not signalled at all, or you can use two different handles, not the same event for synchronization. hope this helps, dont't hesitate to ask for more -
iocp threads exitDifficult to say with such a level of info I have. But when I assume that you implemented the iocp correctly, it can be that you simply end the thread proc. somewhere - forgotten return, uncatched exception whatever like that
-
How to interface a COM class in a non-COM DLLhm, as I could understand the
ATL_NO_VTABLE
problem, when you're including theobject.h
file, the code generated with#import
never contain the ATL macros. You probably forgot to remove theobject.h
include. I always used#import "blahblah.tlb" no_namespace named_guids
for including COM objects to my projects. Problem is, that this doesn't import the object as-is from the C++ point of view. It defines all interfaces the object is derived from and all Guids required for the object - Guids of interfaces and of the object itself. If you look into your debug (or release) directory, you'll seeobject.tlh
andobject.tli
(optional), that contains code generated by the#import
. Well, when you have the interfaces imported, you can use one of them as a controlling interface. General interface isIUnknown
. From this you canQueryInterface
to get any other interface exported by the object. TheCComObject
thing is when you decide not to import interfaces, but the C++ object definition. The method I would choose depends on what you want to achieve, but generally I'd prefer to a) create a special interface for controlling the DCOM object, passed to the .dlls b) create a third c++ object, that is included in the DCOM as well as in the .dlls. It's purpose is only for exchanging the information - the DCOM object creates one instance and passes it to all calls to the .dlls. Or even considering the implementation to be in the C++ object and only calls from outside will be proxied through the DCOM object. Then the DCOM object will be only very thin wrapper - generally only thing it will does will be to create the third object (or derive from) and then simply proxy all calls from DCOM to the C++ object. I hope the explanation is clear, here's 7:00 morning ;-) The a) and b) are more or less equal, the a) is more COMish, while the b) is more C++ish.