|
Heath,
Thanks that was excatly what I was looking for!
|
|
|
|
|
Hi, just reading up on async delegates samples from MSDN.Reference:
".NET Framework Developer's Guide Asynchronous Delegates Programming Sample"
Some questions here, you guru can definitely explain this:
QUESTION 1:
Object state = new Object(); //What do we need this object for?
// Asynchronously invoke the Factorize method on pf.
IAsyncResult ar = fd.BeginInvoke(
factorizableNum,
ref temp,
ref temp,
cb, //Async callback delegate: invoke fc.FactorizedResults when pf.Factorize completes.
state); //What do we need this object for?
QUESTION 2:
I was expecting input parameter to WaitOne would be a Mutex or AutoResetEvent... etc:
AutoResetEvent e;
WaitHandle.WaitOne(e);
But instead, from our MSDN sample:
IAsyncResult ar = fd.BeginInvoke(
factorizableNum,
ref temp,
ref temp,
null,
null);
ar.AsyncWaitHandle.WaitOne(10000, false);
(2-a) I guess .NET framework signal a waitable handle encapsulated by IAsyncResult ar.. signaling it when fd delegate(s) completes. Is my understanding correct?
(2-b) What if there're more than one handler? Should I WaitAll instead?
ar.AsyncWaitHandle.WaitAll(10000, false);
That's it. Thanks.
norm
|
|
|
|
|
As the documentation states, the state can be anything you want to pass to the callback. This could be an array of Object , since every array is an Array and an Array inherits from Object (as everything in .NET does). I use a similar mechanism (my own delegates and callbacks, but same idea) to use generics while passing specifics to the callbacks. For instance, I provide a tree service that has many methods that all use the same "find node X" method that takes a callback and a state parameter. When the node is found, the callback is invoked and the state is passed as a parameter. The callback method uses the state to do the actual work. Each publicly exposed method needs to find a node in the same way, but the callback does something completely different and is specific to the exposed method - the state is data that is passed through from the exposed method to the callback method.
When talking of handles, it all comes down to threads. You could simply pass an EventArgs derivative because those are created in many threads - the handle that you wait on must be global, otherwise one thread won't sync with another thread. The WaitHandle is global to all threads and WaitOne merely waits for it to be signals. If you look at the documentation, WaitAll and WaitAny are actually static methods. You must pass an array of WaitHandle instances to them and they will wait appropriately. WaitOne can be an instance method because it just uses the global handle of the WaitHandle from which it's being called.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
In my application I want to be able to send mail with attachments.
By using the smptMail object I can add attachments by using a filedialog and then the code:
aMessage.Attachments.Add( new MailAttachment(VedleggTxtBox.Text,MailEncoding.Base64))
where the VedleggTxtBox.Text is set by whatever the user select.
Thats all good, but I want to put in a path to a document manually in the code instead of using a filedialog to automaticcaly set the value og Vedleggtxtbox.text.
Plz help..
Or could anyone direct me to a page or some code on how I do attachements by using Outlook in my application. I been searching a long time, and havent found a good example yet using c#.
|
|
|
|
|
Are you sure the path exists that you want to code? You should use File.Exists() before attaching it to be sure. Passing a string you typed and a string that you got from another call are not different to the application and the CLR whatsoever! Seriously - the CLR sees the same thing - it's a System.String .
Also, this doesn't use Outlook, but a simple SMTP mailer. If you use Outlook, you open a can of worms because then you must start interoping a lot of things, thereby bloating the application. You must also make sure that the user has a specific version of Outlook on their system, or make sure your app can handle different Outlook and Office API versions. If all you need to do is send mail, just stick with the simple SMTP mailer.
If you still want the Outlook functionality in your app, the .NET Framework SDK has several examples with Word and MSDN has many examples in VB.NET and C# (primarily VB.NET, unfortunately, but remember that all languages targeting the CLR use the SAME class library so most stuff is the same - just syntax is different).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Is there an easy way to determine which radio button in a group has been chosen, besides having to put code in the checkchanged or clicked event for each button in the group...???
thanks,
vince
|
|
|
|
|
Like in HTML? No, unfortunately. But it doesn't have to be difficult at all. The radio buttons must be in some container, be that any given Control or, typically, a GroupBox . In order for controls to show up in the UI, they must be added to the container's Controls collection. Use that to your advantage:
foreach (Control c in this.Controls)
{
RadioButton rb = c as RadioButton;
if (rb != null && rb.Checked)
{
Console.WriteLine("You selected {0}!", rb.Text);
break;
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I need to make an application that reads from popular GIS file formats like ESRI Shape File or MapInfo TAB.
I found the open source GeoTools.net but they apparently don't work and the website on sourceforge is not really being updated.
Is there any open source or free library out there for use with .NET?
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
Has any one had much luck with this.
I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM.
I add a reference to the DLL, then try to instantiate an object, I get the following error
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Catastrophic failure
Has anyone any ideas.
I have also tried this by just adding a reference to the original .ocx, and letting the IDE to the AXIMP for me. Same problem.
Thanks
|
|
|
|
|
Big Trev wrote:
I have run AXIMP ont the .OCX to create the DLL. Then i have registerd the DLL using REGASM.
These two actions are doing the opposite.
If you intend to use an ActiveX control in your C# code, then use the IDE, Toolbox \ customize, and browse your ActiveX component. The ActiveX component will be preinteroped, so you don't need any manual call to aximp.exe
(this works in most cases. There are gotcha though).
When you drop the component into a form, you'll see whether it gets instantiated or not.
RSS feed
|
|
|
|
|
As Stephane said, just use the "Add Reference..." and select the COM tab. You almost have the right idea, though.
Use aximp.exe to import an ActiveX control and create an interop assembly. DO NOT, however, register it! Regasm.exe is for registering assemblies that contain interop metadata, such as controls that act as ActiveX controls through a CCW (COM-Callable Wrapper). If you use Regasm.exe on the interop assembly generated by from the native ActiveX control, you've just overwritten the registry settings so that the interop assembly is now the target of the CLSID! Any application trying to instantiate your original ActiveX control is now instantiating (unknowingly in almost all cases) the control in the .NET assembly through a CCW. The interop assembly, however, is looking for the actual control and not finding it because it's finding itself!
Now, I would hope (and don't remember off the top of my head) that regasm.exe checks to see if the assembly was imported from an ActiveX control. But it if isn't, you need to use "regasm.exe /u myassembly.dll" immediately, and then use "regsvr32.exe myactivex.ocx" to fix the registry problems that are most likely affecting you.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply. I still can not get it working though.
this is the code i am using to create the object.
COMMSOCXLib.CommsOCXClass comm = new COMMSOCXLib.CommsOCXClass();
try
{
comm.Reset();
}
catch (System.Runtime.InteropServices.COMException e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
And this is the error i catch.
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla
gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at COMMSOCXLib.CommsOCXClass.Reset()
|
|
|
|
|
Did you unregister your interop assembly and re-register the actual ActiveX OCX? You might also re-install ActiveX control if it was packed in an installer, since the install might have written more registry entries. It seems as if the actual COM method (remember, the interop assembly is only a Runtime Callable Wrapper (RCW), in which calls are forwarded) is not being called because the forwarding method can't the object to call.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yep, i did a regasm /u on the interop assembly, and regsvr32 on the ocx.
Still no joy.
let me know if you fancy having a go with the ocx. I can mail it. it is only 100k.
At the moment i an writing a DLL wrapper for the c api that also comes with the product.
Thanks
Trev
|
|
|
|
|
Hi all!
OK, so now I know how to use Office Primary Interop Assemblies to do Word automation, i.e. open a word document in its own window, maximize this window, toggle full screen mode, etc.
The question is: is it possible to load the document into the client area of a windows form? You know, if you open Microsoft Office documents in Internet Explorer they load into the explorer window, not into a blank window. Is this possible with Windows Forms / C#? If so, how?
Other - less important questions:
1) Is it possible to hide the caption (using automation) of the Microsoft Word when in full screen mode? The WordViewer doesn't show the caption in full screen mode, but the Word itself does.
2) Is it possible to force the Microsoft Word window to be always on top of other windows (again, using automation?)
3) Is it possible to use the Microsoft Word Viewer in a similar way? Whem I tried to browse the type libraries using oleview.exe I could find "Microsoft Word 9.0 Object Library", is there a type library for Word viewer?
Thanks in advance, any clues are highly appreciated!
Rado
|
|
|
|
|
Radoslav Bielik wrote:
Is this possible with Windows Forms / C#? If so, how?
Active Documents (formerly known as OLE documents) are supposed to be supported in Whidbey (VS.NET 2004).
In the mean time, you could host the web browser in a form and ask it to show that Word document.
RSS feed
|
|
|
|
|
Thanks for the information!
I will try that.
Rado
|
|
|
|
|
Does anyone know how to add a progress bar to one of the panels of a status bar? I'm referring to a windows application of course. I'm stuck and I can't find anything on the code project about this.
Thanks
|
|
|
|
|
You use owner-drawing to place or draw a ProgressBar into a StatusBar or StatusBarPanel . It's not difficult, and if you search the message threads you'll find many examples posted in the past.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
hi,
i need to put a string into byte[]. i can't find any "smarter" method to do.
currently, i do it in this way. suppose string like this "at+cmgl=4"
byte[] data = {(byte) 'a', (byte) 't', .... ,(byte) '4');
as i can't convert char[] to byte[], that's why i need to it in this way.
so, any better method to do it?
thanks,
jim
|
|
|
|
|
System.Text.Encoding.GetEncoding("ENCODING TYPE).GetBytes(mystring)
Cheers,
Venkatraman Kalyanam
Bangalore - India
"Being Excellent is not a skill, it is an attitude"
Reality is an illusion caused by caffeine deficiency(one Microsoft Research scholor)
|
|
|
|
|
Or even simpler:
System.Text.Encoding.ASCII.GetBytes(mystring) or
System.Text.Encoding.Unicode.GetBytes(mystring) . There are several other encodings you can use. Not only is it easier to type, but it also eliminates partial human error in case your forget an "I" in "ASCII" or something. This also results in faster calls within the CLR since parsing strings is extremely slow, and lookups would have to be performed before you got the actual Encoding object.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
Is it possible to extract the first day of a given week (an integer) from a given year??? I've managed to get the number of the week after a severe struggle with the DateTime class & DateTimeFormatInfo class, but could not find anything about getting the dates in that week...
Thanks...
|
|
|
|
|
I take it you are using the ISO definition of a week number? (That is, a week starts on a Monday and week 1 is the week that contains the first Thursday of the year.)
To calculate the date of the Monday for a given week number, you need to calculate the date of the Monday for week 1 and then add (7 * (weeknumber-1)) days to that date.
The easiest way to do that is to calculate the date of the first Thursday and then subtract 3 days.
To calculate the date of the first Thursday, calculate the day of the week for 1-Jan for that year. If it is a: Monday, add 3 days; Tuesday, add 2; Wednesday, add 1; Thursday, you got it in one; Friday, add 6; Saturday, add 5; Sunday, add 4.
So, amalgamating all that: calc DOW for 1-Jan. For each possibility, the Monday of week 1 will therefore be
If 1-Jan is a Monday, the Monday of week 1 is 1-Jan
If 1-Jan is a Tuesday, the Monday of week 1 is 31-Dec of previous year.
If 1-Jan is a Wednesday, the Monday of week 1 is 30-Dec of previous year.
If 1-Jan is a Thursday, the Monday of week 1 is 29-Dec of previous year.
If 1-Jan is a Friday, the Monday of week 1 is 4-Jan.
If 1-Jan is a Saturday, the Monday of week 1 is 3-Jan.
If 1-Jan is a Sunday, the Monday of week 1 is 2-Jan.
So, at that point it's simple. Good luck!
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
That did the job! Thanks a lot!
Kaloyan
|
|
|
|
|