|
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 ?
|
|
|
|
|
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?
|
|
|
|