|
Please check the format of XML.Not a valid format.No root element is here.
Cheers!!
Brij
|
|
|
|
|
Hello all,
All solved.
I had a slight mistake in the root.
Thank you all
|
|
|
|
|
Hello. I want to learn positions of all elements on a page. I do so:
public class MsHtmlSharpParser {
IHTMLDocument2 htmlDocument;
public HtmlTreeNode htmlTree;
public MsHtmlSharpParser() {
htmlDocument = new HTMLDocumentClass();
}
public void LoadContent(string content) {
htmlDocument.write(new object[] { content });
htmlDocument.close();
((HTMLDocumentClass)htmlDocument).recalc(true);
htmlTree = new HtmlTreeNode((IHTMLDOMNode)htmlDocument.body);
}
}
public class HtmlTreeNode {
public IHTMLDOMNode htmlDomNode;
public List<htmltreenode> children;
internal HtmlTreeNode(IHTMLDOMNode htmlElement) {
this.htmlDomNode = htmlElement;
children = new List<htmltreenode>();
IHTMLDOMChildrenCollection collection = (IHTMLDOMChildrenCollection)htmlElement.childNodes;
int i1, n1 = collection.length;
for(i1=0;i1<n1;i1++)>
children.Add(new HtmlTreeNode((IHTMLDOMNode)collection.item(i1)));
}
public void GetAbsolutePosition(out int x, out int y, out int width, out int height) {
if (htmlDomNode is IHTMLElement) {
x = 0;
y = 0;
x = ((IHTMLElement)htmlDomNode).offsetLeft;
y = ((IHTMLElement)htmlDomNode).offsetTop;
IHTMLElement offsetParent = ((IHTMLElement)htmlDomNode).offsetParent;
IHTMLDOMNode parentNode = htmlDomNode.parentNode;
while (offsetParent != null) {
x += offsetParent.offsetLeft;
y += offsetParent.offsetTop;
parentNode = ((IHTMLDOMNode)offsetParent).parentNode;
offsetParent = offsetParent.offsetParent;
}
width = ((IHTMLElement)htmlDomNode).offsetWidth;
height = ((IHTMLElement)htmlDomNode).offsetHeight;
} else
x = y = width = height = -1;
}
}</htmltreenode></htmltreenode>
I call LoadContent to load html page and parse it. It works successifully, the object tree is built. But if I try to call GetAbsolutePosition, I will see that offsetHeight, offsetWidth, offsetLeft and offsetTop always return zero. Why is it so and how to solve this problem?
Thank you.
|
|
|
|
|
I've got a C dll which has a SetCallback function and I need to implement this from within a .NET C# app.
Basicly the C# app needs to pass a function pointer to the C dll so that the dll can "do stuff" and then notify the C# app that it is complete by calling the function.
I came across this[^] article and was thinking "this is exactly what I want to do. Of course I had some problems implementing it (couple typos in the article as detailed in the comments. But as I was reading the comments, I got down to the comments by leppie and Heath Stewart indicating that it isn't the proper way to do this.
So now, with all that said....my question is...Whats the proper or "right" way to call a Function within a .NET C# app from within an unmanaged C dll using a function pointer?
|
|
|
|
|
kinar wrote: Whats the proper or "right" way to call a Function within a .NET C# app from within an unmanaged C dll using a function pointer?
I don't know, but I would use a C++/CLI assembly to deal with the issue at a mixed mode level rather than directly from C#.
Good luck.
led mike
|
|
|
|
|
Heh, unfortunately I'm in one of those situations where I don't get to make that choice.
|
|
|
|
|
kinar wrote: Heh, unfortunately I'm in one of those situations where I don't get to make that choice.
What? Are you the developer? Develop the solution, when it works none of the monkeys will care how you did it.
led mike
|
|
|
|
|
I've got a unique situation where the only people who use my product are other developers and I have to help them figure out how to get things working.
I'm the developer of the DLL but there are a thousand other developers already out there who are using it in just about every language under the sun (including C# but this is the first time I've come across someone trying to use it "this way").
|
|
|
|
|
kinar wrote: including C# but this is the first time I've come across someone trying to use it "this way"
I don't know what "this way" means? If your DLL has a SetCallback function and people are using it from C# then how is this case any different?
IMHO, as a vendor of a Native DLL, if you want it accessible from .NET languages, best practice is to wrap it in a .NET assembly, like I already said, giving .NET developers first class .NET classes to work with rather than having to do the interop themselves.
led mike
|
|
|
|
|
Sorry for not being clear. Since we support so many different languages and development environments, the DLL has other methodology to accomplish the same task which works fine within a Winforms app.
I've got someone who would like to use the callback instead but is having problems and I was searching for ways to help him with this.
Wrapping the DLL in a .NET assembly may be the only option, however on the surface it seems like this would just move the problem from the 3rd party code into our code and I would still need to figure out howto use the callback within .NET. Unless, rather than "wrapping", you were talking about creating a whole new .NET assembly that duplicates all of the functionality of the native DLL.
|
|
|
|
|
kinar wrote: Unless, rather than "wrapping", you were talking about creating a whole new .NET assembly that duplicates all of the functionality of the native DLL.
No, but you could accept it would not duplicate the code just the compiled version of it. I was originally thinking about option #1 below.
The following assemblies are C++/CLI mixed mode that publish .NET classes, interfaces (whatever is required) with the differences as follows:
1) Just wrap - Linked to the original Native DLL (via dynamic link library .lib) and includes any header files.
2) Static link - Linked to the static link library (.lib) that can be produced by the same Native DLL project and includes any header files.
3) Share source code - Shares the same source code files (using source control tool) of the Native DLL project.
led mike
|
|
|
|
|
I'm still "not getting" what this accomplishes...
From what I understand the concept of using callbacks to call into a .NET app doesn't work well.
Wouldn't you still have the same problem even if it was a .NET assembly doing the calling?
I guess I don't know enough about the .NET side of things to even know what to research at this point.
I understand everything you are saying, but I'm missing the key bit of information that brings it all together.
|
|
|
|
|
kinar wrote: From what I understand the concept of using callbacks to call into a .NET app doesn't work well.
Then you misunderstand, it works perfectly well.
There are any number of mechanisms that can be used. interface, delegate, event. interface works just like it does in C++, you can start learning about delegates and events in this link.[^]
By developing which ever mechanisms you need in a C++/CLI mixed mode assembly, you greatly simplify the users job since you are providing .NET Managed items for them to work with rather than Native C functions they have to use PInvoke to use. You handle all the marshaling internally and the user is not burdened with any of it. As I stated earlier, IMHO, that's what you do if you build a library.
led mike
|
|
|
|
|
I am familair with delegates and events, I guess I just wasn't aware that they work well across assemblies. Previously I have used them for Interop between .NET assemblies and a COM object (or rather the .NET assembly object that is created with VS "autowraps" a COM object).
led mike wrote: By developing which ever mechanisms you need in a C++/CLI mixed mode assembly, you greatly simplify the users job since you are providing .NET Managed items for them to work with rather than Native C functions they have to use PInvoke to use.
I certainly agree that this is "best practice". However, doesn't that mean that my wrapper is required to use the PInvoke to use it? I mean, that code has to exist somewhere right? Or is it more of an issue that by using a mixed mode assembly, I can use the callback in the same way that I would from a standard C/C++ app and then I can expose some other methodology within the assembly to handle the .NET delegate reference that is set within the 3rd party .NET assembly?
I'm not really familiar with mixed mode assemblies but I believe I have a book on using C++ with CLI that I might need to dig through.
Anyway, thanks for your help. I'm sure you've already spent far more time on this thread than you expected
|
|
|
|
|
kinar wrote: However, doesn't that mean that my wrapper is required to use the PInvoke to use it?
No. In mixed mode C++/CLI your code is a first class citizen of both Managed and Native environments.
kinar wrote: Or is it more of an issue that by using a mixed mode assembly, I can use the callback in the same way that I would from a standard C/C++ app and then I can expose some other methodology within the assembly to handle the .NET delegate reference that is set within the 3rd party .NET assembly?
Don't know what 3rd party .NET assembly you are talking about. Yes as I stated above. Using C++/CLI your assembly will publish .NET items to users of the assembly from the .NET platform. However internally you have Native C/C++ code access to any and all API's that you make visible by including the source or libraries same as with a pure Native source or library. All you have to account for is marshalling the memory which the .NET Base Class library provides mechansisms for doing so even that is simple.
kinar wrote: Anyway, thanks for your help. I'm sure you've already spent far more time on this thread than you expected
Not a problem, you are welcome.
led mike
|
|
|
|
|
hi,
i am developing a WindowsApplication that when the user clicks on a ListViewItem a Form opens just on the position of the ListViewItem
does any one know how is it possible to find out which point on the screen is the control location so i could tell the form where to open?
The Control.Position property is not good enough since the control is in a few panels....
The MouseDown event is not good either since this action is accessible thru a context menu strip (which on this case the "MenuItem" may be lower than the ListViewItem)
|
|
|
|
|
Hi ...
I am not sure if I understood you very well ... but what I understood is that you want to show a form where its upper left corner shall be in the upper left corner of a control on the form ... so it comes above it somehow ... anyway ... find the code below and I hope it helps:
Form2 frm = new Form2();
frm.StartPosition = FormStartPosition.Manual;
frm.Location = this.textBox1.PointToScreen(this.textBox1.ClientRectangle.Location);
frm.Show();
This will place it exactly at the upper left corner of the control which including the titlebar ... in case you dont want to have the title bar to be it and the client region of the control use this instead:
Form2 frm = new Form2();
frm.StartPosition = FormStartPosition.Manual;
frm.Location = new Point (this.textBox1.X+this.Location.X,this.textBox1.Location.Y+this.Location.Y);
frm.Show();
I hope this helps ...
Sincerely Samer Abu Rabie
Note: Please remember to rate this post to help others whom reading it.
|
|
|
|
|
Hello All,
I need help for the following subject:
I will insert a HW into usb port of my PC, and I want my program to automatically detect the HW and give me the Port Name (or number) and some inforrmation about the inserted HW?
Thanks,
|
|
|
|
|
|
Hi,
Write WndProc in the code and check for device attached/detached event.(There is one event for this. Try to search on net.)
After getting event write a code to read registry for com port information.
When an device is plugged to USB port an entry is made in the registry.
HKEY_LOCAL_MACHINE/DEVICEMAP/SERIALCOMM
So, you can listen for the changes in this key. And will get to know com port at which device is attached.
|
|
|
|
|
as i said i have a form and textbox. in the textbox i write greek characters and i want to write this textbox into a file.txt
if a save a greek word in the file.text it writes question marks(???????)
please help me. what i have to configure?
|
|
|
|
|
You need to encode your text file as ISO-8859-7 .
I think StreamWriter takes encoding as its parameter.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
i just use
bt is a byte border which i encoded it
bt = System.Text.Encoding.ASCII.GetBytes(s);
s is the textbox for example
filestream.Write(bt, 0, bt.Length);
|
|
|
|
|
I don't know a lot about Encoding but I think ISO-8859-7 and ASCII are not the same. Try this:
StreamWriter sw = new StreamWriter(@"C:\GreekTest.txt", flase, Encoding.GetEncoding("ISO-8859-7"));
sw.WriteLine("αβγδε");
sw.Close();
StreamReader sr = new StreamReader(@"C:\GreekTest.txt", Encoding.GetEncoding("ISO-8859-7"));
Console.WriteLine(sr.ReadLine());
sr.Close();
It worked for me. Hope help you.
Life is 5: 3 me, 1 you.
|
|
|
|
|
Hi
is it posible to make longer timeout connection ?
i'll try to wright: conn.ConnectionTimeout = 30;
buy it "Read Only" and send me an Error
how can i do it ?
|
|
|
|