Perforce checkin email notification

April 5th, 2011 No comments

Quickie today, if you want to be emailed every time someone checks in something to a particular section of the depot you can do this quite easily using the p4 client.

Go to Connection->Edit Current User and click on the ‘Reviews’ tab. Here you’ll see the depot view. Navigate to the topmost section that you want to receive emails from, right click it and select Include Tree. You can also specify the section(s) of the depot you want to review by manually entering a path in the first tab, but if theres a nice pretty GUI there to do it, why bother manually entering paths?!

Categories: Perforce Tags:

Visual Studio filters disappear

April 4th, 2011 1 comment

Recently I had a project in VS2008 whereby all my filters disappeared and all files appeared unfiltered. Very annoying when trying to locate files, I thought something was borked with the vcproj or even the solution. The fix is actually really simple, somehow (I have no idea how) the ‘Show All Files’ option had been toggled. To untoggle it go and click Project->Show All Files. Very simple I know but it had me perplexed for a couple of minutes!

Categories: C/C++, Visual Studio Tags:

Perforce with C# (p4 dotnet)

March 25th, 2011 No comments

I’ve found a need to use Perforce with C# recently. The first step was to get the right DLLs for the job. I got the P4 API DLL from SourceForge here

Extracting it, I think you actually only need the p4API dll in the bin/CLR_2.0 directory, I took the whole directory just in case.

In your project right click on the References directory and ‘Add Reference’ and navigate to the p4api.dll.

// Load up the API
using P4API;
...

