Wednesday, January 19, 2011

Tuesday, January 18, 2011

PInvokeStackImbalance C# call to unmanaged C++ function

After switching to VS2010, the managed debug assistant is displaying an error about an unbalanced stack from a call to an unmanaged C++ function from a C# application.
The VS2008 built C++ dll and C# application never had a problem.

Decision:

  1. Use __stdcall on your C++ function
  2. Examble:
    short __stdcall SuperSpecialOpenFileFunc(SuperSpecialStruct * stuff);
    
  3. Declare CallingConvention = CallingConvention.Cdecl on your DllImport
  4. Use a compiler switch that will turn on stdcall as the default calling convention: -Gz

About pInvokeStackImbalance MDA:
http://msdn.microsoft.com/en-us/library/0htdy0k3.aspx

Monday, January 17, 2011

TSF + PowerShell: List all projects

This will create TFS instance and get all project from the instance.
$registryValue is an object to be displayed in the output grid of PowerGUI window.

    $tfs = get-tfs "http://TFS-URL"
    $projects = $tfs.CSS.ListAllProjects()
    
    foreach($pro in $projects) {
    $registryValue = New-Object System.Management.Automation.PSObject
    $registryValue `
        | Add-Member -Name Name -MemberType NoteProperty -Value $pro.Name -PassThru `
        | Add-Member -Name Status -MemberType NoteProperty -Value $pro.Status -PassThru `
        | Add-Member -Name URI -MemberType NoteProperty -Value $pro.Uri-PassThru `
        | Add-Member -Name BS -MemberType NoteProperty -Value $tfs.BS -PassThru

TFS + PowerShell: Create TFS instance

TFS VS 2010 and PowerShell 2

This function returns TFS instance which will be used in use cases to follow later.

function get-tfs (
    [string] $serverName = $(Throw 'serverName is required')
)
{
    # load the required dll

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

    $propertiesToAdd = (
        ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
        ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
        ('BS', 'Microsoft.TeamFoundation.Build.Client', 'Microsoft.TeamFoundation.Build.Client.IBuildServer'),
        ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
        ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
    )

    # fetch the TFS instance, but add some useful properties to make life easier
    # Make sure to "promote" it to a psobject now to make later modification easier

    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
    foreach ($entry in $propertiesToAdd) {
        $scriptBlock = '
            [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
            $this.GetService([{1}])
        ' -f $entry[1],$entry[2]
        $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
    }
    return $tfs
}


get-tfs "http://TFS-URL"

Sunday, January 16, 2011

7 Mb Linux

Linux is so fun. Just've fiddled with a 4 mb memory + 1 Gb flash storage:
Busybox, Samba server, lighttp, ftp server, torrent.

Powered by Blogger.