|
Ok, thank you for your detailed describtion !!
In my case it´s a com dll I want to load by manually typeing the code (that´s why I was talking about registered components). The reason is that I don´t want that people, using my code in their own projects, have to care about the references I need. I want to enable my code to collect everything it needs on it´s own.
|
|
|
|
|
Sure you can redefine the COM interfaces you require in your source, but you have to worry about instantiating, casting, marshaling, and more. Using tlbimp.exe or aximp.exe to create a Runtime Callable Wrapper (RCW), or interop assembly, is much easier. Besides, whether or not other developers use that interop assembly is moot - they can just as easily create their own! Remember, an RCW isn't the COM object - thus containing the code - itself, but just a wrapper. So long as that COM object is installed on the target machine, anyone can create an interop assembly from it. And there's will be no different from yours except, perhaps, differing only by the public key token if you sign the interop assembly when you create it.
Depending on the complexities of your COM object, manually defining all this stuff can be tedious, if not a waste of time.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Finally it works by invoking the methods on the object, created through the assembly, but I guess you are right. Compared with the two short mouse clicks you need to add a reference it´s really a waste of time.
And using the rcw wrapper class is simply much more comfortable.
Hmm.. so everything will remain unaffected, just explored a little more of the .new world
Thanks to all of you for your help...
|
|
|
|
|
You can use reflection to load an assembly.
<br />
Assembly a = Assembly.LoadFrom("your.dll");<br />
Type t = a.GetType("namespace.classname");<br />
MethodInfo m = t.GetMethod("method");<br />
object o = Activator.CreateInstance(t);<br />
object result = m.Invoke(o,new object[]{parameters});<br />
If you want to avoid call methods in this way, you can also create an interface with all the necessary information about the dll and when you call CreateInstance just cast to it. For instance:
<br />
public interface IAnInterface<br />
{<br />
void Method();<br />
}<br />
.......<br />
<br />
IAnInterface anInterface = (IAnInterface)o.CreateInstance(atype);<br />
IAnInterface.Method();<br />
|
|
|
|
|
I type mismatched the last line
should be "anInterface.Method();" instead of "IAnInterface.Method();"
it was evident but .....
|
|
|
|
|
In fact I´ve already tried it the first way, but didn´t know how to call methods on my created object. Simply connecting an interface pointer to my object never worked...
The second way seems to be pretty smart, so I will try something like that.
Thanks for your inspiration !!!
|
|
|
|
|
You cast the object that you get from Activator.CreateInstance to whatever class or interface it is. The assembly still has to be resolvable by either being in the application directory, a private path, the Global Assembly Cache, or by an implementation in your handler for the AppDomain.AssemblyResolve event. If the assembly can't be found that contains the Type, you'll get a TypeLoadException . Note that there is a significant performance issue using this over direct instantiation.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I see you've told others they kind of missed the point, maybe you were looking for this?
Perhaps what you are looking for is a dynamically loaded dll, as in a plug-in type senario.
The author of the excellent DotNetMagic library has written this article that may turn a lightbulb on in your head:
http://www.divil.co.uk/net/articles/plugins/plugins.asp
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
HOW TO CHECK IN A TEXT BOX WHETHER THE INPUT VALUE IS STRING OR NUMERIC VALUE
|
|
|
|
|
A down and dirty way is to convert the text to a number in a try-catch block. If an exception is thrown, then ....
I'm trapping on the KeyPressed event and checking each key pressed. If it isn't the key I want, I disregard it.
If anyone has a better way of doing this, I would like to see it.
Larry J. Siddens
|
|
|
|
|
As the previous reply mentioned, you can do something like this:
public bool IsNumeric(TextBox tb)
{
try
{
Int32.Parse(tb.Parse);
}
catch
{
return false;
}
} If you need to check larger values or decimal values, you could replace Int32 with Int64 (long ) or Double (double ), respectively. If you want to allow other characters like a group separator ("." or ",", depending on the current culture), currenty symbols, etc., use the Int32.Parse(string, NumberStyles) overload and see the documentation for the NumberStyles enum for more information.
Also, in the future please do not use all caps. Most times, it's considered flaming (yelling at someone) - which most likely you didn't intend - but it still makes it hard to read.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
How you doing? Have you used the method "TryParse"? I see that as a method in the System.Double class.
Larry J. Siddens
|
|
|
|
|
If you read the documentation, this is just like Parse but it try/catches internally and returns a boolean if the value could be successfully parsed. If it could, the out param contains the value, something similar to this:
public static bool TryParse(string s, NumberStyles style,
IFormatProvider provider, out double result)
{
try
{
result = double.Parse(s, style, provider);
}
catch
{
return false;
}
} It just depends on whichever you want to use. If you don't want to handle exceptions yourself, use Double.TryParse .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply Heath!
Larry J. Siddens
|
|
|
|
|
What about using regular expressions?
Something like:
public bool IsNaturalNumber(string sValue)
{
return (Regex.IsMatch(sValue, @"0*[1-9][0-9]*") && !Regex.IsMatch(sValue,@"[^0-9]"));
}
|
|
|
|
|
Sure, but keep in mind that regular expressions are inherently slower than simple string parsing. If you will be using this regex several times, you should at least compile it. This will boost performance a bit, but it will still be slower than just parsing a string, especially in such an easy case.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Jose Fco Bonnin wrote:
@"0*[1-9][0-9]*"
WTF? Firstly, why not use @"\d+" ? And what is the purpose of the "prepended" zero's? And lastly, why test it again (not correctly even!) ? Very counter-productive...
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
if you use @"\d+" and your string is "aaaa1" the result will be true.
|
|
|
|
|
Oops, just forgot the line markers, should be @"^\d+$".
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Thank you Bonnin, it works fine. can u explain the whole stuff,
ie why we want 0,*.......
all i changed \p{Nd} instead of [0-9] and it works fine since i use unicode.
those who reponded to my query once again, thanks a lot.
|
|
|
|
|
Hi everyone,
I did not know where else to post this.
I am using MS XP Office Web Components in C# to generate an excel file using the spreadsheet component. I do not want to use the Excel COM object for various reasons.
My problem is that I could not find any way to set the header and footer property of a Worksheet object. In Excel you can set the header and footer for every worksheet. I wanted to do the same with the spreadsheet component in OWC10. However, I have had no luck finding an API for this.
If anyone has any idea on how to accomplish this, I would really appreciate it.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Greetings
I'm trying to create an CaptureBuffer object. When the constructor is called in run-time I get the following error: value does not fall within the expected range.
My code looks like this:
g = DSoundHelper.DefaultCaptureDevice;
Microsoft.DirectX.DirectSound.Capture c = new Microsoft.DirectX.DirectSound.Capture(g);
CaptureBufferDescription cbd = new CaptureBufferDescription();
cbd.Format = soundbuffer.Format;
cbd.BufferBytes = caps.BufferBytes;
cbd.ControlEffects=false;
cbd.WaveMapped=false;
cbd.ControlEffects=false;
cb = new CaptureBuffer(cbd,c); // Here I get the error.
Please help I'm stuck with this error for two days..
Kind Regards
Shimi
|
|
|
|
|
I'm replying for myself but I located the bug.
The caps object wasn't intialized!
Shimi
|
|
|
|
|
Hi
I am writing code which accepts an array of objects, converts them to XML and loads them into a dataset.
My problem is that when the XML is created, it does not contain an indication of the data types of the fields. As a result, all the data types of the columns in the dataset are System.String.
Is there a way to force creation of shcemea when creating the XML string?
Here is the code:
[Serializable]
[XmlType("MyClass")]
public class MyClass
{
[XmlAttribute("IntField")]
public int IntField;
[XmlAttribute("StringField")]
public string StringField;
[XmlAttribute("ByteField")]
public byte ByteField;
public MyClass() {}
}
string xmlString;
System.Xml.Serialization.XmlSerializer xmlSer;
XmlWriter xmlWriter;
MyClass myObj = new MyClass();
StringWriter sw = new StringWriter();
myObj.IntField = 1;
myObj.StringField = "a string...";
myObj.ByteField = 2;
xmlWriter = new XmlTextWriter(sw);
xmlSer = new XmlSerializer(typeof(MyClass));
xmlSer.Serialize(xmlWriter,myObj);
xmlString = sw.ToString();
// at this point the xmlString looks as follows:
//"
//<myclass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" intfield="1" stringfield="a string..." bytefield="2">"
DataSet ds = new DataSet();
StringReader sr = new StringReader(xmlString);
ds.ReadXml(sr);
// At this point ds.Tables[0].Columns[0].DataType.ToString() returns System.String instead of System.32
|
|
|
|
|
XML serialization using the XmlSerializer always serializes to strings (that's all XML can contains) but deserializes the string back to the Types of the properties with which they map. When you read this XML fragment into a DataSet , the DataSet has no idea what it is reading and will assume that all the columns are simply strings.
In order to coerce the DataSet to use a schema, you can either create a DataSet schema using the DataSet designer in VS.NET, or just type one manually yourself and read that schema in with DataSet.ReadXmlSchema , then use DataSet.ReadXml .
An even better way is to create a strongly-typed DataSet using the VS.NET DataSet designer (right-click on project or project folder, select Add->Add New Item and select DataSet) and use that instead of DataSet :
MyDataSet ds = new MyDataSet();
StringReader sr = new StringReader(xmlString);
ds.ReadXml(sr); This way, the DataSet object is initialized with all the necessary table and column information and you can refer to columns by name without having to cast to the necessary data type.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|