Object needs to be instantiated

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ptrck
    New Member
    • Jul 2007
    • 4

    #1

    Object needs to be instantiated

    I got this code from this link here:"http://bytes.com/topic/c-sharp/answers/474927-problem-setting-time-zone-settimezoneinfo rmation". There is a problem with this line : object varValue = rkTZInfo.GetVal ue("TZI"); which is rkTZInfo needs to be instantiated and I can't see what to instantiate it to.


    Code:
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            private extern static bool SetTimeZoneInformation(ref
            TIME_ZONE_INFORMATION lpTimeZoneInformation);
    
            [StructLayoutAttribute(LayoutKind.Sequential)]
            private struct SYSTEMTIME
            {
                public ushort wYear;
                public ushort wMonth;
                public ushort wDayOfWeek;
                public ushort wDay;
                public ushort wHour;
                public ushort wMinute;
                public ushort wSecond;
                public ushort wMilliseconds;
            }
    
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            private struct TIME_ZONE_INFORMATION
            {
                public int Bias;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
                public string StandardName;
                public SYSTEMTIME StandardDate;
                public int StandardBias;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
                public string DaylightName;
                public SYSTEMTIME DaylightDate;
                public int DaylightBias;
            }
    
            [StructLayoutAttribute(LayoutKind.Sequential)]
            private struct REGTZI
            {
                public int Bias;
                public int StandardBias;
                public int DaylightBias;
                public SYSTEMTIME StandardDate;
                public SYSTEMTIME DaylightDate;
            }
    
            public bool SetTimeZone(int index)
            {
                // Omitted (uses index to find the time zone in the registry so that I can get the
                // information about the time zone using the appropriate key's TZI value
    
                // We've found the right time zone, get the TZI data
                
                object varValue = rkTZInfo.GetValue("TZI");
                byte[] baData = varValue as byte[];
                int iSize = baData.Length;
                IntPtr buffer = Marshal.AllocHGlobal(iSize);
                Marshal.Copy(baData, 0, buffer, iSize);
                REGTZI rtzi;
                rtzi = (REGTZI)Marshal.PtrToStructure(buffer, typeof(REGTZI));
                Marshal.FreeHGlobal(buffer);
    
                // Now fill out TIME_ZONE_INFORMATION with that data
                TIME_ZONE_INFORMATION tZoneInfo = new TIME_ZONE_INFORMATION();
                tZoneInfo.Bias = rtzi.Bias;
                tZoneInfo.StandardBias = rtzi.StandardBias;
                tZoneInfo.DaylightBias = rtzi.DaylightBias;
                tZoneInfo.StandardDate = rtzi.StandardDate;
                tZoneInfo.DaylightDate = rtzi.DaylightDate;
                tZoneInfo.StandardName = (string)rkTZInfo.GetValue("Std");
                tZoneInfo.DaylightName = (string)rkTZInfo.GetValue("Dlt");
    
                if (!SetTimeZoneInformation(ref tZoneInfo))
                {
                    return (false);
                }
            }
  • Bassem
    Contributor
    • Dec 2008
    • 344

    #2
    I think you have a part of the code, the missing part is designer code, that's where this object is "declared" and "instantiat ed".

    Thanks,
    Bassem

    Comment

    • ptrck
      New Member
      • Jul 2007
      • 4

      #3
      Thanks Bassem for your reply.....with regards to the designer code, I did not see anything else from the link except what I've posted. I think the original poster just did not add it.

      Comment

      • Bassem
        Contributor
        • Dec 2008
        • 344

        #4
        That's true. And that we often do here.
        Me, I don't like to read a post that waste my time and my effort with the designer code. And easily I should expect what the coder added into its design.

        Comment

        • ptrck
          New Member
          • Jul 2007
          • 4

          #5
          I understand fully the reasons behind it but in this case I'm stuck and this individual looks like he's not even a member of this forum anymore which prevents me from sending him a private message.

          Comment

          • Bassem
            Contributor
            • Dec 2008
            • 344

            #6
            I didn't work with WebParts controls before, or I would tell you what exactly the control is.

            Anyway, I think it is not a control, it is something like a Dictionary<byte[], string> that what the code tell me, but I'm sure someone here can tell us more.

            Thanks,
            Bassem

            Comment

            Working...