User Profile

Collapse

Profile Sidebar

Collapse
vekipeki
vekipeki
Last Activity: Feb 12 '10, 07:29 AM
Joined: Nov 27 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • vekipeki
    replied to double compare 0.2 != 0.2 How?
    No, you cannot override the existing == operator (it is a static method). But I wouldn't call that a good idea even if it were possible, modifications like that would be a nightmare to debug.
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to double compare 0.2 != 0.2 How?
    That is how things work, the only thing you can do is add a handy extension method to System.Double, something like:

    Code:
    public static bool AlmostEquals
         (this double a, double b)
    {
        return (Math.Abs(a - b) < 1e-5);
    }
    and then use it, when appropriate, like
    Code:
    MessageBox.Show((1.0 - 0.8).AlmostEquals(0.2));
    Although if this is only a unit test, you might just add a...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to create a new instance of Object ?!
    You might want to take a look at Activator.Creat eInstance method.

    This should also work:

    Code:
    class OtherClass
    {
        public static T CreateInstance<T>() where T : new()
        {
            return new T();
        }
    }
    (if I understood correctly what you are asking for)

    In that case you would use it like this:

    Code:
    MyClass obj = OtherClass.Create
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to List<T> Extension Method in C#2.0
    Extension methods are a feature of C# 3.0, but not related to the Framework version.

    To use C# 3.0 with .Net 2.0, you will however need Visual Studio 2008, but it will compile and run in CLR 2.0 just like you were using C# 2.0.

    By adding a this keyword in the parameter list, you are telling the compiler to add an extension method to the class of the specified "this" type.

    For example, to add average,...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to Getting function names from ordinals in a dll
    in C
    But it doesn't display the call stack for the unmanaged side (COM). The problem is that exception happens in the message loop, so the method at breakpoint is Application.Run ():

    Code:
    -- Message: Attempted to read or write protected memory.
       This is often an indication that other memory is corrupt.
    -- Stack trace:
       at System.Windows.Forms.UnsafeNativeMethods
          .DispatchMessageW(MSG& msg)
       at
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to Getting function names from ordinals in a dll
    in C
    Additional info:

    I cannot find the .def file for the COM dll, so I cannot use it to get the name. I am not interested in instantiating the COM class, I only want to know what function is related to a specified ordinal.

    My original problem is that I have found an exception using WinDbg, which happens in ChartFXClientSe rverCore!Ordina l5507(+0x97b7), so I would like to see the specific function to try to isolate the proble...
    See more | Go to post

    Leave a comment:


  • vekipeki
    started a topic Getting function names from ordinals in a dll
    in C

    Getting function names from ordinals in a dll

    Hi, first of all sorry if this isn't exactly C++ related, but didn't know where it would be more appropriate.

    I am trying to get actual function names from their ordinal numbers from a COM dll. I tried using dumpbin.exe but it only returns [NONAME] for each ordinal (except the first few):

    Code:
        ordinal hint RVA      name
    
             21    0 00002439 DllCanUnloadNow
             25    1 00007F41 DllGetClassObject
    ...
    See more | Go to post

  • vekipeki
    replied to convert string to char*
    Use the dumpbin.exe tool to make sure that you have the correct entry point name in C++.
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to convert string to char*
    Check this link for some examples on P/Invoke: http://msdn.microsoft.com/en-us/magazine/cc164193.aspx. There is also a download link for a "PInvoke Interop Assistant" tool, which helps you create the correct DllImport signature (if you did a mistake).

    You can get detailed info on string marshalling on this link: http://msdn.microsoft.com/en-us/library/s9ts558h.aspx.
    See more | Go to post

    Leave a comment:


  • Maybe you could get it from the total number of days between those two dates?

    Code:
    double numberOfDaysElapsed = (date2 - date1).TotalDays;
    Note that you need to take into account which week days your dates actually are (e.g. Monday to Wednesday is not the same as Friday to Sunday).
    See more | Go to post

    Leave a comment:


  • Check this link: http://www.thinksharp.org/hex-string...ray-converter/
    See more | Go to post

    Leave a comment:


  • It exists in VS2005 also: NameValueCollec tion.

    But Hashtable also implements IEnumerable for DictionaryEntry objects, so you can also write:

    Code:
    foreach (DictionaryEntry entry in myHashtable)
    {
       Console.WriteLine("Key = {0}, Value = {1}", entry.Key, entry.Value);
    }
    There is also a generic Dictionary<TKey ,TValue> you can use, which implements IEnumerable for KeyValuePair<TK ey,TValue>...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to How to return generic abstract class ?
    As I said, that example doesn't help you a lot.

    Because this code:

    Code:
    public sealed class ReadyForGenericSingleton : AbstractGenericSingleton<ReadyForGenericSingleton>
    {
        public static ReadyForGenericSingleton Instance
        {
            get
            {
                if (!Initialised)
                {
                    Init(new ReadyForGenericSingleton());
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to How to return generic abstract class ?
    But the example in the first article looks like this:

    Code:
    public class Singleton<T> where T : class
    {
        Singleton() { }
     
        class SingletonCreator
        {
            static SingletonCreator() { }
     
            private static T CreateInstance()
            {
                ConstructorInfo constructorInfo = typeof(T).GetConstructor(BindingFlags.Instance |
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to How to return generic abstract class ?
    To call the GetStorage<T> method, you already need to know the type of T, so it isn't actually a factory.

    I still don't understand why Instance needs to be static. If it was public and abstract in your base class (StorageBaseAbs tract<T>), then you could simply get the singleton using:

    Code:
    StorageDataBase db = StorageDataBase.Instance;
    or

    Code:
    StorageDataBase db = StorageBaseAbstract
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to How to return generic abstract class ?
    The important thing to notice here is that Class1.Instance is of type Class1, while Class2.Instance is of type Class2. Since they are both static and are not defined in any interface or parent abstract class, for C# compiler they are completely different.

    You are telling compiler that T should be derived from BaseClass<T>, but you are not telling him that T is Class1 or Class2, so it doesn't want to allow that.

    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to How to return generic abstract class ?
    Please use CODE tags when posting, it makes your code much easier to read.

    How about something like this:
    Code:
    abstract class BaseClass<T>
    {
        public abstract T Instance { get; }
    }
    
    class Class1 : BaseClass<Class1>
    {
        private Class1() { }
    
        readonly Class1 _instance = new Class1();
        public override Class1 Instance
        {
    ...
    See more | Go to post

    Leave a comment:


  • vekipeki
    replied to Checkbox EventHandler
    No, checkboxes will not have an event handler, only the button click event will be handled. Until the button is pressed, you don't need to care about what is going on with the checkboxes.

    Just read them all in submitButton_cl ick handler, the same way you created them, using a for loop....
    See more | Go to post

    Leave a comment:


  • Nevertheless, you need to pass the connection string to SqlConnection to create it. I didn't say that the second part of the code needs to be in the same class as the first part, but you need to have the connection string ready before creating SqlConnection (that's what the error is telling you, after all).

    Your class doesn't enforce that in any way - you are creating an SqlConnection from a static string, without knowing if it was...
    See more | Go to post

    Leave a comment:


  • First problem is that you shouldn't be creating a database connection just like that, "in the middle of nowhere".

    Create a private string field which contains the connection string only, and then create a connection only when you need to do a transaction.

    Code:
    // add this to your class, [B][I]but not as a static field[/I][/B]
    private string connectionString = null;
    
    if (open.ShowDialog() == DialogResult.OK)
    ...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...