Welcome to MSDN Blogs Sign in | Join | Help

No TOUCH utility on Windows to help refreshhing the Fusion Cache? MS-DOS copy command syntax...

After reading the November '06 "Manifest and the fusion cache" blog entry that one my peers wrote, I immediately thought about the *nix style TOUCH utility.

But it's not available out-of-the-box on Windows... I was surprised to learn that the Updating the Date and Time Stamps on Files trick worked well on Windows 7.

All thanks to our old MS-DOS command:

@echo off
if %1.==. goto end
if not exist %1 goto end
copy /b %1 +,, > nul
echo %1 touched!
:end

Posted by yvesdolc | 1 Comments

Windows 7 redirection (a.k.a. virtualization) application I use to demonstrate the effect:

C:> cl /W4 /EHsc Redirection.cpp

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Redirection.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Redirection.exe
Redirection.obj

Source: 

#pragma comment(lib, "ole32")

#pragma comment(lib, "ShlWApi")

#pragma comment(lib, "Shell32")

 

#define _WIN32_WINNT 0x0600

#define UNICODE

 

#include <windows.h>

#include <shlobj.h>

#include <shlwapi.h>

#include <iostream>

using std::wcout;

using std::endl;

 

class auto_free_com_memory {

public:

   auto_free_com_memory(void * p) : m_p(p) {}

   ~auto_free_com_memory() {if (m_p) ::CoTaskMemFree(m_p);}

private:

   void * m_p;

};

 

