|
Ah, in which case if you are using Visal Studio, just add a COM reference to the project (right click references>Add reference>COM Tab>Browse) and VS will do the rest for you, allowing you to call the COM object as if it were a .NET class. Visual Studio just does some boiler-plating for you.
eg, if I did this with ADODB.COnnection I could go
ADODB.ConnectionClass myConn = new ADODB.ConnectionClass();
note it adds the suffix "Class" to the COM Object's true name.
|
|
|
|
|
Actually I've tried to import the dll and the tlb file, but I got an error message, BUT I did find a solution:
Import the Microsoft.VisualBasic Object (yes, I know )
and use the following (example)
object idisp;<br />
<br />
try{<br />
idisp = Interaction.CreateObject("idisp.Command", null);<br />
bidisp = true;<br />
}<br />
catch(Exception e){<br />
bidisp = false;<br />
MessageBox.Show(e + "");<br />
}
And it worked .
I'm not sure if there is a complete C# solution.
tnx for the effort!!
No hurries, no worries.
|
|
|
|
|
I examined the CreateObject class, and doing the same without it is not so hard:
object idisp;<br />
bool bidisp;<br />
<br />
try {<br />
idisp = Activator.CreateInstance(Type.GetTypeFromProgID("idisp.Command"));<br />
bidisp = true;<br />
} catch (Exception e) {<br />
bidisp = false;<br />
MessageBox.Show(e + "");<br />
}
---
b { font-weight: normal; }
|
|
|
|
|
Try the SQL/ADO forum for more info.
BUT here's what I have done:
ODBC - Easy to do in C#, there are tons of article here. Worst part is the DSN as you eithe rhave to manually provision it OR use on of the autmation techniques you find on CodeProject - and trust me when I say there are a few. You can use this with MySQL, or other non Microsoft DBs as opposed to delving into the C based APIs. If your app is running on say Linux this might be a good option.
OLE DB - Not really for your relational databases per se, but if you have data stores like Excel or other spreadsheets, or office files, it works great and again pretty easily once you know the finer configuration points.
SQLClient - If you are using SQL Server then this is probably the best route because of the inherent support.
All of the options Odbc, OleDb, and SqlClient have a similar data model. You should be able to find code here, of course on MSDN, and throughout other sites.
Good luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
tnx but I'm not going to the db, it was the CreateObject I needed and so far I was succesful (see complete thread)
tnx!
No hurries, no worries.
|
|
|
|
|
Hi all C# Gurus,
Is it possible to rotate images using GDI or anything else.
If yes (it must be) then please guide me through the process.
Also, it would be nice if anyone can tell me how to read from XML files.
Or alternately, please let me know any article on the same which i have surely missed .
Thanks in advance.
Any help will be highly appreciated.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
Hello!!
Well about rotate images i know a library in C# where you can draw many figures and insert images and you can rotate, scale and a lot more it's pretty cool:
http://www.cs.umd.edu/hcil/piccolo/[^]
Regards,
Alberto Martinez
|
|
|
|
|
An easy way to draw rotated image is to use transformations:
Graphics g = ...;
g.RotateTransform(angle);
g.DrawImage(...)
if you want to rotate around any point, you can use matrix.
Matrix m = new Matrix();
m.RotateAt(angle, new PointF(x, y));
g.Transform = m;
g.DrawImage(...);
|
|
|
|
|
When working with a C# project, is it possible to get the exact path of the currently open project via code so that it can be displayed say in a messagebox or a textbox ??
|
|
|
|
|
hope this will help you
MessageBox.Show(Application.ExecutablePath.ToString());
this wil return the path of exe
-- modified at 7:56 Friday 17th March, 2006
|
|
|
|
|
Hi,
Can you please specify what did you mean by 'currently open project'? Do you want to know the physical path in Visual Studio .Net? or when you are running the application?
Jim
Work smart, not hard
|
|
|
|
|
Hi gurus,
I have an automation add-in created using C# for Excel, in which I am
exposing a number of functions. Is there any way I can add help-text
the way excel does for other categories like Financial, Statistical,
etc.
The place I want my help-text to be available is in the
Insert->Function. Here, we can select a category and function. The
corresponding help text is displayed. Now, my automation add-in is
also listed in this categories. I want help text to be displayed when a
user selects my add-in and functions in it.
I tried the MacroOptions method, but it is raising an exception.
This is the code I tried (I tried both early binding and late binding):
early binding:
code:
_excelApplication.MacroOptions("Report_Alloc", "custom description", Missing.Value,
Missing.Value, Missing.Value, Missing.Value, "Report.Report", Missing.Value, Missing.Value, Missing.Value);
Exception Message: "Exception from HRESULT: 0x800A03EC."
StackTrace " at Microsoft.Office.Interop.Excel._Application.MacroOptions(Object Macro, Object Description, Object HasMenu, Object MenuText, Object HasShortcutKey, Object ShortcutKey, Object Category, Object StatusBar, Object HelpContextID, Object HelpFile)\r\n at .......
late binding:
code:
object[] parameters = new object[10];
parameters[0] = "Report_Alloc";
parameters[1] = "Some sample description...";
parameters[2] = Missing.Value;
parameters[3] = Missing.Value;
parameters[4] = Missing.Value;
parameters[5] = Missing.Value;
parameters[6] = "Report.Report";
parameters[7] = Missing.Value;
parameters[8] = Missing.Value;
parameters[9] = Missing.Value;
_excelApplication.GetType().InvokeMember("MacroOptions", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, _excelApplication, parameters, new System.Globalization.CultureInfo("en-US"));
Exception Message: "Exception has been thrown by the target of an invocation."
StackTrace " at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)\r\n at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)\r\n at ......
Inner Exception Message: "MacroOptions method of Application class failed"
Any help would be appreciated.....
Jim
|
|
|
|
|
Does anyone of you can tell why the following code:
private void HandleKeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
char c = e.KeyChar;<br />
<br />
if(c == (short)Keys.Back)<br />
{<br />
e.Handled = true;<br />
SendKeys.Send("{LEFT}");<br />
return;<br />
}<br />
}
works in common textBox but it doesn`t work in richTextBox?
In textBox line e.Handled = true; stops the backspace key action and only action after pressing bakcspace key is move the cursor to left (SendKeys.Send("{LEFT}"); ).
In richTextBox it`s taken double action. e.Handled = true; code doesn`t block backspace key action so:
1) first it deletes character (backspace key do it - it isn`t block)
2) second it moves the cursor to left (like SendKeys.Send("{LEFT}"); code do)
Can anyone figure out what`s wrong with it?
|
|
|
|
|
Try this
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Back))
{
e.SuppressKeyPress = true;
SendKeys.Send("{LEFT}");
return;
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Back))
{
e.SuppressKeyPress = true;
SendKeys.Send("{LEFT}");
return;
}
}
|
|
|
|
|
It`s working
Thank you very much
But code
e.SuppressKeyPress = true; I turned into e.Handled = true;
-- modified at 9:50 Friday 17th March, 2006
|
|
|
|
|
Hello!
how can i show and hide a Quick Launch Toolbar or Desktop Toolbar (which are present in the TaskBar Context Menu --> ToolBar) using C# application.
|
|
|
|
|
Hello!
I have wrote a code in which i m trying to hide the Notification icon when i click on the context menu (which pops on that icon). BUt in this manner two events fire. One which is my event written in the code(which works according to my requirement) and other is the Windows own event, which is Taskbar Popup menu. which always seems bad. if i call any messagebox after that fired events, the windows event hide but i don't want to show message box. Please help me.
|
|
|
|
|
Hi,
Sorry to disappoint you, but i wanted to ask my own question in this.
Are you able to detect when the user is clicking on the window in the taskbar?
Actually, i have made a program in which i have made the FormBorderStyle as None. This prevents the system menu to appear when i click on the window in the taskbar.
So, i wanted to figure out a way in which i could detect a click on the taskbar window and display the menu manually.
Please let me know, if you happen to know about this.
Thanks in advance.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
|
I think, i am getting your problem.
See, when you pop-up the message box, the event is still being fired and it still shows the taskbar menu too, but the message box removes the focus and hence makes the taskbar menu disappear.
Secondly, the fact that the taskbar menu is appearing shows that you are able to hide the icon successfully, but somehow another event is being generated which is being sent again.
I am not sure about how this is happening, but i guess, you can refer to this article[^] for more details.
Also, i hope, you are using the NotifyIcon control. It saves a lot of time.
I hope this helps.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
Hello!
I have wrote a code in which i m trying to hide the Notification icon when i click on the context menu (which pops on that icon). BUt in this manner two events fire. One which is my event written in the code(which works according to my requirement) and other is the Windows own event, which is Taskbar Popup menu. which always seems bad. if i call any messagebox after that fired events, the windows event hide but i don't want to show message box. Please help me.
|
|
|
|
|
I want to know my opened ports in my local machine.How can i identify the opened port numbers with out using my ip address.If i use my IP address to
get the ports,it will make port scanning.I can't use port scanning concept.
If u know any other concept related to this Pleas Repaly fastttttttttt
Deepthi
Deepthi
|
|
|
|
|
I think this will solve your problem :
try {
int port = FindUnusedPort(IPAdress.Any);
}
catch (SocketException) {
// no free ports
}
...
using System;
using System.Net;
using System.Net.Sockets;
...
public int FindUnusedPort(IPAddress localAddr) {
for (int p = 1024; p <= IPEndPoint.MaxPort; p++) {
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
try {
s.Bind(new IPEndPoint(localAddr, p));
s.Close();
return p;
}
catch (SocketException ex) {
// EADDRINUSE?
if (ex.ErrorCode == 10048)
continue;
else
throw;
}
}
throw new SocketException(10048);
}
Cheers
JIjo
|
|
|
|
|
|
I want help in opennig only one child file at a time. My application irritates me when there are too many child forms open.
I added this code (on all the menu items) to open only one, but the problem is that, I can't open another child while there is a child active. How do you control that ?
Interfaces - Is the folder Name where all forms are located
frmPerson - is the child form (requered form to open)
private void mnuManagePerson_Click(object sender, System.EventArgs e)
{
if (Interfaces.frmPerson.ActiveForm.ActiveMdiChild == null)
{
Form frmchildfrmPerson=new Interfaces.frmPerson();
frmchildfrmPerson.MdiParent = this;
frmchildfrmPerson.Show();
}
}
Cool Joe
"Only the best"
South Africa
-- modified at 5:12 Friday 17th March, 2006
|
|
|
|
|