Create a world file.
CreateWorldFile.cpp
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

  
#include "CreateWorldFile.h"

int main(int argc, char** argv)
{
  cout << "CreateWorldFile - "
       << "ArcObjects C++ SDK Developer Sample" << endl << endl;
  
  if (argc != 2)
  {
    cout << "Usage: CreateWorldFile [input raster]" << endl;
      
    AoExit(0);    
  }
  
  char* input = argv[1];
  
  if (!InitializeApp())
  {
    AoExit(0);
  }

  // Create the world file
  Create(input);
  
  ShutdownApp();
  AoExit(0);
}

HRESULT Create(char* input)
{
  // data location
  CComBSTR dataPath;
  CComBSTR dataFile;

  HRESULT hr = GetParentDirFromFullPath(input, &dataPath);
  if (FAILED(hr) || dataPath.Length() <= 0)
  {
    cerr << "Failed to get path name." << endl;
    return E_FAIL;
  }
  hr = GetFileFromFullPath(input, &dataFile);
  if (FAILED(hr) || dataFile.Length() <= 0)
  {
    cerr << "Failed to get file name." << endl;
    return E_FAIL;
  }

  // Get the raster workspace through the workspace factory.
  IWorkspaceFactoryPtr ipRasWkspFac(CLSID_RasterWorkspaceFactory);
  IWorkspacePtr ipWksp;
  hr = ipRasWkspFac->OpenFromFile(dataPath, 0, &ipWksp);
  if (FAILED(hr) || ipWksp == 0)
  {
    std::cerr << "Couldn't open the workspace." << std::endl;
    return hr;
  }

  IRasterDatasetPtr ipRasDataset;
  hr = ((IRasterWorkspacePtr) ipWksp)->OpenRasterDataset(dataFile, &ipRasDataset);  
  if (FAILED(hr) || ipRasDataset == 0)
  {
    std::cerr << "Couldn't open the raster Dataset." << std::endl;
    return hr;
  }

  // Create world file
  IWorldFileExportPtr ipWorldFile(ipRasDataset);
  hr = ipWorldFile->Write();
  if (SUCCEEDED(hr))
    cout << "World file has been created!" << endl; 
  else
    cout << "Could not create world file." << endl;
  return S_OK;
}