Here's just the nuts-and-bolts from some working code:
// in main()...
GDALAllRegister(); // register all drivers
// open your raster - format doesn't matter as all the drivers are registered
GDALDataset* SourceRasterDS = (GDALDataset*) GDALOpen(Raster,GA_ReadOnly);
double GeoTransform; // Get the geotransform object
SourceRasterDS->GetGeoTransform(GeoTransform); // from the raster dataset
GDALRasterBand* SrcBnd = SourceRasterDS->GetRasterBand(1); // just one band - 1 based, not 0. This raster has only one band.
// read 32bit floating point raster
float* RasterBlock = (float*)malloc(ReadRows*ReadCols*sizeof(float));
// localize the X,Y offset to the raster block
LocalX = GeoTransform + (ColOff * GeoTransform);
LocalY = GeoTransform + (RowOff * GeoTransform);
// get a cell in the block - convert X,Y to Col,Row
ThisCol = (Xcoord - LocalX) / GeoTransform;
ThisRow = (Ycoord - LocalY) / GeoTransform;
// find the index in the 1-d (one dimension, not One Direction) array
LocInArray = (ReadCols*ThisRow) + ThisCol;
CellValue = RasterBlock[LocInArray];
This code gets the value of one cell in a block in the raster.. the original raster was over 2TB as IMG so I couldn't read the whole thing into memory but I needed to do operations within a specified AOI which is translated to ColOff,RowOff and ReadCols by ReadRows rather than trying to read each cell directly from the source raster.
As I said in my comments it is important to set your paths and also add the additional dependency gdal_i.lib or the code will not link properly:
Creating/Writing raster is also fairly straightforward:
GDALDriver* IMGdriver = GetGDALDriverManager()->GetDriverByName(DRVname); // get the ERDAS Imagine driver
AccumDS = (GDALDataset*) IMGdriver->Create(AccumName,Cols,Rows,1,GDALDataType::GDT_UInt32,NULL);
AccumData = (unsigned __int32*) malloc(MaxLasRasterSize * 4); // sizeof(__int32) = 4 ALWAYS!!!
GDALClose((GDALDatasetH)AccumDS); // very important to close the dataset
This code is missing about 500 lines between creating the memory (AccumData) and writing it - but that's not important in this context. Just remember that you need to address in Col,Row from this current block when modifying values in the memory and you should be fine.
When you download GDAL be sure to download the source, in the tools folder there are some spectacular examples of how to use GDAL that I used as a learning aid, you should find some value in them too.
In Visual Studio (this example from 2010) you need to set some properties in your project:
To ensure that the compiler/linker can find the inputs that it needs.