|
Thanks, this did help in minimising the cause of getting a corrupted log.
And I found on the net an actual way of reparing the corrupted one and/or export the entries to HTML or Excel sheet.
|
|
|
|
|
Hi all,
My question is about how to intercept Office event in a C# add-in. I want to intercept file printing, saving, copying etc. I know that I can intercept events in VBA by supplying the rights macros, eg for file print,
Sub FilePrint()
MsgBox "I am printing " + ActiveDocument.Name
ActiveDocument.PrintOut
End Sub
The Application.Class in Word does not seem to have a FilePrint event
So my question is how do I achieve this functionality in a C# add-in ?
Thanks in advance
|
|
|
|
|
Hello all.
First of all I'm trying to send CTRL+ESC using SendKeys.Send("^{ESC}");
It doesn't work. Why?
Second, can you tell me how can i send LWIN (Left Windows key) using SendKeys? Thx
|
|
|
|
|
Hi guys, I am facing a problem regarding static methods, what happens when we call a static method (accessing only local variables),
public static void HelpMePlease()
{
int a=0;
a++;
Console.WriteLine("A must be 1 " + " a :" + a.ToString());
a++;
Console.WriteLine("A must be 2 " + " a :" + a.ToString());
a++;
Console.WriteLine("A must be 3 " + " a :" + a.ToString());
a++;
Console.WriteLine("A must be 4 " + " a :" + a.ToString());
}
Lets suppose, I call this method from 50 threads simultaneously.
will All methods keep single copy of a. or each one will have its own copy.
Please explain it comprehensively, compiler internals etc.
Thanks in advance
M.Waseem
|
|
|
|
|
M.Waseem Chishti wrote:
Lets suppose, I call this method from 50 threads simultaneously.
will All methods keep single copy of a. or each one will have its own copy.
You already wrote the code, what does it do? On the latter part, local variables are created and placed on the stack, so each call will have its own locals.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
yeah all methods are maintaining their own copies.
all i wanted to know is what copiler does when a method is called ??
is there any diffrence between behaviour of compiler when you call a static method ??
|
|
|
|
|
When you call a static method, there is no reference to the object, as there is no object. Other than that, there is no difference.
Calling a static method does not use the address of an object:
Console.WriteLine("test");
=
ldstr "test"
call void [mscorlib]System.Console::WriteLine(string)
Calling a non-static method uses the address of the object:
num.ToString("d4");
=
ldloca.s num
ldstr "d4"
call instance string int32::ToString()
---
b { font-weight: normal; }
|
|
|
|
|
Hello...
In other words:
1. Every Thread contains his own stack...
2. Local variables are always stored on the stack from the specified thread (each one have its own copy)...
--> The static keyword before functions haves no effect on there locals...
|
|
|
|
|
Thankx
|
|
|
|
|
Here is how the IL code looks like:
.method public hidebysig static void HelpMePlease() cil managed
{
.maxstack 2
.locals (
int32 num1)
L_0000: ldc.i4.0
L_0001: stloc.0
L_0002: ldloc.0
L_0003: ldc.i4.1
L_0004: add
L_0005: stloc.0
L_0006: ldstr "A must be 1 a :"
L_000b: ldloca.s num1
L_000d: call instance string int32::ToString()
L_0012: call string string::Concat(string, string)
L_0017: call void [mscorlib]System.Console::WriteLine(string)
L_001c: ldloc.0
L_001d: ldc.i4.1
L_001e: add
L_001f: stloc.0
L_0020: ldstr "A must be 2 a :"
L_0025: ldloca.s num1
L_0027: call instance string int32::ToString()
L_002c: call string string::Concat(string, string)
L_0031: call void [mscorlib]System.Console::WriteLine(string)
L_0036: ldloc.0
L_0037: ldc.i4.1
L_0038: add
L_0039: stloc.0
L_003a: ldstr "A must be 3 a :"
L_003f: ldloca.s num1
L_0041: call instance string int32::ToString()
L_0046: call string string::Concat(string, string)
L_004b: call void [mscorlib]System.Console::WriteLine(string)
L_0050: ldloc.0
L_0051: ldc.i4.1
L_0052: add
L_0053: stloc.0
L_0054: ldstr "A must be 4 a :"
L_0059: ldloca.s num1
L_005b: call instance string int32::ToString()
L_0060: call string string::Concat(string, string)
L_0065: call void [mscorlib]System.Console::WriteLine(string)
L_006a: ret
}
.maxstack 2 -- this allocates space for your variable on the stack.
As the local variables are allocated on the stack, every call to the method has it's own set of variables.
Your function is thread safe. (As the Console class is also thread safe, even the writing to the console is thread safe. It might look awful if you have several threads writing to it at the same time, but it's safe.)
---
b { font-weight: normal; }
|
|
|
|
|
is there no diffrence between how compiler treats a static method and an instance method (if both are only accessing their local variables) ??
|
|
|
|
|
Other than sending a object reference to the instance method, no, there is no difference.
---
b { font-weight: normal; }
|
|
|
|
|
sallam
iwant to controll the lcd(lcd)
through serial port RS 232
please give some information how to do it if u know
|
|
|
|
|
Hi all!i have a read function here.I face a problem,it just can read limited byte only..Can somebody help me?Where to edit to make it read more bytes?Thank so much!
public byte[] Read(int NumBytes)
{
byte[] BufBytes; //------Declaring of dynamic Array
byte[] OutBytes; //------Declaring of dynamic Array
BufBytes = new byte[NumBytes]; //------Setting the Array Size to NumBytes( From parameter )
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort = new OVERLAPPED(); //------Declaring of ovlCommport
int BytesRead = 0; //------Declaring of BytesRead and set to 0
ReadFile(hComm, BufBytes, NumBytes, ref BytesRead, ref ovlCommPort); //------Get data from RS232
OutBytes = new byte[BytesRead];//------Setting the size of Array to BytesRead
Array.Copy(BufBytes, OutBytes, BytesRead); //------Copy previous array data to new array data for preventing data loss
return OutBytes; //------Return the GET data
}/*-- End of Check Port is Open --*/
return null; //------Return null( nothing )
}/*-- End of Function Read --*/
|
|
|
|
|
Hello...
Try something like this:
public MemoryStream Read(int bufSize)
{
byte[] BufBytes = new byte[bufSize];
MemoryStream stream = new MemoryStream();
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead = 0;
while(ReadFile(hComm, BufBytes, bufSize, ref BytesRead, ref ovlCommPort) != 0 /* or true (based on your interop declaration) */)
stream.write(BufBytes,0,BytesRead);
}
return stream;
}
Remark: This is code is not tested (it can contains some small bugs but the base concept will work)...
|
|
|
|
|
Hi!Thanks!This code no problem but how am i going to call it to my Main,please?Thanks again!
|
|
|
|
|
I wish to add a context menu in windows explorer which should allow me to:
1. Select multiple files and / or a combination of multiple files and folders at the same time.
2. Perform one out of 3 operations shown in the context menu (and not the default option only) depending upon where the user clicks.
I tried to search Code Project as well as Google. I am able to get sample code only for single-file selection and generally single-option (i.e., default option) from the context menu. The best sample code which comes nearest to my requirements is provided at the link
http://www.theserverside.net/articles/showarticle.tss?id=ShellExtensions[^].
However, the problem is that this is for single file selection. I tried to change it to multi-file selection, but I am yet to get success in that though I continue to make further enhancements.
Can anybody please suggest link to some code on the lines suggested by me above? Thanks in advance.
|
|
|
|
|
Hi, how can I detect my default smtp mail server?
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hi,
Does anyone know if it's possible to owner draw the LEFT had part of a propertygrid? Using custom UI Editors I can draw change the look of the value field, but not the name field...
Shane
|
|
|
|
|
I'm very much a novice so please make any replies idiot proof.
Here's a snippet of code I'm working on...
RegistryKey regkey;/* new Microsoft.Win32 Registry Key */
regkey = Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment"); //Set global environment variable
regkey.SetValue("IPv4Pri", ipaddress);
Registry.LocalMachine.Flush();
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
Everything works great in that the registry key I wrote is in the registry and will ba available once I reboot. But I was googling and hoping that I don't have to reboot.
I'm trying to get the "SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);" thing to work and having a great amount of difficulty. It doesn't even recognize the SendNotifyMessage method.
Any insights on how I can "publish" my new registry setting so any new windows opened will have the key available?
Any help is greatly appreciated.
|
|
|
|
|
tomlog wrote:
RegistryKey regkey;/* new Microsoft.Win32 Registry Key */
regkey = Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment"); //Set global environment variable
regkey.SetValue("IPv4Pri", ipaddress);
Registry.LocalMachine.Flush();
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
First of all, you should condense the first two lines into one, create and initialise in the one line.
Secondly, I suspect you need to call CreateSubKey one key at a time, this code is assuming everything except the last item already exists. That's assuming it's being written at all, as I read the rest of your post, I wonder what the problem could be ?
tomlog wrote:
I'm trying to get the "SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);" thing to work and having a great amount of difficulty. It doesn't even recognize the SendNotifyMessage method.
SendNotifyMessage is not supported in C# without pInvoke[^]. Once you import it, you can use it, but this also means that you need to use pInvoke to catch the message.
tomlog wrote:
Any insights on how I can "publish" my new registry setting so any new windows opened will have the key available?
If you wrote something to the registry then all programs can see it. The problem is letting them know, apparently.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm clueless on what pInvoke[^] is...
What would I put in my code to import/use/catch it?
Right now the regkey I write gets tot he registry and if the system is rebooted the key shows up. I'm looking for a way to not have to reboot so that my changes can be seen by any new command windows.
|
|
|
|
|
tomlog wrote:
what pInvoke[^] is...
It's a link, to a site that explains it. Basically, you put a statement in your code which works by importing a function from a dll.
tomlog wrote:
What would I put in my code to import/use/catch it?
You'd use the signature provided by that site, then you'd have a method you could call. Call it where you like.
tomlog wrote:
Right now the regkey I write gets tot he registry and if the system is rebooted the key shows up. I'm looking for a way to not have to reboot so that my changes can be seen by any new command windows.
You simply MUST be wrong. The registry does not work that way, it's instant.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I am trying to get drag and drop to work between listbox. When I have the mode set to One it works like a dream. When the mode is set to MultiExtended it fails to work and I get an IndexOutOfRangeException. The strange thing is that when I check the size of SelectedItems or SelectedIndices it shows the correct number of selected items. However, when I try to retrieve the values I get the IndexOutOfRangeException.
Another thing I discovered is that this problem only seems to occure in mouse events. If I call the same code from the event SelectedIndexChanged or from the click event of a button it does work.
Has anyone seen this behaviour before or have a solution?
Regards, nidkil
|
|
|
|
|
Could you post some code? Maybe we could see what's going wrong...
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|