473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Object needs to be instantiated

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


Expand|Select|Wrap|Line Numbers
  1. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  2.         private extern static bool SetTimeZoneInformation(ref
  3.         TIME_ZONE_INFORMATION lpTimeZoneInformation);
  4.  
  5.         [StructLayoutAttribute(LayoutKind.Sequential)]
  6.         private struct SYSTEMTIME
  7.         {
  8.             public ushort wYear;
  9.             public ushort wMonth;
  10.             public ushort wDayOfWeek;
  11.             public ushort wDay;
  12.             public ushort wHour;
  13.             public ushort wMinute;
  14.             public ushort wSecond;
  15.             public ushort wMilliseconds;
  16.         }
  17.  
  18.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
  19.         private struct TIME_ZONE_INFORMATION
  20.         {
  21.             public int Bias;
  22.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  23.             public string StandardName;
  24.             public SYSTEMTIME StandardDate;
  25.             public int StandardBias;
  26.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  27.             public string DaylightName;
  28.             public SYSTEMTIME DaylightDate;
  29.             public int DaylightBias;
  30.         }
  31.  
  32.         [StructLayoutAttribute(LayoutKind.Sequential)]
  33.         private struct REGTZI
  34.         {
  35.             public int Bias;
  36.             public int StandardBias;
  37.             public int DaylightBias;
  38.             public SYSTEMTIME StandardDate;
  39.             public SYSTEMTIME DaylightDate;
  40.         }
  41.  
  42.         public bool SetTimeZone(int index)
  43.         {
  44.             // Omitted (uses index to find the time zone in the registry so that I can get the
  45.             // information about the time zone using the appropriate key's TZI value
  46.  
  47.             // We've found the right time zone, get the TZI data
  48.  
  49.             object varValue = rkTZInfo.GetValue("TZI");
  50.             byte[] baData = varValue as byte[];
  51.             int iSize = baData.Length;
  52.             IntPtr buffer = Marshal.AllocHGlobal(iSize);
  53.             Marshal.Copy(baData, 0, buffer, iSize);
  54.             REGTZI rtzi;
  55.             rtzi = (REGTZI)Marshal.PtrToStructure(buffer, typeof(REGTZI));
  56.             Marshal.FreeHGlobal(buffer);
  57.  
  58.             // Now fill out TIME_ZONE_INFORMATION with that data
  59.             TIME_ZONE_INFORMATION tZoneInfo = new TIME_ZONE_INFORMATION();
  60.             tZoneInfo.Bias = rtzi.Bias;
  61.             tZoneInfo.StandardBias = rtzi.StandardBias;
  62.             tZoneInfo.DaylightBias = rtzi.DaylightBias;
  63.             tZoneInfo.StandardDate = rtzi.StandardDate;
  64.             tZoneInfo.DaylightDate = rtzi.DaylightDate;
  65.             tZoneInfo.StandardName = (string)rkTZInfo.GetValue("Std");
  66.             tZoneInfo.DaylightName = (string)rkTZInfo.GetValue("Dlt");
  67.  
  68.             if (!SetTimeZoneInformation(ref tZoneInfo))
  69.             {
  70.                 return (false);
  71.             }
  72.         }
  73.  
Mar 3 '10 #1
5 1841
Bassem
344 100+
I think you have a part of the code, the missing part is designer code, that's where this object is "declared" and "instantiated".

Thanks,
Bassem
Mar 6 '10 #2
ptrck
4
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.
Mar 8 '10 #3
Bassem
344 100+
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.
Mar 8 '10 #4
ptrck
4
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.
Mar 8 '10 #5
Bassem
344 100+
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
Mar 8 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jeremy S. | last post by:
I suspect I may be fundamentally misunderstanding how object variable references behave - and I'd sure appreciate some clarification - given my particular scenario. Summary: In an ASP.NET (1.1)...
2
by: Frédéric Mayot | last post by:
Hi, In my web application, I need to connect to an SQL Server database. My pages (UI) will use one or more business objects as well as datareaders (I cannot make everything a business object...)...
3
by: ECathell | last post by:
I have a database object. lets call it boxes. I have a winform that allows the fields of the box object to be edited. When the box is first instantiated I would like to make a copy of the box object,...
4
by: Luke Matuszewski | last post by:
Here are some questions that i am interested about and wanted to here an explanation/discussion: 1. (general) Is the objectness in JavaScript was supported from the very first version of it (in...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
8
by: Brad Pears | last post by:
I want to check to see if a particular object exists using vb.net 2005. I have a class called clsContract. When the user clicks the 'New Contract' button, I want to check to see if a clsContract...
4
by: dgleeson3 | last post by:
Hello All I have three classes Form1, DataBase_Manager and Users. Form 1 creates two object of type DataBase_Manager and Users as below. Public Class Form1 Inherits Form Public...
1
by: mirandacascade | last post by:
1) Module1 has the following delcaration: Public g_frmZZZ as Form Public g_txtForm2 as Variant 2) app has two forms: form1 and form2 3) a command button on form1 opens form2; it also has...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
10
by: sumsin | last post by:
The C++ Object Model book says that 'Nonstatic data members are allocated directly within each class object. Static data members are stored outside the individual class object. Static and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.