c++ - Pointer class variable returns NULL from muncion -
i'm developing dll (in visual studio 2013) read tiff (satellite images), using gdal library, , having issue variable data - empty (returns null).
in dll have funcion defined in "rasterfuncs.h" this:
namespace rasterfuncs { // class exported rasterfuncs.dll class myrasterfuncs { public: // open raster file static rasterfuncs_api int open(char* rname, gdaldataset *podataset); }; }
and in dll cpp have following:
namespace rasterfuncs { int myrasterfuncs::open(char* rname, gdaldataset *podataset) { podataset = (gdaldataset *) gdalopen(rname, ga_readonly); if (podataset != null) { cout << "rasterxsize 1:" << podataset->getrasterxsize() << endl; cout << "rasterysize 1:" << podataset->getrasterysize() << endl; cout << "rastercount 1:" << podataset->getrastercount() << endl; } return 0; } }
at point have podataset image data.
however, call dll form cpp using following code:
rfilename = "c:/image1.tif"; // open raster satelitte image gdaldataset *podataset = null; gdalallregister(); rasterfuncs::myrasterfuncs::open(rfilename, podataset); if (podataset != null) { cout << "rasterxsize:" << podataset->getrasterxsize() << endl; cout << "rasterysize:" << podataset->getrasterysize() << endl; cout << "rastercount:" << podataset->getrastercount() << endl; }
and when test podataset come back, shows null.
anybody in issue?
thanks in advance , best regards!
remember default arguments functions passed by value, meaning function have copy of value.
when assign podataset
variable in function, you're changing local copy. calling function not see modification. need pass argument by reference:
static rasterfuncs_api int open(char* rname, gdaldataset*& podataset);
Comments
Post a Comment