|
Hi Leppie,
Thanks for the reply. The reason I pass the first element address because I want to manipulate the value in my COM object. It works fantastically in x86, but doesn't work in x64.
leppie wrote: (does COM not require you to pass the length parameter too?)
You were right, the length of the array must be passed in to the COM object. But in my case (not in this example), it is actually determine by another attribute that is set previously.
leppie wrote:
Your array length is only 5, so how can you read the 6th element?
Uppppsss... you were right again. It should be new int[6]. Sorry...
|
|
|
|
|
Before I begin, I'm a C#/.NET newbie. I'm completely familiar with C/C++ and using VS in that context, but you can probably expect me to have made very trivial errors.
Anyway...
I'm trying to implement a spell check into a tool I'm helping to develop -- I suppose the easiest way to do this would be to use the spell check from Word, so I don't have to duplicate any of its functionality.
I'm working in C#, but the article on this site for a VB.net version (http://www.codeproject.com/KB/office/SpellCheckUsingWord.aspx) helped to walk me through writing it up.
However, there are catches! Apparently, all of the tutorials I've checked out are using a different version of Office (11 instead of 12) which keeps me from compiling.
Here's my relevant code...
ApplicationClass WordApp = new ApplicationClass();
DocumentClass WordDoc = WordApp.Documents.Add();
WordApp.Visible = false;
String OldClipboardText = Clipboard.GetText();
Clipboard.SetDataObject(textBox1.Text);
WordDoc.Content.Paste();
WordDoc.Activate();
WordDoc.CheckSpelling();
WordDoc.Content.Copy();
if (Clipboard.GetDataObject.GetDataPresent(DataFormats.Text))
{
textBox1.Text = CType(Clipboard.GetDataObject.GetData(DataFormats.Text), String);
}
WordDoc.Saved = true;
WordDoc.Close();
WordApp.Quit();
Clipboard.SetDataObject(OldClipboardText);
and here's the compilation log:
------ Build started: Project: StupidSpellcheckSandboxApp, Configuration: Debug Any CPU ------
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(27,41): error CS1501: No overload for method 'Add' takes '0' arguments
c:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll: (Related file)
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(35,17): error CS1501: No overload for method 'CheckSpelling' takes '0' arguments
c:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll: (Related file)
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(38,31): error CS0119: 'System.Windows.Forms.Clipboard.GetDataObject()' is a 'method', which is not valid in the given context
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(40,37): error CS0103: The name 'CType' does not exist in the current context
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(40,53): error CS0119: 'System.Windows.Forms.Clipboard.GetDataObject()' is a 'method', which is not valid in the given context
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(40,94): error CS0118: 'string' is a 'type' but is used like a 'variable'
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(44,17): error CS1501: No overload for method 'Close' takes '0' arguments
c:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll: (Related file)
C:\Documents and Settings\amacdonald\My Documents\Visual Studio 2008\Projects\StupidSpellcheckSandboxApp\StupidSpellcheckSandboxApp\Form1.cs(45,17): error CS1501: No overload for method 'Quit' takes '0' arguments
c:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll: (Related file)
Compile complete -- 8 errors, 0 warnings
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Why is VS crying over the number of arguments? All of the MSDN documentation I've read says that the arguments I leave out are optional. I'm rather exasperated, having been Googling this for a while, either to find a less frustrating method of implementing this (and preferably less hackish than copying and pasting it behind the scenes) or to see if somebody else that figured out what's up with the function parameters, but no luck.
Thanks in advance.
|
|
|
|
|
Alex, one thing I'd say is, are you sure you need to use the full blown Word spell checker? There are plenty of free, more lightweight alternatives out there. (I just searched for C# spell checker and got some articles).
Also, are you aware that WPF (the new UI toolkit part of .NET 3 and up) has text boxes and rich text boxes with built in spell checker?
Now, if none of that dissuades you from using Word's spellchecking, here are my thoughts:
-a couple of the errors are mistranslations from VB.NET, such as the CType one and possibly the "string is a type but is used like a variable". Are you aware there's a C# article showing how to use Word's spellcheck on CodeProject?
-the rest of the compiler errors may be differences between VB.NET and C#, where VB.NET allows for "optional" params, C# doesn't. For cases like this, try passing in the default value (such as null for objects, 0 for ints, false for bools, etc.).
Another thing to check out if you're set on Word's spellchecking is Microsoft's "Visual Studio Tools for Office" set of APIs. Microsoft built some interop dlls and tools for easier interop with Word from C#. Search MSDN for more info.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
|
Alex MacDonald wrote: if (Clipboard.GetDataObject.GetDataPresent(DataFormats.Text)) { textBox1.Text = CType(Clipboard.GetDataObject.GetData(DataFormats.Text), String); }
i guess there are some bracets missing: Clipboard.GetDataObject().GetDataPresent(...
|
|
|
|
|
Hi
i was created a solution in viusal studio 2005, and now i want to change sulotion name, therefore, i was rename my assembly name and default namespace in project properties, also i was changed sultion name in sultion explorer and rebuild my project, but when i open windows explorer to see solution name and folder of my projects, it's still has old name and didn't change, how to change it ?
thanks
|
|
|
|
|
You have to rename them through the file system, e.g. through Windows Explorer.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
Hey everyone. I've been scrounging around on here and finally figured out how to export the data to an excel document from my dataset, the only problem i'm having now is I can't add a new worksheet. I have a data set with that i've filled with three different tables and I need each table to go into a seperate worksheet (so the marketing guys can then use that for their photoshop stuff.) what I have so far is just adding different headers on the same sheet...
Excel.ApplicationClass excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
System.Data.DataTable table = data1.Tables["table1"];
int Collindex = 0;
int rowIndex = 2;
excel.Cells[1, 1] = "table 1";
foreach (System.Data.DataColumn col in table.Columns)
{
Collindex ++;
excel.Cells[2, Collindex] = col.ColumnName;
}
foreach (DataRow row in table.Rows)
{
rowIndex++;
progbar2.PerformStep();
progbar2.Refresh();
Collindex = 0;
foreach (DataColumn col in table.Columns)
{
Collindex ++;
excel.Cells[rowIndex + 1, Collindex] = row[col.ColumnName];
}
}
progbar1.PerformStep();
progbar1.Refresh();
table.Clear();
table = data1.Tables["table2"];
progbar2.Value = 0;
progbar2.Refresh();
progbar2.Maximum = data1.Tables["table2"].Rows.Count;
progbar2.Refresh();
rowIndex = rowIndex + 3;
excel.Cells[rowIndex, 1] = "table 2";
foreach (DataRow row in table.Rows)
{
rowIndex++;
progbar2.PerformStep();
progbar2.Refresh();
Collindex = 0;
foreach (DataColumn col in table.Columns)
{
Collindex++;
excel.Cells[rowIndex + 1, Collindex] = row[col.ColumnName];
}
}
progbar1.PerformStep();
progbar1.Refresh();
table.Clear();
table = data1.Tables["table3"];
progbar2.Value = 0;
progbar2.Refresh();
progbar2.Maximum = data1.Tables["table3"].Rows.Count;
progbar2.Refresh();
label7.Text = "Safety Cover Pricing";
label7.Refresh();
rowIndex = rowIndex + 3;
excel.Cells[rowIndex, 1] = "table3";
foreach (DataRow row in table.Rows)
{
rowIndex++;
progbar2.PerformStep();
progbar2.Refresh();
Collindex = 0;
foreach (DataColumn col in table.Columns)
{
Collindex++;
excel.Cells[rowIndex + 1, Collindex] = row[col.ColumnName];
}
}
I've played around with excel.application.worksheets.add() but can't get the syntax correct (if that's even the right object I want to be working with. I just need a point in the right direction.
Thank you!
|
|
|
|
|
|
Well, I've seen this before and tried it but the compiler yells at me saying missing isn't found in the current context. I even tried replacing globals.thisworkbook with excel.application.workbook but it still gave me the same problem. What I don't understand is why we can't just add a worksheet without passing any parameters.
|
|
|
|
|
workbook.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
The MS example was incomplete. The line above works.
|
|
|
|
|
I am trying to make an application, and I want to have a menu at the top, and then when i click on lets say Start on the menu bar, it changes the window, so that it still has the menu at the top but everything else has changes. I dun want to remake the window, and i dun want to have all of the things in code and just change the visibility.
here is what i thought would work, creating UserControls and then change the UserControl.
UserControl replace = new CreatePage();
this.C = replace;
CreatePage is a page that asks for a bunch of items. Please let me know what i should do.
I do not get any sort of error, but nothing actually changes. Thanks for everyone helps
|
|
|
|
|
Throw your controls on a panel of some sort. When you want to hide them, hide the panel. Voila it's all gone.
WPF forum is over there[^], by the way.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
thanks for the advice, i put it in the C# section because the coding i had was C#.
Still looking for maybe a better solution tho
|
|
|
|
|
I'm not sure I follow, but you should have some type of control (grid, canvas, etc) for your main window. Then based on the event (start menu click, for instance), add or remove your user controls.
For example: You have a Grid named MyGrid in your window, which has multiple row definitions and you want to add a user control (your replace control):
CreatePage replace = new CreatePage();
replace.SetValue(Grid.RowProperty, 2);
this.MyGrid.Children.Add(replace);
|
|
|
|
|
thanks your comments were helpfull, but here is my main predicament. I want to have a starting window. if you click a button it will show you something different. this different thing is called, and is a UserControl.
How it is Called:
void New_Click(object sender, RoutedEventArgs e)
{
this.Grid.Children.Remove(UC);
this.Grid.Children.Add(create);
}
create was already initialized up top, and it has its own xaml and code behind file.
So now the window is populated with all the original information but instead of UC in the main text area, i have put this new createplayer UserControl. Now its going to fill out some information in a form. then you would hit a submit button. I then want it to go back so that UC is the UserControl not create. Everything you entered into this form, is then saved into a class.
What is the best way to do this? Let me know if anything is unclear
|
|
|
|
|
In a mail merge task i am doing, it is desired to have one large file that holds all the merged documents for easy printout. Is there a quick and dirty way to append RTF files together? Thanks.
|
|
|
|
|
Read every file into a rich text box and copy and paste everything together.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
I'm currently developing a desktop application in C# that will be installed on a network drive.
This will cause FileIOPermission error because the users don't have the Full Trust on the Intranet Zone.
I don't want that the user should have to install the SDK to change the settings and wonder then if it possible to change the settings to Full Trust thrue the application?
|
|
|
|
|
Phrone,
I'd think this wouldn't be possible, else you could run any code you want on a persons computer.
Also, you dont need to do this. See link.
MSDN[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
i highly doubt you can change to full trust via an application, i've tried to programatically change a handful of security settings all with negative results. Are you talking about the error you get running a .net program from a network drive because windows doesnt trust .net apps executing from a network drive, or your app is trying to write a file and the user doesnt have write permissions to the network drive? in either event i dont think theres any way to change it from the app, but you may convince whoever is deploying it to give write access to that directory for the latter problem. to solve the former you'll have to deploy it to each computer, or manually tell windows to trust that app on each system. I've had a similar problem before 6 mo or a year ago and couldnt find a work around aside from changing the setting on each computer, so i just told the users they had to locate the app on the system that would run it tho it doesnt sound like that solution will work for you.
|
|
|
|
|
NO AND IT ABSOLUTELY SHOULD NOT BE ALLOWED TO HAPPEN.
Being able to do this would be a road paved in gold for malware writers. "No need to worry about user security settings we can just turn it off for them WOOHOO!"
You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4....
-- El Corazon
|
|
|
|
|
Due to user feedback, Microsoft will be adding this to .NET 3.5 Service Pack 1: .NET 3.5 SP1 apps will run with full trust from the Intranet Zone[^].
.NET 3.5 SP1 will be released this summer, so if you can wait until then, you're all set. Until then, you'd have to setup a .NET security policy.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
It's Through , not Thrue.
There, I'm happy.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hi All,
I have a timer with a interval of 1000 ms and a eventhandler :
timer_updateinterval = new System.Windows.Forms.Timer();
timer_updateinterval.Interval = 1000;
timer_updateinterval.Start();
timer_updateinterval.Tick += new EventHandler(RunTik);
in my RunTik methode i m checking the DateTime.now time and when it's equal to the DateAndTime setted on a lable, there most happen some action:
private void RunTik(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
DateTime start = Convert.ToDateTime(lblStarttime.Text);
if (now.ToString() == start.ToString() | now > start)
{
///do something
}
}
Bud i m gettin the error: index was ouside the bounds of the array on the line:
DateTime now = DateTime.Now;
Can anyone tell my what the problem is and how to slove this?
Thanx.
|
|
|
|
|