// Create the connection
P4Connection p4 = null;
            try
            {
                p4 = new P4Connection(); // Uses the default connection to Perforce
                p4.Connect();

                // Don't throw an exception on a Perforce error.  We handle these manually.
                p4.ExceptionLevel = P4ExceptionLevels.NoExceptionOnErrors;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

I want to delete a file from the repository so to do this I needed to just put through the right call. From what I’ve gathered you can run any P4 command that can be run via the command line, all you need to do is

try
{
       if (p4 != null)
       {
             p4.RunUnParsed("delete", selectedItemPath);
       }
}
catch (System.Runtime.InteropServices.COMException ex)
{
        MessageBox.Show(ex.Message);
}

Done!

Categories: C/C++ Tags: ,

C# Npgsql tutorial

March 24th, 2011 No comments

Hi,

I’ve just started using C# for the first time and decided to chuck up a little intro on how to connect with a Postgres database. This is a very stripped down tutorial, does the basics and doesn’t really handle exceptions, error states and the like. Firstly you need to get a few DLLs, Npgsql.dll, policy.2.0.Npgsql.dll and MonoSecurity.dll. You can get them from PgFoundry here.

I’ve put these in the same folder as the project. Go to Solution Explorer and locate the ‘References’ section under your project. Right click that and Add Reference. Click the ‘Browse’ tab and select the Npqsql dll only.
Firstly you need to load up the package/namespace (I’m not sure of the correct terminology here). Then you’re ready to connect to the database using the correct name, port, username and so on. This is simple.

using System;
...
using Npgsql;

....

NpgsqlConnection dbConnection = new NpgsqlConnection("Server=myServer;Port=xxxx;User Id=xyz;Password=xyz;Database=myDB;");

try
 {
        dbConnection.Open();
 }
catch
{
        //Handle error states here
}

That’s it! You’re now ready to execute queries and updates on the database.

I’ve included a very simple select statement below, it selects all from a hypothetical animal table and extracts the name and type column values from the results. The GetOrdinal is a useful helpful function to return you the integer that represents the index of the named column. It is more robust to changes in the database as indices may change but you need to check for NULLs as it won’t work (I’ve found out!)

NpgsqlCommand Command = new NpgsqlCommand("select name,type from animals", dbConnection);
NpgsqlDataReader result = Command.ExecuteReader();

while (result.Read())
{
      String animalName = result.GetString(result.GetOrdinal("name"));
      String animalType = result.GetString(result.GetOrdinal("type"));
      ... (Do something here)
}

Finally when you’re done with your database you need to close down the connection

dbConnection.Close();
dbConnection = null;

Thats it’s some very simple DB manipulations in very few lines of code, impressed with C# so far I must say!
Next step do things in transactions and handle exceptions!

Categories: C#, C/C++ Tags: , ,

warning C4541: ‘dynamic_cast’ used on polymorphic type ‘xyz’ with /GR-; unpredictable behavior may result

February 17th, 2011 No comments

I got this error today in Visual Studio when building our game at work.
I was trying to go a harmless dynamic_cast to downcast and object to a derived object and was confronted with this problem. After looking up the error it seems that it can be made to go away by turning on RTTI which is something we do not want to do due to the overhead of it and we have our own reflection system anyway and the type information isn’t required from RTTI. The reason being that dynamic_cast makes use of typeid which is only available under RTTI enabled projects.

I could have done a static_cast but didn’t want to do this blindly. Also not being a fan of ‘unpredictable behaviour’ I instead had to resort to a old fashioned dangerous C-style cast e.g.

     MyObject* pObj = (MyObject*)pObjectToCast;

This works fine, gets rid of the warning but I don’t like it.

Categories: C/C++ Tags:

Hundreds of errors including: Expected declaration specifiers or ‘…’ before ‘CFXMLTreeRef’

January 5th, 2011 1 comment

Hi,

I upgraded recently to XCode 4.2 and on building the release version of my app was getting 96 odd errors. All of these orginate from Foundation.h with a callstack like below

/Users/parrotbait/Documents/Dropbox/
/myApp/myApp_Prefix.pch

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:81:0 In file included from /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:17:0 In file included from /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:29:0 In file included from /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h:54:0 In file included from /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/WSMethodInvocation.h:773:0 Expected declaration specifiers or '...' before 'CFXMLTreeRef' in /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/WSMethodInvocation.h

Why were the OSX frameworks being used? As they were being used for an iOs build there was all sorts of problems. So I began to hunt down the origin of the call to the OSX headers.
After checking my project settings everything looked fine and I couldn’t see what the problem was. However after opening the transcript of the build I saw that on compiling the precompiled headers I was the errors were occuring. There was a compiler flag ‘-F’ for framework that indicates what paths to search for frameworks:

-F/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks

Right clicking on my Target and searching for Framework in the build section, I found that I had somehow (although I don’t remember doing this and am not convinced I really did) had an entry for ‘Framework Search Paths’

"$(DEVELOPER_DIR)/SDKs/MacOSX10.6.sdk/System/Library/Frameworks"

Removing this got rid of my 100s of build errors.

Categories: iPhone, iTouch, Objective C Tags:

Visual Studio – No files were found to look in. Find was stopped in progress.

December 13th, 2010 No comments

This is the weirdest thing, I was working away in Visual Studio 2008 when I attempted a global search and it failed indicating that ‘No files were found to look in. Find was stopped in progress.’. The weird thing is that I had selected Entire Solution and it should have worked. After some quick googling I found out that other people have had the same problem. Although the reason for it happening hasn’t been entirely explained (nor do I really care) the solution is as follows:

In VS2008 press Alt + Break to make find work again
In VS2005 press Ctrl + Scroll Lock (I haven’t tried this one)

Find works again, hurray!

Categories: C/C++ Tags:

Get Windows folder path

December 10th, 2010 No comments

It is quite easy to find a path to a particular folder in Windows, a function called SHGetFolderPath exists that will return you the user’s file system path to common system locations such as My Documents, Program Files, My Music, App Data and so on. I wanted to get the system font folder path so this function proved especially useful. Usage is as below:

Requirements: Add shell32.lib to your linked in libraries.

#include 
#include 

TCHAR strPath[ MAX_PATH ];

if (FAILED(SHGetSpecialFolderPath(
	0,       // Hwnd
	strPath, // String buffer.
	CSIDL_FONTS, // CSLID of folder
	FALSE ))) // Create if doesn't exists?
{
	//SOMETHING HAS GONE WRONG
}

Works a treat
WARNING: This function is supported from Windows 2000 Server onwards, if you need to support these OSes you may need to use something else.

Categories: C/C++ Tags:

PrintF wide format specifier

November 15th, 2010 No comments

Today I ran into the problem whereby printf was putting junk into a string even though it was using %s. A little perplexed about it I had a look around and saw that there is a separate format specifier that expects a wide string. My application is not compiled in Unicode but I require a wide string at this point.

So

wsprintf(buffer, L"Name %s", myWideCharString)

The above code wouldn’t work. However if I use the code below it would

wsprintf(buffer, L"Name %lS", myWideCharString)

The reason being that printf does some behind the scenes conversion and %s or %S will convert to a char*. %lS tells it that what is coming in is a wide string and to handle it as such.

I also found out that %f doesn’t work with wsprintfW, wierd and quite silly really.

Categories: C/C++ Tags:

Pure virtual functions error LNK2019

November 3rd, 2010 No comments

I ran into this error today when trying to refactor some code. Confused initially as LNK2019 means a function definition cannot be found. However the functions were defined in the derived classes so why the error?

The problem stemmed from the fact that my base class called the virtual functions in the constructor and destructor. Apparently the vtables aren’t available at this point for a class and so the compiler cannot resolve the call for a particular function. Hence the error.

The solution of course is to not call virtual functions from the constructor or destructor.

Categories: C/C++ Tags: