|
Create a key pair using sn.exe -k KeyFile.snk. When you generate an interop assembly, use the /keyfile:<filepath> switch to both tlbimp.exe and aximp.exe (if importing an ActiveX control to derive from AxHost as well). If you're doing this from within VS.NET, go to the project configuration and in there is a place you can either entire a file path (relative to the project root) or a key container name. I typically install my key into my machine store using sn.exe -i KeyFile.snk MyContainerName (obvious use a container name you want).
I would delete the interop assemblies you've already created and regenerate them as I've mentioned here. Also be sure you use a key pair (possibly the same one - it helps identify your assemblies, though it's not verifiable like X.509 certificates). A strong name requires that the assembly be signed, which you seem to already know. A strongly named assembly can only use strongly named assemblies.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
A quick question about the oleDbDataAdapter. Is it a good idea to use these in threads to update a dataset? I notice that if I am running concurrent threads where each uses an adapter to fill a dataset, the first thread will work, and the second thread (different adapter and dataset, but same connection) will run, but nothing will be put into my dataset. Obviously the second thread cannot fill its dataset because the connection is open from the first thread. I understand why the adapter isn't filling my dataset, but I'm sort of shocked it would just skip the fill command without giving any indication that it did so. What is the int that the Fill function returns anyway? Can I use that number to determine if the function actually did its job? And if so, what would be the best way to go about using adapters in threads...right now I'm locking them down until the connection is free...is there a better way? Just curious, thanks a bunch!
|
|
|
|
|
When using the System.Data.OleDb classes, your options are limited because of the abstraction that OLE DB provides (basically the whole purpose of its existence). With the System.Data.SqlClient classes this really isn't a problem.
You might check if the OLE DB provider for whatever you're connecting to supports connection pooling or limitations that might help in this situation. The properties that you pass to your connection string are used by the OLE DB provider for your data source.
Other than that, locking against a shared resource (such as a static property of some class) or using a delegation approach to create and execute commands and / or adapters (and synchronizing them internally) are about your only options. It's the OLE DB provider for your data source here that is the problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've been writing a desktop sharing engine for .NET (pcanywhere sort of deal) . . . and I rely on the region class heavily for accumulating change rectangles (which I pull from the region class using the GetRegionScans method). I recently ran into the memory leak bug located in the GDI+ GetRegionScans call (see http://www.bobpowell.net/getregionscansbug.htm [^]for more details). Has anybody found a reasonable alternative to this bug? If not, any ideas or documentation on region minimal spanning rectangle algorithms?
Thanks!
-Guy
Senior Research Scientist
http://www.perspectivelabs.com
|
|
|
|
|
There must be a way?
I've written many "NT Service" programs with VB6 and most have some sort of user interface. They all have an icon in the tray to indicate 'I'm running'.
Now comes C#. I've written the service and installed it, but I'm having one hard time trying to figure out how to have some UI involved. I've triggered threads in the onStart() that toggle between a non-visible form which holds a notifyicon and a UI. Clicking on the icon shows a form, closing the form reloads the icon in the tray, perfect. However, after logging off then logging back on the icon moved to bit heaven, I'm assuming because there was nothing left to hold it and I don't know how to reload the form from within its called method.
In VB6, its as simple as using a timer to keep attempting to put the icon in the tray. If there's an error nobodys logged in, no place to put the icon, so try again in a few seconds. When there's no error, someone must have logged in.
I don't know how to see if a user has logged on to re-start the method I don't know how to write!
There's got to be a way to simply have a "service process", owned and operated by the 'system' display its own icon from its own process when it knows its running and have it be there after a user logs back on. I stress owned by the "system" because due permissions available on the target machine, the polling of service manager with normal user rights can not be done. These boxes are really locked down, so the administrator has to install the program and the system has to run it.
Can anyone please help?
|
|
|
|
|
|
I have two separate combo boxes and I would like to create one function to populate them.
I would like to be able to pass a combobox control and use it.
I.E.
void LoadDD(<no sure=""> <ddname>)
{
string[] dirs = Directory.GetDirectories("\\Family");
foreach (string dir in dirs)
{
<ddname>.Items.Add(new ListItem(GetName(dir), dir));
}
}
Any ideas??
|
|
|
|
|
You almost had it. If you want to tie the method to a particular control:
void LoadData(ComboBox box)
{
string[] dirs = Directory.GetDirectories("\\Family");
foreach(string dir in dirs)
{
box.Items.Add(new ListItem(GetName(dir), dir));
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
I have an ArrayList. At some point I wish to copy all of it's items to a new ArrayList. I could probably loop through all objects in the ArrayList but isn't there a faster way (it seems to be a bit stupid method) ?
Just to explane why I need this: I'm translating an old Visual C++ MFC program into C# (with blessings of the original author). I ran into an object CArray that is an usual array but is capable of growing and shrinking dynamically. Anyway, at some point the thing copies itself into another CArray. There's no equivalent for that in C# as far as I know. Code:
oldArr.Copy(newArr);
oldArr.RemoveAll;
Regards, Desmond
|
|
|
|
|
ArrayList oldArr = new ArrayList();
oldArr.AddRange( new string[] {"hello", "world!"} );
ArrayList newArr = new ArrayList(oldArr);
Console.WriteLine(newArr[0].ToString());
Additionally, you can use the .CopyTo method, using an array as a temporary buffer, or as a the destination array itself:
ArrayList list = new ArrayList();
list.AddRange( new string[] {"hello", "world"} );
string[] tempArr = new string[2];
list.CopyTo(tempArr);
ArrayList list2 = new ArrayList(tempArr);
MessageBox.Show(list2[0].ToString());
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Doesn't this make a swallow copy instead of a deep copy ?
|
|
|
|
|
Yes, so long as what the ArrayList contains are reference types. If you want to perform a deep copy, you could do something like this:
private ArrayList Copy(ArrayList list)
{
if (list == null) throw new ArgumentNullException("list");
ArrayList copy = (ArrayList)list.Clone();
for (int i=0; i<copy.Count; i++)
if (copy[i] is ICloneable) copy[i] = ((ICloneable)copy[i]).Clone();
return copy;
} So long as the objects that the list contains are cloneable, you'll clones depending on the internal implement (perhaps deep or only partly deep).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Or just call ArrayList.Clone .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to draw RTF text in my custom UserControl without actually having a RichTextBox window. I have seen a couple articles on the web about creating a windowless RichTextBox by supplying it with a custom ITextHost interface (see http://www.codeguru.com/Cpp/controls/richedit/windowless/article.php/c5367).
The problem is, these examples are for c++ and I am wondering how one could go about doing this from C#. Is there a way to somehow import the ITextHost interface from the control? Does anybody have any clue to point me in the right direction? (and no, I am not above using unmanaged code to get this to work).
Or is there a better way to accomplish this?
Thanks in advance!
Michael
Developer, Author, Chef
|
|
|
|
|
.NET is a natural progression from COM, and can easily interop with COM. Read Interoperating with Unmanaged Code[^] in the .NET Framework SDK for basic information on these concepts.
Also, be sure to read Windowless Rich Edit Controls[^] in the Platform SDK for details information, not just examples.
First, you should consider encapsulating both the CreateTextServices API as well as the implementation of ITextHost in a class to make it easy to use. You then need to declare the ITextHost and, optionally (though recommended), ITextServices interfaces in C#. An example of (part, since it's so long) of ITextHost host looks like this (methods must be in order since this interface inherits from IUnknown and methods must be in the proper VTBL order):
[Guid("c5bdd8d0-d26e-11ce-a89d-00aa006cadc5")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITextHost
{
IntPtr TxGetDC();
IntPtr TxReleaseDC(IntPtr hdc);
bool TxShowScrollBar(IntPtr fnBar, bool fShow);
} Be sure you know the conversion from unmanaged to managed data types. For example, many of the methods use INT , which is not necessarily 32 bits. It is system dependent, just like IntPtr . You can also use a Int64 (long ) and use MarshalAs(UnmanagedType.SysInt) which would make it easier and should work well for many, many years (since 64-bit processors are just starting to hit main-stream on the x86 platform supported by current CLI implementations).
The CreateTextServices factory function would look like this:
[DllImport("riched20.dll")]
private static extern int CreateTextServices(
[MarshalAs(UnmanagedType.IUnknown)] object punkOuter,
ITextHost pITextHost,
[MarshalAs(UnmanagedType.IUnknown), Out] out object ppUnk); You could also use IntPtr instead of object and then use appropriate methods from the System.Runtime.InteropServices.Marshal class to get the information you need. Note that you do not need to implement IUnknown on your object. The CLR does this for you. Note that the out object is a pointer to a pointer that returns either a ITextService or ITextDocument implementation. If you re-declare these in managed code, you can simply cast the output object to these interfaces (or use the as operator). If the cast return null (or throws an exception), then then interface it not supported. The CLR performs the QueryInterface for you automatically.
When you start looking at all the structs, consts, and other interfaces you would need to implement for full support, I'm sure you'll see why there isn't a .NET implementation! It's much easier in C++ where you can include the headers that contain all these definitions for you and don't have to worry about marshaling (all that would be handled by the COM runtime).
If you decide to venture this way, be sure to have a good working knowledge of COM interoperability in .NET.
You might consider using a mixed-mode MC++ (Managed C++ assembly) that can include the necessary headers and aggregate the methods you need on a __gc class (since a managed class can't implement an unmanaged interface like ITextHost . You could easily use the resulting assembly from any other .NET language like C#. There's still be a lot fo to, but this will probably be a much easier approach.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
You had 49 minutes (since I posted) to think about and write a response and that is all you could manage?
Seriously, many many many many thanks for the tips and pointers. I will be looking into this as you suggest. If I manage to get this working well, I will share the info in the form of an article.
Again, thanks thanks thanks for setting me down the right path!
Michael
Developer, Author, Chef
|
|
|
|
|
|
Heath Stewart wrote:
Sorry it took so long!
Practice makes perfect!
- Nick Parker My Blog | My Articles
|
|
|
|
|
Heath,
1) Just wanted to let you know that I was successful in taking the second route you outlined. I initially spent about 2 hours trying to get everything defined in C#. This was a bit of a nightmare as you suggested. Then I spent about 10 minutes doing it as a mixed-mode MC++ class library, and exposing the routines I needed. Works like a charm! In the future, I plan revisit the c# way (to eliminate the mc++ dll and learn what I was doing wrong), but for now this is completely workable. Thanks for the previous advice.
2) 5 Years ago I was lucky enough to take a 1 year sabbatical. What did I do? Since I was about to turn 30 I decided I wanted to see the world, but learn something as well. Since I have always cooked, I decided to go to Paris and attend culinary school at Le Cordon Bleu. I heartily reccommend it for burned-out developers! Amazing time, amazing people, amazing food, and an amazing amount of work. The only problem: Software pays way too much to let it go completely! So I heartily applaud the mid-life career change, but I warn you that you will find it hard to let go of your current one.
Thanks again!
Michael
Developer, Author, Chef
|
|
|
|
|
Mwolski wrote:
...but I warn you that you will find it hard to let go of your current one
I don't think I'll have any problems letting go of the chest pains, irregular heart beat, headaches, stiff joints, tendenitous, and stress. Money is a slight factor, but hopefully these stock options pay-out.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Any sample C# speech recognition source code with speech input through fourier transforms anywhere? Thanks all.
|
|
|
|
|
Many, many moons ago on http://research.microsoft.com[^] the Speech SDK was posted with some COM controls that made interaction with TTS and STT engines easy. Much of this went into Microsoft Agent.
Recently, Microsoft created its Speach Server[^] which uses the newer Speech SDK and technology for voice technologies (their answer to VoiceML, I guess). Unfortunately, it doesn't seem to leverage the same component-based technology that previous versions did so that you could use it with, say, a Windows Forms application. You could, however, use the older, stable versions (4.0 I think? ...it's been a while since I've used the Speech SDK in anything) to create RCWs (runtime-callable wrappers) from the COM components and use that.
The Microsoft Speech API is pretty good and has a much smaller footprint than IBM's ViaVoice and the (not extinct?) DragonDictate, plus it can easily be bundled with applications and, IIRC, is royalty free (it was, after all, free to download and develop on anyway).
There was a lot of sample code with previous versions, though it was in VB and C++. But since you'd be creating RCWs, the VB code would be close to what you need, which is just instantiating the components, calling methods, and getting/setting properties in much the same way the VB samples would. There was also pretty decent documentation with it.
See http://research.microsoft.com/srg/[^] for more information and downloads.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Maybe I should write up a little article on wrapping the Speech API to be used in .NET as I did for the Imagine Cup project?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Sounds like a good idea.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I should probably do it up after our FAQ article is done. Once graduation rolls around I don't think it will take too long for us to put together the article (FAQ article).
- Nick Parker My Blog | My Articles
|
|
|
|
|