MSFN Forum: Getting my feet wet with C# - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Getting my feet wet with C# need some debug assitance Rate Topic: -----

#1 User is offline   PC_LOAD_LETTER 

  • Well, I stole something else
  • Group: Super Moderator
  • Posts: 1,829
  • Joined: 13-October 07
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 29 December 2007 - 11:05 PM

I got tired of fiddling with the registry to tweak out the Vista Screensavers and ive been meaning to try my hand at C#. This thread is the result of that attempt. Ive clipped together various code snippets from around the web and this is what i came up with:
Attached File  ribbons.jpg (41.9K)
Number of downloads: 4
The actual utility:
Attached File  scr.exe (8K)
Number of downloads: 3 (no source yet -its embarrassing bad)

Heres the problem. the utility works perfectly if you already have the settings in the registry but if the keys dont exist before you run it, it crashes
keys required for it to run properly:
Attached File  ribbons.reg (476bytes)
Number of downloads: 2

heres the code clipping of where i get the data from the registry
		  RegistryKey RibbonsKey = Registry.CurrentUser;
		  RibbonsKey = RibbonsKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Screensavers\\Ribbons", true);		
		  RibbonWidth = (int) RibbonsKey.GetValue("RibbonWidth");
		  Console.WriteLine("RibbonWidth = " + RibbonWidth);

as far as i can tell its failing at line 3 in that code when it tries to ready the data inside a nonexistent key. how can i make it ignore the error or restructure the code to prevent it.

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
   at ScrForm..ctor()
   at Test.Main()


also, can I get a decent IDE for free? (no warez) textpad + command line is getting tiresome.

P.S. I know TweakVista can already do this. I refuse to pay for a skinned regtweaker. Plus this is good way to learn (I hate making useless 'Hello World' apps)


#2 User is offline   Glenn9999 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 588
  • Joined: 23-April 07

Posted 30 December 2007 - 04:38 AM

View Postgeek, on Dec 29 2007, 11:05 PM, said:

also, can I get a decent IDE for free? (no warez) textpad + command line is getting tiresome.


Notepad++ Ask if you need any help on configuring it (the language pre-sets are okay, but setting up the compiler to run from it is not so obvious).

Quote

Heres the problem. the utility works perfectly if you already have the settings in the registry but if the keys dont exist before you run it, it crashes


In your code you'll need to check for that. Something like "try to read these registry entries, if they do not exist then create them."

Quote

as far as i can tell its failing at line 3 in that code when it tries to ready the data inside a nonexistent key. how can i make it ignore the error or restructure the code to prevent it.


Or a non-existent key path if you did not create that first. In either event, there should be an exception condition triggered which you should be able to test for.

This post has been edited by Glenn9999: 30 December 2007 - 05:13 AM


#3 User is offline   PC_LOAD_LETTER 

  • Well, I stole something else
  • Group: Super Moderator
  • Posts: 1,829
  • Joined: 13-October 07
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 30 December 2007 - 05:40 PM

got it
RibbonWidth = (int)RibbonsKey.GetValue("RibbonWidth");

should have been
RibbonWidth = (int)RibbonsKey.GetValue("RibbonWidth", 1030000000);

because if it failed the data type wasnt int so therefore would fit where i was trying to put it.

it now works 100% and i went ahead and made all 4

Attached File  Aurora.jpg (54.44K)
Number of downloads: 1
Attached File  Aurora.exe (9K)
Number of downloads: 3

Attached File  bubbles.jpg (71.54K)
Number of downloads: 0
Attached File  Bubbles.exe (11.5K)
Number of downloads: 3

Attached File  Mystify.jpg (40.7K)
Number of downloads: 0
Attached File  Mystify.exe (7.5K)
Number of downloads: 3

Attached File  ribbons.jpg (43.09K)
Number of downloads: 1
Attached File  Ribbons.exe (8K)
Number of downloads: 4

if only there was a way to actually build them into the screensavers control panel
but either way they work great

#4 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,019
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 31 December 2007 - 01:18 AM

View PostGlenn9999, on Dec 30 2007, 05:38 AM, said:

Notepad++ Ask if you need any help on configuring it (the language pre-sets are okay, but setting up the compiler to run from it is not so obvious).

Holy crap, you can do that!? This would have saved me so much time during my last semester... :wacko:

#5 User is offline   Glenn9999 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 588
  • Joined: 23-April 07

Posted 31 December 2007 - 12:55 PM

View Postgamehead200, on Dec 31 2007, 01:18 AM, said:

View PostGlenn9999, on Dec 30 2007, 05:38 AM, said:

Notepad++ Ask if you need any help on configuring it (the language pre-sets are okay, but setting up the compiler to run from it is not so obvious).

Holy crap, you can do that!? This would have saved me so much time during my last semester... :wacko:


(Description of an attempt to run the compiler deleted. Below is much better.)

This post has been edited by Glenn9999: 31 December 2007 - 05:26 PM


#6 User is offline   Glenn9999 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 588
  • Joined: 23-April 07

Posted 31 December 2007 - 05:23 PM

Nevermind the above post...got it figured out.

I got the compiler thing figured out to my satisfaction. Actually I missed something in Notepad++. There's a plugin called NPPEXEC which allows batch scripting, and has an output console. So you can get it so it literally works like an IDE.

Hit F6 and you'll get a console where you can type commands and things. For the compiler I was trying to run earlier, the following works:

npp_save
"c:\program files\borland\delphi 3\bin\dcc32" "$(FULL_CURRENT_PATH)"


The second-line is as before (runs the compiler, full_current_path is the currently loaded file). npp_save is a nppexec script command which saves the current file to disk.

Save this to a script name, then when you pull up Notepad++, you can hit F6 and then select the script name, and then hit ENTER. Subsequent compiles only require F6 then ENTER. Of course, you can have multiple scripts if you have multiple compilers. The scripts are saved in plugins\config.

Can't get much better than this :)

#7 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,019
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 31 December 2007 - 06:33 PM

Wow, like I said, that would've come in real handy during my last semester. We were told to either use Notepad++ and the command line compiler or Visual Studio (provided to us by MSDN-AA). :wacko: I ended up using Notepad++.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy