ok, that sounds fair.. Can you guide me how to do that? Is it possible to run .Net applications during LogOff? The .Net runtime is active even during user logoff? Best Regards Mikke
Mikke_x
Posts
-
Running application as windows shutdowns -
Running application as windows shutdownsHi all! I have a queistion. I would like to run an application every time that my windows (XP) is shutting down. Is it possible to register a batch script that executes every shutdown in the registry? Best Regards Mikke
-
Events over .Net RemotingHi! Thank you for you reply! I realize that what I was trying to do was not as easy or smart as I thought.. What puzzles me is that it works well if I use a delegate with only a string as a argument. Why does that work?? I cannot have a delegate with two strings as arguments, but one work. I tried to implement the ISerializable interface. That did not work either. I can buy the thought of the events not working if the server cannot find the client, that is reasonable. But why does it work if the argument is a string?? :confused: Best Regards Mikke
-
Events over .Net RemotingHi all, I have a problem I cannot solve by my own. The message is quite long, but I hope that someone is nice enough to read it and give me a hand. The basic problem is that I cannot sent events over .Net remoting that has an event argument as a class I have created, but strings as arguments works just fine. I have three projects: Server, Middle and Client. Server going to generate events and pass them through .Net remoting to the client. The middle project contains the remoted object. It also contains a delegate that is used to define the events generated in the server. The server is remoting the class in the middle project through a TCP channel. The connection class in the server is remoting the object:
private void OpenConnection() { BinaryClientFormatterSinkProvider clientProvider = null; BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = 7889; props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; props["name"] = "StatusControl"; TcpChannel chan = new TcpChannel( props,clientProvider,serverProvider); ChannelServices.RegisterChannel(chan); RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("ProductionStatusControl.DistributedStatusControl, ProductionStatusControl"),"IDistributedControl", WellKnownObjectMode.Singleton ); // Singleton class used to retreive messages from the remoted objects m_single = StatusSingletonConnection.GetInstance(); System.Threading.ThreadStart ts = new System.Threading.ThreadStart( SendMessages ); System.Threading.Thread t = new System.Threading.Thread( ts ); t.IsBackground = true; t.Start(); }
The middle project has a delegate:public delegate void ProductionStatusDelegate( StatusMessage message );
, a class as event argument:/// /// A status message from the floating storage /// [Serializable] public class StatusMessage { private FloatingStorageEventType m_type; private string m_message; /// /// Creates a new Status message instance /// /// /// public StatusMessage( FloatingStorageEventType type, string message ) { this.m_message = message; this.m_type = type; }
-
Converting interface pointersHi all! I tried to post this in the C# forum, but without replies. I tought I might try here too. I have a small Interop question: I have a COM object that takes a structure as in-parameter. One of the fields in the structure is an IID*. When doing this in C++ the code: GUID rrid = __uuidof( _InterfaceName ); parStruct.riid = &rrid; works fine. How would I do this in C#? I have tried several things, but can´t get it to work. The type of the struct-field in C# is intPtr. And the only way I can find such a type, that I can think of, is: Type t = typeof( _InterfaceName ); System.RuntimeTypeHandle h = t.TypeHandle; parStruct.riid = h.Value; But I guess that I am way off here. Any one that can give me a hand here? Regards Mikke Added info: Hi again! I tried to create a C++ .Net project instead, just to try and find a work-around. When I took the COM objects needed and tried to import them into my brand new cpp project i got this error message: TlbImp warning: The type library importer could not convert the signature for the member 'RobEventParams.riid'. And a couple of other ones like this one for other similar parameter-structs with riid fields. What does that mean for me? Is it impossible to marshal something from .Net into this COM? The purpose is to set up a sink and recieve events from the COM object, to do this I should send a ref to an object that should recieve the events and the signature of an interface implemented in the receiver. It is the interface "signature" that is the riid, and also the problem here. When I execute my C# code above I get an exception telling me that "No such interface supported". Do I have to submit a non-.net method as a sink here? Best regards again / Mikke
-
Guid to intPtrHi all! I have a small Interop question: I have a COM object that takes a structure as in-parameter. One of the fields in the structure is an IID*. When doing this in C++ the code: GUID rrid = __uuidof( _InterfaceName ); parStruct.riid = &rrid; works fine. How would I do this in C#? I have tried several things, but can´t get it to work. The type of the struct-field in C# is intPtr. And the only way I can find such a type, that I can think of, is: Type t = typeof( _InterfaceName ); System.RuntimeTypeHandle h = t.TypeHandle; parStruct.riid = h.Value; But I guess that I am way off here. Any one that can give me a hand here? Regards Mikke Added info: Hi again! I tried to create a C++ .Net project instead, just to try and find a work-around. When I took the COM objects needed and tried to import them into my brand new cpp project i got this error message: TlbImp warning: The type library importer could not convert the signature for the member 'RobEventParams.riid'. And a couple of other ones like this one for other similar parameter-structs with riid fields. What does that mean for me? Is it impossible to marshal something from .Net into this COM? The purpose is to set up a sink and recieve events from the COM object, to do this I should send a ref to an object that should recieve the events and the signature of an interface implemented in the receiver. It is the interface "signature" that is the riid, and also the problem here. When I execute my C# code above I get an exception telling me that "No such interface supported". Do I have to submit a non-.net method as a sink here? Best regards again / Mikke
-
Exception in SafeNativeMethodsHi! Sorry for posting in multiple boards, but my post in the C# board gave no replies what so ever, so I thought I give it a try here too. I´m working on a project where we are making a hook for an other software. Now we have encountered a problem and I would like some help on finding a work-around. When we are opening a new form in the hook an exception is thrown and the form is destroyed. The exception is a System.TypeInitializationException that says that "The type initializer for "System.Drawing.SafeNativeMethods" threw an exception. -->System.NullreferenceException: Object reference not set to an instance of an object". I have traced the exception into the InitializeComponent() method and it is thrown when the first component on the form is initialized. This exception does not appere every time, but once in a while. I can not see any real reason for the problem and we are not doing any different when it works and does not. I have searched the net and found others that have had the same problem, mut I have not found any good solution. The problem seems to be in GDI+, at least that is what how I have understod it when reading posts on other forums.. The application loading the hook is creating appDomains for all hooks so that it can unload them as it whishes, I think that this might be the root of the problem, or? We would really need to show this form, its for configuring the hook, and the main application really needs to unload the hooks now and then, so the problem is a fact. Is there any good work-around for this? Is there anything we can do to solve this problem without having to make changes in the main application? All help appriciated! Regards Mikael
-
SafeNativeMethodsHi! I´m working on a project where we are making a hook for an other software. Now we have encountered a problem and I would like some help on finding a work-around. When we are opening a new form in the hook an exception is thrown and the form is destroyed. The exception is a System.TypeInitializationException that says that "The type initializer for "System.Drawing.SafeNativeMethods" threw an exception. -->System.NullreferenceException: Object reference not set to an instance of an object". I have traced the exception into the InitializeComponent() method and it is thrown when the first component on the form is initialized. This exception does not appere every time, but once in a while. I can not see any real reason for the problem and we are not doing any different when it works and does not. I have searched the net and found others that have had the same problem, mut I have not found any good solution. The problem seems to be in GDI+, at least that is what how I have understod it when reading posts on other forums.. The application loading the hook is creating appDomains for all hooks so that it can unload them as it whishes, I think that this might be the root of the problem, or? We would really need to show this form, its for configuring the hook, and the main application really needs to unload the hooks now and then, so the problem is a fact. Is there any good work-around for this? Is there anything we can do to solve this problem without having to make changes in the main application? All help appriciated! Regards Mikael
-
Stream writing htmlHi! Thanks alot! Both to Heath and Steven! Will try this first thing monday morning! The Joel on Software text gave som intresting, and fun!, reading. / Mikke
-
Stream writing htmlHi all! I have a wierd problem and I can´t understand why it happens. I have a couple of html pages that I read from and write to. When I read and write I use FileStream.ReadByte() and FileStream.WriteByte(). The problem I have is that when I view the file in IE after it is done, IE can not recognise the my swedish characters ( å,ä,ö ). What really bothers me is that if I take the source of the page via IE and copy paste it into a textfile and give it the extension html there are no problems at all. There is absolutely no differences between the files that work and the ones that does not work, the content of the pages are the same, but still IE can read one and not the other.. :doh: There have to be some differences in some part of the not visible content of the files, but how do I resolve the problem? I need to save the files, and in my current implementation I would like to use stream.WriteByte() but I would also like to keep the swedish characters. Please advice.. / Mikke
-
enum questionYeah, I see what you mean. But I still can´t see the point of beeng able to declare an enum as: enum ints :int {zero, one} if I can´t use it as constant int without convert. enum has always been an int in the background. If it is to be saved to file or something one should comment the code good enought so that the other people in the team knows not to change the order of the declarations. Or do them visible by: enum ints { zero=0, one=1 } ; Then there should be no problem. / M
-
enum questionOk, can understand the type error thing, but still.. Since I declare the enum as a int ( through :int ) I thought I could use the enum fields as constant ints. It would give a nice looking code. And since the compiler knews it is an int I can´t really see the problem. / M
-
enum questionHi! Have a small question. Have added a couple of enum types to a project thinking it would be fast and easy. Altough I found a small disturbing thing that enoyed me. enum is an int as defult, so a declaration like: private enum ints { zero, one, two }; generates like three int constants with values 0,1 and 2 ( at least in C and alike ). But C# does not treat ints.zero like an int, and I think that is kinda strange. What I would like to do is like: int a = ints.zero; But then VS compains about converting. even if one declares the enum as: private enum ints :int {zero, one, two }; it does not alow a simple: int a = ints.zero; One have to do like: int a = (int)ints.zero; Anyone who can explain why? I´m just confused :confused: why it is like that, its not like it is a problem, it just does not look so good. / M
-
CPU time consuming programYeah of course. The problem here was that the process used 99% of the processor all the time. Altough it looked like it had really low priority since it did only use the processor if no other thread wanted to execute. We did resolve the problem however. Can´t really explain the reason behind the problem, but it was because of a sleeping thread. We started a thread when we started the application and suspended it immedediately. Now we have changed it so that we don´t start the thread until we need it instead of starting it and suspend it from the start. M
-
CPU time consuming programHello! We are developing a program in c#, we have a problem with probably the threading. After a few minutes running our program, it starts to consume all cpu time, we have not started any own threads. The running thread does not seem to have any priority, it does not slow down any other programs, it just overrides the idle thread, it seems. Does anyone know of any known problem using c# concering out problem, or has any other ideas of what the problem might be. M
-
Invert grapics in 2Dok, thank you! I thought it might be like that, but wanted to be sure. I have used a OOD doing the class hierachy and have encapsulated all the important features. Altough some of the functionallity has been placed outside the class because some of components in the application are drawing some graphics om the panel, mainly debug information. Looks like I will have to do some changes in the painting routines then.. / Mikke ( by the way, I think that openGL uses upper right corner too. If I remember correctly, I have not used it in a while.. )
-
Invert grapics in 2DHi! I have made an application with a panel showing 2d graphics. Now I have found out that the grapichs are inverted, the x axis is pointing in the right direction but y is downwards when it should be upwards on the screen. I can´t really find any good way to invert the axis. I could just change code doing the drawing, but the panel is accessed from a lot of places and it would take a lot of time. What I would like to do is invert the axix at startup and that all the 2d graphics in the panel is drawn in the right way every time a graphics object is created via panel.CreateGraphics(). Help would be much appreciated! Regards! / Mikke
-
Returning string from unmanaged dll[System.Runtime.InteropServices.DllImport("pciDriver.dll", CharSet=CharSet.Auto) ] private static extern string GetString( int i ); and I call it like: GetNumberOfStrings( ref i ); System.Console.Out.WriteLine( GetString( j ) );
-
Returning string from unmanaged dllHi! Thanks! But I still get the wrong output. :confused: My exported dll has a function that first writes the string to export to file and then returns it, Ie: __declspec(dllexport) LPCTSTR GetString( int i ) { FILE* file; file = fopen("test.txt", "a" ); fprintf(file, "%s%c",m_strings[i], '\n'); fclose(file); return m_devices[i]; } This gives the correct output in the file, but the string I receive in the managed console is containing ten questionmarks first and then some correct charakters: --- test.txt: PCI-1750 I/O=2040H Advantech DEMO I/O=1H --- Console output: ????????? /O=2040H ??????????HEMO I/O=1H This is really confusing...
-
Returning string from unmanaged dllHi! I'm writing a console application in C# and a dll in unmanaged C++. The dll is loaded via p/invoke and I access some functions in it that are dllexport'ed. What I would like to do is return a string or rather char[] from the dll to the C# console. I have tried several ways but at best I get about half the string, the rest of it is replaced by "?". :confused: I have tried to return a pointer to the string. This is when I get the "half string". ( the secont half of the string actually.. ?? The first ten letters are questionmarks.. ) What I would like to do is to pass a char* as an argument and that it should be pointed to a string in the unmanaged code. Is it possible? What should I pass as argument and what should I recieve at the dll?