|
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 ?
|
|
|
|
|
E_Gold wrote: is it posible to make longer timeout connection ?
Connection timeout is part of the connection string. Try defining "...Connection Timeout = 60..." (60 seconds) in the connection string.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
|
I am filling dataset from excel. But all rows are not appearing in dataset. Because I am having Numbers and characters in same column in Excel.
But In dataset I am getting only numbers in that column. So please help how can I have All rows in dataset.
Snapshot is attached with code: http://i33.tinypic.com/294nrew.jpg
Thanks.
Manoj
|
|
|
|
|
I recall there is some setting in the connection string that helps with this issue.
It is the IMEX=1 setting. Not sure if 1 was the correct value, but a few searches should present the correct answer.
http://www.connectionstrings.com/?carrier=excel[^]
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Thanks it is working.
strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + txtUrl.Text + ";" +
"Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
|
|
|
|
|
I used several forms in my project.
I have one big problem: when I want to click the button on the non-activated form (i.e., non-current form), then I have to click two times (first time just activate the form and it works only for the second click). Actually, for most softeares we use everyday, we only need to click once even the button on the form is not activated or not current form.
I have tried several functions, but non works. I think most people will meet this problem. I really don't know how do you solve this?
thanks.
|
|
|
|
|
You can activate the form on hover.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Which is faster? I have a class that loops through consitantly monitoring input and filters down tot he correct path based off multiple factors, I noticed now that my paths that are down the nested if by 7 or 8 layers take as long as 2 seconds to execute.
Will porting over my code to select / case statements increase efficiency?
|
|
|
|
|
I prefer if statements for non-numeric comparisons and case statements for integral comparisons of large sets. Likely the code slowness is due to algorithm inefficiency than control-flow structure as .NET uses a nifty cheat to make cases work fast on strings. Post some code.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
For me, it's a matter of readability, and then suitability of purpose. Heavily nested if statements are generally harder to read than a switch statement. Unless I feel a crying need to use if (less than three nested if's), I'll use a switch statement.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
So there is no actual efficiency when using a select case over a bunch of if statements?
|
|
|
|
|
I don't know if you'd notice an efficiency using either one unless you were going to have more a handful of cases. Most of my switch statements never exceed more than a dozen cases.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
EliottA wrote: So there is no actual efficiency when using a select case over a bunch of if statements?
In your situation, there is no "actual efficiency" in terms of performance using if statements vs using switch statements. If your deepest loops are taking 2 seconds to execute, switching from if to switch may improve your execution time by the tiniest fraction of a millisecond.
But that's besides the point. Unless you absolutely need to shave milliseconds off your code, decisions about how your code is organized should be about readability and communicating your intent to future readers of the code. Don't prematurely optimize.
That aside, there is more opportunity for a compiler to optimize long switch statements than with a series of if statements. The compiler will typically convert if statements into a series of compare-and-jump operations. Switch statements (in C#) can be implemented using techniques like jump tables (when comparing int s) or hash tables (when comparing string s) to increase code efficiency. But we're talking about real low-level, behind-the-scenes stuff that the average developer will likely never have to consider in real-world applications.
Enjoy,
Robert C. Cartaino
|
|
|
|