Categories
Geeky/Programming

FizzBuzz Test

This is all over the blogs today:

CodingHorror.com. Jeff Atwood writes a great post entitled Why Can’t Programmers.. Program?

Just for kix, I did it, just so I knew I wasn’t crazy 🙂

for(int i = 1; i < 101; i++)
{
if(i % 3 == 0 && i % 5 == 0)
{
Console.WriteLine("FizzBuzz");
}
else if(i % 3 == 0)
{
Console.WriteLine("Fizz");
}
else if(i % 5 == 0)
{
Console.WriteLine("Buzz");
}
else
{
Console.WriteLine(i.ToString());
}

}

Categories
Geeky/Programming

Careful! rand_s and OS compatability

if you want to use the secure version rand_s() – be careful, it only works on XP and higher!!

http://msdn2.microsoft.com/en-us/library/sxtz2fa8(VS.80).aspx

Guess you don’t get to be secure on Windows 2000 or lower. 😛

Categories
Geeky/Programming

WPF Programming – Xceed Datagrid Control

So, now that I have the extensions and have started digging into WPF, I notice one thing blatantly missing. Datagrids! So I did a quick search and found that Xceed has a free (as in beer) datagrid control for WPF, you can get here. I have downloaded it and can’t wait to start using it.

Categories
Geeky/Programming

.NET 3.0 WPF/WCF Templates for VS2005

Microsoft recently released the .NET Framework 3.0 (WinFX) that includes Windows Presenation Foundation, Windows Communication Foundation, Windows Workflow Foundation, and Windows CardSpace. If you are trying to develop using the WPF or WCF using VS2005, you might be wondering if there are VS2005 Templates avail for these project types. You would think that by installing the Vista SDK and the .NET Framework 3.0 you would have them, but no. After doing some digging, there are extensions for WWF for Visual Studio. For WPF and WCF, you are left with the November 2006 CTP Release of the Extensions, which is the “Cider” Release. I guess from what I am reading, there won’t be RTM versions of these extensions, well, not until the Visual Studio release of “Orcas”.

Now, I guess I don’t mind that the CTP versions are what you are supposed to use, but the problem is there is no where I can find (in one place) where all of this is laid out and specified. You have to dig around on forums and what not. Microsoft should lay out what is what so you don’t have to second guess.

After installing the RTM 2006 Extensions, you should see the .NET Framework 3.0 projects types in VS2005 as shown here:

dotnet3_projecttemplates.JPG

Categories
Geeky/Programming

warning CS0618: 'System.Web.Mail.SmtpMail' is obsolete:

Previously in .net 1.0 and 1.1, to send mail from a console application, you could use

using System.Web.Mail

and use a method similar to this:

static void SendMail()
{
MailMessage msg = new MailMessage();

msg.To = “toaddress1@whatever.com,toaddress2@blah.com”;
msg.From = “fromaddress@whatever.com”;
msg.Subject = “My Subject”;
msg.Body = “My Body”;

msg.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = “yourmailserveraddressorip”;

SmtpMail.Send(msg);

}

If you then upgrade to .net 2.0, you will get this when building:

warning CS0618: ‘System.Web.Mail.SmtpMail’ is obsolete: ‘The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202&#8217;

Nice huh, link doesn’t tell you much except the API is obsolete.
The old way still works, but you get a bunch of ugly warnings.
So, to fix that, you need to do this. First remove the using statement for System.Web.Mail, then add and change your mailing method as follows:

using System.Net.Mail;

static void SendMail()
{
MailMessage msg = new MailMessage();

msg.To.Add(“toaddress1@whatever.com,toaddress2@blah.com”);
msg.From = new MailAddress(“fromaddress@whatever.com”);;
msg.Subject = “My Subject”;
msg.Body = “My Body”;

msg.IsBodyHtml = true;

SmtpClient smtpClient = new SmtpClient(“yourmailserveraddressorip”);

smtpClient.Send(msg);

}

As you can see, pretty close but a few subtle differences. No more warnings! 🙂

** Note that if you really want a good SendMail function, you should pass in the parameters and have overloads for options such as HTML mail, etc. Depending
on the app I am making, I’ll just throw up a email method like this, but it’s really the quick and dirty way to do it. **

Categories
Geeky/Programming

LNK1104: cannot open file 'LIBC.lib'

If upgrading a C++ project from VS2003 to VS2005, you might run into this error. LNK1104: cannot open file ‘LIBC.lib’

I resolved it by doing the following:

Project->Properties->Configuration Properties->Linker->Input

Ignore Specific Library: libc.lib

I guess VS2003 has there by default, from what I have been reading.

Categories
Geeky/Programming

.NET: Redirect URI cannot contain newline characters.

if you are doing a Response.Redirect, and are seeing this error, try something like this

string url = someUrlWithNewLines;

url.Replace(“nr”, “”)

Response.Redirect(url);

Seems trivial, but I have seen the error crop up many times. Just for kicks I did a Google search on it, and a lot of people are asking about it, but no real answer. So, here it is 🙂

Categories
Geeky/Programming

VS2005 C++ Unit Tests – System.AccessViolationException: Attempted to read or write protected memory.

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..

If you have VS2005 C++ Unit Tests, written in managed C++ as they should be, and you are calling native code from them, and you see that error when running your unit tests – I have found it to mean that you are using insecure versions of methods (strcpy, etc). If you change the method calls to the secure versions, you should see your tests pass!

Categories
Geeky/Programming

VS2005 LNK1104 Error – cannot open file

If you are referncing another lib in a project and you goto build and get

fatal error LNK1104: cannot open file ‘C:MyProjectDebug.obj’

Do a double check in the project you are referencing configuration. If you have a space in the name (Say “Debug Test”) you might see this error and scratch your head. If the project you are referencing outputs to $(ConfigurationName), then the output directory will have a space. Seems that when you reference that project or lib, it doesn’t like it with a space in the path name, doh! 🙂

Categories
Geeky/Programming

HowTo: Make a Win32 DLL without MFC and ATL

Vs2005->New->Project

Win32->Win32 Project

On the Wizard, Application Settings, choose DLL radio box, hit finish.

This is all great, except when you build it, you just end up with a dll. How do you use the dll in another project?

Add a Module-Definition File (.def) – call it Export.def

next time you build, there will be a “.lib” file avail so you can link in the dll with another project.

You can add a EXPORTS section to export functions. The LIBRARY secion is added for you automatically. Have Fun with your new Win32 dll!