|
I am not familiar with any of this, however:
1.
getting 0 (success) on some parameter values is good, it indicates your P/Invoke stuff could be correct (or pretty close).
2.
A little Google action led to pages such as this one[^] which states:
All newly defined WAVE types must contain both a fact chunk and an extended wave format description within the 'fmt' chunk. RIFF WAVE files of type WAVE_FORMAT_PCM need not have the extra chunk nor the extended wave format description.
That might be a strong clue, although I couldn't tell you what it really means.
|
|
|
|
|
Is the codec for WAVE_FORMAT_ALAW installed?
Next, some codecs can be used for playback only, not for recording or conversion. On Windows XP, you could try to do the conversion with Windows Audio Recorder in order to find out if it is possible at all.
You might also have a look at NAudio: http://naudio.codeplex.com/[^]
|
|
|
|
|
Bernhard Hiller wrote: Next, some codecs can be used for playback only, not for recording or conversion. On Windows XP, you could try to do the conversion with Windows Audio Recorder in order to find out if it is possible at all.
I'm sure it can be converted.
Bernhard Hiller wrote: Is the codec for WAVE_FORMAT_ALAW installed?
Do you know how to check out if a codec is installed?I am pretty new about this.
|
|
|
|
|
can anyone help please
i am stil trying to read and save images in mysql using C# but no luck... anyone has a resource or sample code in C# ploease
|
|
|
|
|
|
This link[^] discusses what you are looking for.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
hello, with ref to this: A simple histogram displaying control [^ ]
It is a tutorial teaching how to display grey scale histogram of the picture. i manage to do a histogram for separate channel, red, green, blue as shown here: http://yfrog.com/n4histogramj [^ ]
having a qns here how do i get the most occurred min and max value of red, green and blue?
before i can do a comparison and get the min and max, i list the values of the histogram into a list box.
Histogram: http://img220.imageshack.us/i/22953975.jpg/
Listbox: http://img694.imageshack.us/i/64724501.jpg/
i suppose the largest value would be 255 however there is values tt is larger than 255.
needing help.
modified on Saturday, November 20, 2010 11:18 AM
|
|
|
|
|
I'm working in a C# app that uses GhostScript. It's creating black & white TIFF's. I need it to create color TIFF's, but I don't know the appropriate command line switches for that. Any know?
Everything makes sense in someone's mind
|
|
|
|
|
You might get an answer here, but I suggest you post your question on a ghost-script forum in the mean-time. You have a higher chance of getting results there as almost everyone on GhostScript forums are, by definition, solving problems with GhostScript.
|
|
|
|
|
Hi all,
I have tried to open an existing Word 2k10 document in mail merge format.
private object tArg = true;
private object fArg = false;
private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;
sourceDoc = word.Documents.Open(ref oSourceFile,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref wdOpenFormatAllWord,
ref fArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg,
ref mArg);
and then added some tables in it and then save it and close it using .
sourceDoc.Save();
((Microsoft.Office.Interop.Word._Document)sourceDoc).Close(ref tArg, ref wdOriginalFormat, ref fArg);
I am getting an exception on doing the close and HRESULT points to 0x800A140C. Can somebody suggest me any solution for this
|
|
|
|
|
|
Hello Kushagra,
what is the value ofthe variable mArg. It's being used in some places where a boolean is expected, but also as the last parameter where no boolean is expected.
Parameter 11 has to do with encoding (as far as the comments go at least) but it's passed a boolean (fArg). Are your sure all the parameters are of the proper
type and have a meaningfull value?
Supplying a wrong parameter might still allow opening the document, but a subsequent save could fail.
Best Regards,
Manfred
|
|
|
|
|
ManfredRBihy wrote: what is the value ofthe variable mArg. It's being used in some places where a boolean is expected, but also as the last parameter where no boolean is expected.
mArg is nothing but NULL which specifies missing value to let the function decide its own default value. I will look for replacing the right parameters .. meanwhile if you find some good solution on this .. please let me know.
-Kushagra
|
|
|
|
|
I haven't worked with the Word Interop, but I've done quite a bit with Excel Interop, which I would guess is similar...
Instead of using dummy variables for parameters you don't want, use "Type.Missing" instead. For example, here's a line from one of my production systems that saves a file in Excel:
Ref.SaveAs(outputFile, -4143, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
"Ref" points to a Microsoft.Office.Interop.Excel.Workbook, outputFile is just a plain string variable. You shouldn't need to use dummy variables and "ref" keywords for everything.
|
|
|
|
|
I finally got this sorted ... Looks there is some issue with Save() api of WOrd 2010 where its not able to decide which format to save the document in ... I used SaveAs() instead and then closed the Document... which worked wonders in my case..
-Kushagra
|
|
|
|
|
Apparently this issue occurs because the Compatibility Mode feature in Office 2010 (Word, Excel, etc.) has been turned off. I guess there are two ways you can fix this. Turn the Compatibility Mode feature back on or like the previous post mentions use the SaveAs() method instead. Using the SaveAs() method fixed the issue for me:
Microsoft.Office.Interop.Word._Document msWord = new Document();
object filename = "C:\\SomeWordFile.doc";
// Open the document. Perform operations on the msWord object.
// ...
// ...
// When it comes to close the document do something like this:
object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
object missing = System.Reflection.Missing.Value;
object notTrue = false;
msWord.SaveAs(ref filename,
ref fileFormat,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing);
msWord.Close(ref notTrue, ref missing, ref missing);
Hope this helps.
|
|
|
|
|
Just use *.docx instead *.doc for the name of your document and that is it.
|
|
|
|
|
Is there a way to cut down on the individual exception handling code placed in classes and methods so it can be centralized but not result in termination.
I can see that you can use program.cs and put a try/catch around Application.Run. The exception can be caught. This provides a basis for logging and informing the user, but the application still terminates after the catch logic.
You can put an Application.Run in the catch and get it to start over one more time, but the next exception cannot be caught. So its not much use.
The solution I am trying to determine would look something like:
Form1.cs:
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void testMethod()
{
throw new ArgumentException("Invalid parameter");
}
private void nextMethod()
{
}
}
}
Program.cs:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch
{
}
}
}
}
The return to previous level and continue does not seem possible. I am then left with sprinkling exception handling code throughout the application and replicating catch blocks to some degree.
It seems to me that there must be a way to create a centralized exception handler and reduce the number of try/catch blocks overall.
I have read quite a few articles but none seem to address this issue. I realize I can try to reduce the exception handling with logic and rethrow exceptiosn, etc. But this still leaves the issue open for me.
Am I missing something?
Any ideas welcome.
Thanks.
REMEMBER: THIS WAS ORIGINALLY POSTED IN Q/A BY SOMEONE ELSE, AND WAS MOVED HERE BECAUSE A THREADED DISCUSSION WAS MORE APPROPRIATE.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
If all the OP wants is to get the app restarted again, then this should suffice:
static class Program {
[STAThread]
static void Main() {
try {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
} catch(Exception exc) {
somehowLogException(exc);
Application.Restart();
}
}
}
Application.Restart() starts the same app over again, in a new process. The drawbacks should be obvious: the current status will be lost, anything the user has entered/done and wasn't persisted somehow is gone, and some categories of problems will just occur over and over, e.g. a FileNotFound situation typically does not get solved by trying again.
IMO the question doesn't make much sense, there is no general solution to run-time problems, a problem should be handled locally if it can be solved at that level, or propagated up the calling chain.
BTW: very good of you to promote the question from Q&A to a programming forum!
|
|
|
|
|
I missed the Restart Method. Thanks.
In trying this, it starts another instance, and has a dialogue box that pops up if the user creates the same exception repeatedly. The box has retry or quit buttons.
This is helpful.
Thanks.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
To your "does not make much sense" comment
My goal was to try to find a way to cut down on repetitive coding of try/catch/finally blocks by centralizing the exception handling. There is a lot of repetitive coding to deal with exceptions. A lot of exceptions are somewhat routine.
Do you use try/catch/finally in all of your methods and just try to minimize them with logic? or what would you suggest?
Maybe I am not approaching exceptions efficiently?
Thanks.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
The general rule is: One must solve a problem at the level where one can solve the problem. Here is a fictitious example (a simple web browser), first without any error checking, without try/catch. Assume a URL is entered in the appropriate TextBox and some button gets clicked (or the ENTER key gets hit), causing the Navigate method to be called.
class Program {
public static Main() {
Application.Run(new Browser());
}
}
class Browser : Form {
public Navigate(string URL) {
string HTML=GetWebPage(URL);
WebPage page=DecodeHtml(HTML);
ShowPage(page);
}
}
Now assume the HTML is invalid (say a missing </table> tag), so the DecodeHtml method throws an exception, navigate fails, the Exception reaches Main, the app crashes. Good? I don't think so. Now put try/catch in Main. Any better? No, Main cannot solve the problem, all it could do is nicely tell the user "Something went wrong, and I quit (or I restart)", so whatever the user had done till then is lost. Not good.
Now assume Navigate has a separate try/catch around each of its lines; DecodeHtml fails, so page is null, causing ShowPage to either fail or show an empty page. Good? I don't think so, the user expects to see a page, and when some HTML error occurs, he still wants to see as much as possible of that page.
Now have some try/catch inside DecodeHtml(). It could hold a lot of the decoding stuff, and try and guess what was intended, i.e. return a page as well as it can plus signal something isn't quite OK, maybe showing an error message in a status bar. This would be acceptable behavior from the user's point of view. Hence, that is what must be done.
Does this mean, the lowest level must solve all problems? No. It means the lowest level must solve the problems it can deal with well, and it must propagate the ones it cannot adequately handle, to the higher level (the caller).
Another example, not quite about exceptions, more about user errors: a compiler will easily detect your mistakes in the source files you feed it. Do you want the compiler to crash at the first error? You don't. Do you want the compiler to continue compiling and report more errors? You do (up to a point, getting more than 100 error messages isn't really helpful). So the compiler should not give up, it should try and continue to satisfy the user's expectations. And yes, that may take a lot of code.
In the end it is a balance between the user's comfort and the programmer's effort. And IMO the user is much more important than the programmer, as he is the paying customer; and there could be a lot of them.
|
|
|
|
|
Thanks for the guidance.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|
John Simmons / outlaw programmer wrote: It seems to me that there must be a way to create a centralized exception handler and reduce the number of try/catch blocks overall.
There is - in .NET there's an UnhandledException in the AppDomain class which allows you to catch almost all unmanaged exceptions (the exception to this rule, no pun intended, being terminal exceptions such as StackOverflowException ).
|
|
|
|
|
using System;
using System.Security.Permissions;
public class Test {
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Example()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : " + e.Message);
}
throw new Exception("2");
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args) {
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
}
public static void Main() {
Example();
}
}
This works.
If the user recreates the exception (they do pound on the keys and mouse) it does not seem to catch the second throw. Not sure there is a way to deal with that. This helps as part of the solution.
Thanks.
"Coding for fun and profit ... mostly fun"
|
|
|
|
|