int wmain() {

   wchar_t * folderPath = NULL;

 

   if FAILED(SHGetKnownFolderPath(FOLDERID_ProgramFiles, KF_FLAG_CREATE, NULL , &folderPath)) {

      wcout << L"Cannot retrieve FOLDERID_ProgramFiles known folder location." << endl;

      return -1;

   }

 

   auto_free_com_memory _fp(folderPath);

 

   // System drive root redirection

   wchar_t systemDriveRoot[] = {folderPath[0], folderPath[1], folderPath[2], L'\0'};

   WCHAR filePath[MAX_PATH];

   if (wcscpy_s(filePath, systemDriveRoot) || !PathAppend(filePath, L"UAC Redirection test.log")) {

      wcout << L"Could not build the path to a file under the system drive root folder." << endl;

      return -2;

   }

 

   wcout << L"Creating \"" << filePath << L"\"." << endl;

   HANDLE file = CreateFile(filePath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

   if (file == INVALID_HANDLE_VALUE)

      wcout << L"Could not create a file under the system drive root folder. (error " << GetLastError() << L")." << endl;

   else

      CloseHandle(file);

 

   // Program Files redirection

   if (wcscpy_s(filePath, folderPath) || !PathAppend(filePath, L"MyUACRedirection")) {

      wcout << L"Could not build the path to a file under the Program File known folder." << endl;

      return -3;

   }

 

   // Does the file folder exist?

   DWORD folderAttributes = GetFileAttributes(filePath);

   if (folderAttributes == INVALID_FILE_ATTRIBUTES || ! (folderAttributes & FILE_ATTRIBUTE_DIRECTORY))  {

      wcout << L"The folder \"" << filePath << L"\" must exist and be accessible for this test to work." << endl;

      return -4;

   }

  

   if (!PathAppend(filePath, L"MyUACRedirection.log")) {

      wcout << L"Unexpected error adding the file name to \"" << filePath << "\"."<< endl;

   }

 

   wcout << L"Creating \"" << filePath << "\"." << endl;

   file = CreateFile(filePath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

  

   if (file == INVALID_HANDLE_VALUE)

      wcout << L"Could not create \"" << filePath << "\" (error " << GetLastError() << L")." << endl;

   else

      CloseHandle(file);

 

   return 0;

}

Posted by yvesdolc | 0 Comments

Windows 7 Libraries and the Common File Dialog…

As you can read in the application cookbook:

When using IFileDialog, you must use GetResult method instead of combination of GetFolder and GetFilename. Use the Shell APIs where possible to interact with and manipulate items in the Shell Namespace (for example, IShellItem).

So let me share a small code snippet I wrote. Hopefully, this will help you.

Here is how the execution looks like on my machine (Windows 7 Beta 1):

 image

image

And now the code snippet:

#include <comdef.h>
#include <shlobj.h>

_COM_SMARTPTR_TYPEDEF(IFileOpenDialog, __uuidof(IFileOpenDialog));
_COM_SMARTPTR_TYPEDEF(IShellItem, __uuidof(IShellItem));

#include <sstream>
using std::endl;
using std::wostringstream;

const wchar_t NullString[] = L"(NULL)";

void FileOpen(HWND window) {
   IFileOpenDialogPtr fileOpenDialog(__uuidof(FileOpenDialog));
   fileOpenDialog->SetTitle(L"Select any file under a Library");
   FILEOPENDIALOGOPTIONS fileOpenDialogOptions;
   fileOpenDialog->GetOptions(&fileOpenDialogOptions);
   fileOpenDialogOptions ^= FOS_FILEMUSTEXIST;
   fileOpenDialog->SetOptions(fileOpenDialogOptions);
   if (fileOpenDialog->Show(window) == HRESULT_FROM_WIN32(ERROR_CANCELLED))
      return;

   LPWSTR filename = NULL;
   fileOpenDialog->GetFileName(& filename);
   IShellItemPtr folderShellItem;
   fileOpenDialog->GetFolder(& folderShellItem);
   LPWSTR folderShellItemName = NULL;
   folderShellItem->GetDisplayName(SIGDN_FILESYSPATH, & folderShellItemName);

   IShellItemPtr resultShellItem;
   fileOpenDialog->GetResult(& resultShellItem);
   LPWSTR resultShellItemName = NULL;
   resultShellItem->GetDisplayName(SIGDN_FILESYSPATH, & resultShellItemName);

   wostringstream b;
   b << L"IFileOpenDialog::GetFileName():" << endl << (filename ? filename : NullString) << endl << endl
     << L"IShellItem::GetDisplayName() on IFileOpenDialog::GetFolder():" << endl << (folderShellItemName ? folderShellItemName : NullString) << endl << endl
     << L"IShellItem::GetDisplayName() on IFileOpenDialog::GetResult():" << endl << (resultShellItemName ? resultShellItemName : NullString);

   CoTaskMemFree(filename);
   CoTaskMemFree(folderShellItemName);
   CoTaskMemFree(resultShellItemName);

   MessageBox(GetDesktopWindow(), b.str().c_str(), L"Results of dialog", MB_OK);
}

Voilà.

Resources:

  • Windows 7: Empower users to find, visualize and organize their data with Libraries and the Explorer
  • Windows Application Quality Cookbook

     

  • Posted by yvesdolc | 0 Comments

    Getting a list of all the subscribers to an event with WinDbg and SOS

    I was wondering and Lee Culver from the CLR Quick Response Team was kind enough to give me an answer. The output below is for CLR V4 so the format might be a bit different than V2. "The debugging session below was identical in v2 except for SOS formatting differences."

    Enjoy and thanks Lee! 

    There’s no magic to it, you just walk the object until you find what you are looking for.  This object has an event called Foo:

     

    0:000> !do 0000000002dabe68

    Name:        Test

    MethodTable: 000007ff00044700

    EEClass:     000007ff00162510

    Size:        24(0x18) bytes

    File:        D:\dd\clr\src\binaries\AMD64chk\events.exe

    Fields:

                  MT    Field   Offset                 Type VT     Attr            Value Name

    000007ff00044b48  4000001        8               Test+T  0 instance 0000000002dabf48 Foo

     

    0:000> !do 0000000002dabf48

    Name:        Test+T

    MethodTable: 000007ff00044b48

    EEClass:     000007ff001629e8

    Size:        64(0x40) bytes

    File:        D:\dd\clr\src\binaries\AMD64chk\events.exe

    Fields:

                  MT    Field   Offset                 Type VT     Attr            Value Name

    000007feef8b3bc0  4000046        8        System.Object  0 instance 0000000002dabf48 _target

    000007feef8b3bc0  4000047       10        System.Object  0 instance 0000000000000000 _methodBase

    000007feef8b7388  4000048       18        System.IntPtr  1 instance      7ff0003aca8 _methodPtr

    000007feef8b7388  4000049       20        System.IntPtr  1 instance      7ff00044a10 _methodPtrAux

    000007feef8b3bc0  400004a       28        System.Object  0 instance 0000000002dabf18 _invocationList

    000007feef8b7388  400004b       30        System.IntPtr  1 instance                2 _invocationCount

     

    This has the object (_target), a method pointer (!dumpmd on _methodPtrAux or if it’s null, ln on _methodPtr), and an optional invocation list.  If the event has multiple subscribers, then _invocationList will be non-null:

    0:000> !da -details 0000000002dabf18

    Name:        System.Object[]

    MethodTable: 000007feef89b3c8

    EEClass:     000007feeef17718

    Size:        48(0x30) bytes

    Array:       Rank 1, Number of elements 2, Type CLASS

    Element Methodtable: 000007feef8b3bc0

    [snip tons of output, all of your subscribers here]

     

    Posted by yvesdolc | 0 Comments

    Is MFC 2008 Feature Pack fighting my will?

    I modify some MFC user interface related code, build, run and … nothing changes!

    “Well, let’s manually delete the Debug directories and all generated files, then rebuild.”

    I can still see my initial user interface layout! I go back to the code; double check what I did is correct, rebuild, STILL NO VISUAL CHANGE!

    I did the previous steps several times when it hit me: the layout is stored/saved in the registry between executions! From the documentation:

  • Save and restore toolbar and menu states to the registry.

  • Access the workspace manager that persists customization settings to the registry.

     

    What if there would be a bug in that part? Thanks to that line in my wizard generated application class:

       SetRegistryKey(_T("Local AppWizard-Generated Applications"));

    I know where to look for the registry key I need to delete!

    By the way, I hope that by the time we release Visual C++ 10, we’ll finally have dropped those TCHAR.H macros! It’s close to 2009 and the world has definitively been going Unicode for a while now! But I digress…

    I rebuild my application again and try it: the last version of my user interface there! So there’s a bug in “our” MFC code.

    I ended up adding the following post-build event to each configuration for now:

       reg.exe DELETE "HKCU\Software\Local AppWizard-Generated Applications\$(TargetName)" /F

  • Posted by yvesdolc | 0 Comments

    The OEM Ready Program and RMTool.exe

    On the The OEM Ready Program page, OEM’s can download the OEM Ready Program Test Cases for Windows Vista.

     

    The 7th test is to verify that the application is Restart Manager Aware. To test this, you must use RMTool.exe but where do you get it from? Mentioned in the appendix of the document is a link to the Vista Logo Tools.

     

    Once installed:

     

    gci 'C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows' -r | % { if (!$_.PSIsContainer) {$_.Fullname}}
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\CreateLogoUsers.cmd
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\Logo Testing Tools for Windows.rtf
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RegDiff\filter
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RegDiff\RegDiff.exe
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RegDump\RegDump.exe
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\Restart Manager\AMD64\RMTool.exe
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\Restart Manager\x86\RMTool.exe
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RollBack\InjectFailure\failhere.DLL
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RollBack\InjectFailure\FailInstallFromCommitCustomAction.msm
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\RollBack\InjectFailure\FailInstallFromDeferredCustomAction.msm
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\ThreadHijacker\AMD64\threadhijacker.exe
    C:\Program Files (x86)\Microsoft Corporation\Logo Testing Tools for Windows\ThreadHijacker\x86\threadhijacker.exe

     

    If you want to test an application (e.g. Notepad++):

     

    [50] rmtool /?

    RMTool.exe [-l] [-p PID] [-f file] [-s svc] [-i file]  [-F] [-S] [-R] [-A]

            -p PID  Process id to register with Restart Manager
            -f file File to register with Restart Manager
            -s svc  Service to register with Restart Manager
            -i file Read files to register from specified file (must be unicode)
            -w n    Wait n sec before starting pass.
            -F      Force shutdown
            -A      Shutdown only if all apps restartable
            -S      Shutdown applications.
            -R      Restart applications. (includes -S)
            -l[rofw]        Logoff or shutdown saving app state.
                    r - Reboot the machine.
                    o - Turn the machine off.
                    f - Operate forcefully.
                    w - Use ExitWindows() instead of InitiateShutdown().

        By default RMTool will only query information about
        affected processes. Use the -S,-R flags to enable

        shutdown/restart behaviors.

            Note: You can specify up to 25 items of each type
            to register. To add multiple items, repeat the flag
            and item specifier.

                    Eg.  RMTool.exe -p 123 -p 456 ...

    [51] (ps -Name Note*).Id
    3780

    [52] rmtool -p 3780 –S
    Starting Session
    StartSession() returned 0
    SUCCESS: StartSession()
    Session Key: 56feb14b111fd340b6d872d72d4e8ca6?
    Registering file
    RegisterResources() returned 0
    SUCCESS: RegisterResources()
    Getting affected apps.
    RmGetList() needs 1 structs, reboot reasons 0, returned 0xea
    SUCCESS: Allocating RM_PROCESS_INFO array
    SUCCESS: GetAffectedApps()
    My PID: 3624, Affected Apps: 1, needed 1, reboot reasons 0
        PID(1:3780, type 1, stat 1) - Notepad++ : a free (GNU) source code editor ()
    Shuting down applications
    SUCCESS: RmShutdown()
    Getting affected apps.
    RmGetList() needs 1 structs, reboot reasons 0, returned 0xea
    SUCCESS: Allocating RM_PROCESS_INFO array
    SUCCESS: GetAffectedApps()
    My PID: 3624, Affected Apps: 1, needed 1, reboot reasons 0
        PID(1:3780, type 1, stat 2) - Notepad++ : a free (GNU) source code editor ()
    Ending Session
    EndSession() returned 0
    SUCCESS: EndSession()

     

    Resources in case you want to do more than follow the basic requirement:

    1.       Restart Manager

    2.       Restart Manager in Vista for developers

    3.       Windows Installer and Restart Manager: MSI Files-In-Use V2

    4.       (Re-)Start Me Up ...

     

    À demain, si on le veut bien…

    Posted by yvesdolc | 1 Comments

    Windows Resource Protection API call and PowerShell 2.0

    A month ago, I was lucky enough to give a presentation on Isolated Applications and Side-by-side Assemblies to an ISV. Later, Maarten asked me if the side-by-side cache was protected by Windows Resource Protection. I checked and answered (“Yes”) but still wished I had a tool to quickly check if a file was protected or not. So I took this opportunity to learn a bit more about Boost:

    #include <wtypes.h>

    #include <boost/filesystem.hpp>

    #include <iostream>

    #include <Sfc.h>

     

    #pragma comment(lib, "sfc")

     

    using namespace boost::filesystem;

    using namespace std;

     

    int wmain() {

       basic_recursive_directory_iterator<wpath> end_iterator;

       basic_recursive_directory_iterator<wpath> iterator(L"C:\\Windows");

       while (iterator != end_iterator) {

          if (is_regular(iterator->status())) {

             if (!SfcIsFileProtected(NULL, iterator->path().string().c_str()))

                wcout << iterator->path() << endl;

          }

          try {

             ++iterator;

          } catch (basic_filesystem_error<wpath> & e) {

             wcout << L"\n\nException!" << endl

                   << e.what() << endl

                   << e.path1() << endl;

          }

       }

     

       return 0;

    }

     

    But as Maarten doesn’t like C++, I decided to look at how to do this with PowerShell 2.0:

     

    Add-Type -MemberDefinition '[DllImport("sfc.dll", CharSet = CharSet.Unicode, EntryPoint = "SfcIsFileProtected")] public static extern bool IsFileProtected(IntPtr zero, String filename);' -Name 'WindowsResourceProtection' -Namespace 'Win32'

     

    function IsFileProtected {

    param([string] $f = $(throw 'Please specify a file'))

    return [Win32.WindowsResourceProtection]::IsFileProtected([IntPtr]::Zero, $f)

    }

     

    gci \Windows -r | ? {!(IsFileProtected($_))}

     

    Of course, I guess I could have used SFC.EXE /VERIFYFILE=

    But how would I have learned about those other topics then? Eh Maarten?

    Posted by yvesdolc | 0 Comments

    Native Manifests: let's do COM and forget the Registry...

    You might have heard about it, might have seen those filenames ending with the .manifest extension, heard about the side-by-side directory ($env:windir\WinSxS), seen those project properties in Visual C++ but have you ever done anything explicit with that feature?

    I would like to share a simple example that involves a custom COM interface on a CoClass being called by a simple executable.

    Pretty boring in those days of [...]LINQ[...] and W[.]F topics... I know, I know.

    What if we do that without registering anything in the Registry? COM without the Registry?

    Yes, you can. I know that there are still a majority of you developing native code so here is the simple client part:

    #include <ObjBase.h>
    #include "..\Manifests.TheDLL\ManifestsTheDLL_i.h" // Result of IDL compilation of the component.

    int wmain() {
          if FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))
                return -1;
          ITheInterface * theInterface = NULL;
          __try {
             if FAILED(CoCreateInstance(__uuidof(TheCoClass), NULL, CLSCTX_INPROC, IID_PPV_ARGS(&theInterface)))
                return -2;
             theInterface->TheMethod(L"Message from the executable.");
          } __finally {
                if (theInterface)
                      theInterface->Release();
          }
          CoUninitialize();
          return 0;

    }

    And the custom part in the ATL-based inproc component:

    STDAPI DllRegisterServer() {
      return E_FAIL;
    }

    STDAPI DllUnregisterServer() {
       return E_FAIL;
    }

    ...

    STDMETHODIMP TheCoClass::TheMethod(wchar_t * message) {
       MessageBox(GetDesktopWindow(), message, L"Live from the TheCoClass class", MB_OK);
       return S_OK;
    }

    Build the solution and run the executable, the message box appears! What you've been witnessing is regfree COM! I'll put some resources at the end of this blog entry but for now, let me share a bit more.

    First, let's Allow Isolation (default) and "disable UAC" for the DLL:

    image

    If we don’t disable UAC for the DLL, the application will fail to load the DLL and we’ll have an error event:

    Activation context generation failed for "d:\Users\YvesDolc\Documents\Visual Studio 2008\Projects\Manifests\Debug\Manifests.TheApplication.exe".Error in manifest or policy file "d:\Users\YvesDolc\Documents\Visual Studio 2008\Projects\Manifests\Debug\Manifests.TheDLL.DLL" on line 2. The requestedPrivileges element is not allowed in component manifest.

    I  set the Assembly Identity below to Manifests.TheDLL, processorArchitecture=X86, version=1.2.3.4, type=win32:

    image

    Then, under Isolated COM:

    image

    When building, Manifests.TheDLL.DLL.embed.manifest gets generated, compiled and stored in the resource of the component:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <
    assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
    >
       <
    assemblyIdentity name="Manifests.TheDLL" processorArchitecture="X86" type="win32" version="1.2.3.4"></assemblyIdentity
    >
       <
    dependency
    >
          <
    dependentAssembly
    >
             <
    assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity
    >
          </
    dependentAssembly
    >
       </
    dependency
    >
       <
    dependency
    >
          <
    dependentAssembly
    >
             <
    assemblyIdentity type="win32" name="Microsoft.VC90.ATL" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity
    >
          </
    dependentAssembly
    >
       </
    dependency
    >
       <
    file name="Manifests.TheDLL.dll" hashalg="SHA1"
    >
          <
    comClass clsid="{FFA34D8E-7DF5-4D99-8CD0-5784FAC1944B}" tlbid="{5F6C3293-DAA3-4721-9A19-15735B069DB6}" description="TheCoClass Class"></comClass
    >
          <
    typelib tlbid="{5F6C3293-DAA3-4721-9A19-15735B069DB6}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib
    >
       </
    file
    >
    </
    assembly>

    That's all we need for the component side. On the application side, we set the Additional Manifest Dependencies to type='win32' name='Manifests.TheDLL' version='1.2.3.4' processorArchitecture='X86':  

    image

    That triggers the generation of the following manifest:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <
    assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
    >
       <
    trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"
    >
        <
    security
    >
          <
    requestedPrivileges
    >
            <
    requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel
    >
          </
    requestedPrivileges
    >
        </
    security
    >
      </
    trustInfo
    >
      <
    dependency
    >
        <
    dependentAssembly
    >
          <
    assemblyIdentity type="win32" name="Manifests.TheDLL" version="1.2.3.4" processorArchitecture="X86"></assemblyIdentity
    >
        </
    dependentAssembly
    >
      </
    dependency
    >
      <
    dependency
    >
        <
    dependentAssembly
    >
          <
    assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity
    >
        </
    dependentAssembly
    >
      </
    dependency
    >
    </
    assembly>

    Voilà.

    I'm going to give you the solution with both projects so you can try it.

    There’s a lot more to cover but it’s time to go to bed now. À demain si on le veut bien. A dormir chiquitos y chiquitas.

    Resources:

    1. Isolated Applications and Side-by-side Assemblies
    2. How To Build and Service Isolated Applications and Side-by-Side Assemblies for Windows XP
    3. Building C/C++ Isolated Applications and Side-by-side Assemblies
    4. Side-by-Side Manifest Maker (I have not tried it but it does look interesting)

    Let me add part of a comment I received from David Janson after reviewing a draft of this blog entry:

    One thought…

    As you say below, every component has a unique identity.  However, what is important is that the component *does not change* once it exists.  For example, what if you rebuilt the COM control without making any changes.  The new component will have the same identity as the old one yet have different content.  This is simply not allowed by SxS.  Once a component has been installed with an Identity, it simply can’t change.

    Which means that Versioning is incredibly important, even during R&D.

    Every time you build a new build, you must give that new build a version that is different (higher) than the last installed build.  Otherwise you’ll get an error message like “Same identity but manifest contents are different” when you install the new build because the file hash has changed.

    Even removing the old version doesn’t quite do the trick because the SxS store uses a form of garbage collection and doesn’t delete the uninstalled files right away.  There is a trick but its much better to simply update the version every time you have a new build you want to install.

    Posted by yvesdolc | 1 Comments
    Attachment(s): Manifests (VC++2008).zip

    C++: Class hierarchy diagrams for MFC (including Visual C++ 2008 Feature Pack ones)

    These diagrams show the relationship of classes within the MFC, including the original classes released with Visual Studio 2008 plus the additional classes provided with the Visual C++ 2008 Feature Pack.
     
     
    Posted by yvesdolc | 0 Comments

    C++: Digging into C++ Technical Report 1 (TR1)

    If you're a C++ developer and not using yet the shared_ptr<> class, you're in for a surprise: http://channel9.msdn.com/ShowPost.aspx?PostID=385821

    The discussion below the video is also quite interesting: something like the "GC" camp vs. the "ref counting"...

    Thanks Stephan!

    Posted by yvesdolc | 0 Comments

    Microsoft Visual C++ Floating-Point Optimization

    As you might already know, there's such an article from Eric Fleegal on MSDN: http://msdn2.microsoft.com/en-us/library/aa289157(vs.71).aspx.

    Dave, a peer of mine, asked a related question to the C++ team and I thought the answer would be valuable to others. From Marko Radmilac:

    We haven’t provided details in the article on when we would be allowed to perform a single precision operation instead of double. Here’s the correct example:

     

    float f = (float) sqrt( (float) value);

     

    Because casts ensure that value going into sqrt and value coming out are rounded to single precision, we can change sqrt to sqrtf, thus only changing the place of rounding. If the value coming into sqrt was double value and we still performed this transformation, the results would be disastrous (up to half of precision bits could be wrong). In short, /fp:fast does whatever VS2003 was doing without /Op switch and perhaps a few other, relatively safe optimizations. For their purposes /fp:fast should be sufficient and they shouldn’t shy away from it.

     

    Marko

     

    P.S. The example for the other downcast is as follows:

     

    float f = (float) ((double) f1 + (double) f2);

     

    Since f1 and f2 are floats to begin with and we store into f, then we change this into:

     

    float f = f1 + f2;

     

    This is especially beneficial on x64 platform and x86 SSE2.

    Posted by yvesdolc | 0 Comments

    Getting old...

    I very clearly remember when Michael Brecker started his concert by faking the sound of Miles Davis with an “electronic/synthesizer saxophone”, myriad of wires hanging everywhere. I was sitting at less than 2 meters in front of him, on the stage, in the Louvain la Neuve auditorium. My friend Alex thinks it was in 1987.

    Steps Ahead’s Modern Times album must be one of the first “jazz” albums I bought, even before “Friday Night in San Francisco”. When Phillipe Baron played Safari on the radio, I knew I had to have that vinyl record!

    When I brought it at home, I think I’ve heard that tune a dozen times.

    Although it’s late notice, I just realized he past away a year ago. I think he did contribute (like John McLaughlin) in my discovery of Jazz. Thanks a lot Mike.

    http://www.patmethenygroup.com/breckertribute_layout.pdf

     

    Posted by yvesdolc | 0 Comments
    Filed under:

    C++ Variadic Templates

    Found this interesting documents/primer on that topic: http://www.osl.iu.edu/~dgregor/cpp/variadic-templates.pdf

    I wonder when we'll see this in our own compiler and thus have efficient make_shared<T> and allocate_shared<T>.

    Bonne fin de semaine.

    Posted by yvesdolc | 0 Comments

    Acquiring small targets on a screen can be challenging...

    I've installed SPB Mobile Shell, Point UI and lately TouchPal on my AT&T Tilt... I'm hungry for any mechanism to make the use of my mobile phone easier/safer...

    I decided to stick with SPB Mobile Shell for now.

    I find this video quite interesting:

    Posted by yvesdolc | 0 Comments
    Filed under:

    C# 3.0 var keyword + Enumerable.AsEnumerable

    On my way back from México, I read Pro LINQ: Language Integrated Query in C# 2008. Just like Charles Petzold first introducing WPF through code (and not markup), I like Joseph Rattz’ introduction of LINQ through [extension] methods first instead of the using query expressions. I do think this makes things easier to understand. For me at least. I did not like a big part of the book as it felt more like a reference book. But again, it’s just me.

    One thing I disagree with his advice:  page 27, he states that one should refrain from using the var keyword just because it’s convenient. I think that:

    var integers = new List<int> { 1, 2, 3 };

    is clear enough, no need for:

    List<int> integers = new List<int> { 1, 2, 3 };

    Also, on page 355, he states that strings will get boxed! Although an immutable type behaving like a value type, System.String is not a value type and will thus never be boxed. I guess he meant that the problem with c["Id"] == s["Id"] is that you’re comparing for equality of object reference you’re not comparing the content of the String instances.

    Now, one thing I tend to forget when talking to developers is that some are still trying to grasp the idea of generics. And that’s exactly what I thought about when seeing Enumerable.AsEnumerable:

    public static IEnumerable<TSource> AsEnumerable<TSource>(this IEnumerable<TSource> source) {

       return source;

    }

     

    Why would anyone need to use what looks to be such a useless code method? Look at this query expression:

    var query = from dr in orderDataTable.AsEnumerable()

                select dr.Field<int>("OrderID");

     

    If I’d like to cast OrderTable to a generic version of IEnumerable<T>, what value of T should I pick? In this example, the answer might be easy as DataTableExtensions.AsEnumerable(this DataTable source) returns an EnumerableRowCollection<DataRow> instance: we can cast to IEnumerator<DataRow>.

    Both would work:

    var query = from dr in (IEnumerable<DataRow>) orderDataTable

                select dr.Field<int>("OrderID");

    and

    var query = from dr in orderDataTable as IEnumerable<DataRow>

                select dr.Field<int>("OrderID");

     

    But as soon as you have anonymous types involved, doing something like this is impossible: you don’t know the compiler generated name of those types! What would you use as the generic IEnumerable type parameter (you know, the T in IEnumerable<T>)?

    The purpose of what looks like the simplistic Enumerable.AsEnumerable() method is hidden in its signature: the compiler will get you the right T to use in IEnumerable<T>, no need to know what it is.

    OK. I’m no LINQ expert but by writing this, I’m clarifying my thoughts. I hope this helps.

    Bonne nuit les petits.

     

    Posted by yvesdolc | 1 Comments
    More Posts Next page »
     
    Page view tracker