Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dll not working -- Please look at my code!

Status
Not open for further replies.

Shawnasie

Programmer
Aug 19, 2008
23
US
I am using a dll which allows me to create files containing both images and data about the images. I don't get an error when I run my program. However, when I go to view the files in a special viewer, it won't show a particular section. So, something is wrong with the way that I am entering the fields. If anyone has any ideas, I would so appreciate it. I am getting a little desperate. I am using Borland Builder 2009.

Here is my code:
Code:
HINSTANCE hNitfDLL = LoadLibrary( "C:\\Documents and Settings\\Lab1\\My Documents\\RAD Studio\\Projects\\TWriteNitf2.dll" );

if(hNitfDLL == 0)
{
   //failed
    return;
}

typedef void*  (*pCreateFunc)();     // DLL function typedefs
pCreateFunc    pfnCreate;        // pointer to DLL "create" func

pfnCreate  = reinterpret_cast<pCreateFunc>(GetProcAddress(hNitfDLL, "_CreateTWriteNitf21Instance"));
TMainIFace *nitf = static_cast<TMainIFace *>(pfnCreate());

TTextIFace *text = nitf->AddText();
char szbuf[] = "my nitf text block";
text->AddData(szbuf, strlen(szbuf));

TImageIFace * img = nitf->AddImage();
AnsiString strimg = imageNames->Strings[j];
img->AddJpeg("C:\\Documents and Settings\\Lab1\\My Documents\\My Pictures\\AllenMtn.jpg",JCS_YCbCr,736,648);

//File Header
TBaseHeaderIFace * fileHdr = nitf->Header();


fileHdr->SetField("FTITLE", FTITLE.c_str(),FTITLE.Length());

fileHdr->SetField("FSCOP","1");
fileHdr->SetField("ONAME","Operator");


//Image Header
TImageHeaderIFace * imgHdr = img->Header();
imgHdr->SetField("IDATIM", dateTime.c_str());


imgHdr->SetField("ICORDS", "G");
imgHdr->SetField("IGEOLO",IGEOLO.c_str(),IGEOLO.Length());


//Controlled Extension Subheader
TControlledExtensionIFace * ceHdr = imgHdr->AddCE();
ceHdr->LoadXML("SENSRA.xml");
ceHdr->SetField("SENSOR_LOC",SensorLocation.c_str());
//ceHdr->SetField("SENSOR_ALT",altitude);
//ceHdr->SetField("SENSOR_ALT_UNIT",ALT_UNIT.c_str(),ALT_UNIT.Length());

AnsiString nitfName = "TestNitf" + AnsiString(j)+ ".ntf";
nitf->Write(nitfName.c_str());

delete nitf;

FreeLibrary(hNitfDLL);

It is the controlled extension (addCE) part that is not showing up. And here is some of the virtual code from the dll, in case that sheds some light.

Code:
class TBaseHeaderIFace;

typedef struct
{
   TBaseHeaderIFace const *Header;
   char FieldName[10];
   char FieldValue[300];
   char FieldDesc[300];
} TError;

class TBaseHeaderIFace
{
public:
   virtual const char* ToString() const = 0;
   virtual unsigned int Size() = 0;
   virtual bool SetField(const char* AField, const char* AValue, unsigned int ASize = 0) = 0;
   virtual bool SetField(const char* AField, unsigned int AValue) = 0;
   virtual char* GetFieldValue(const char* AField, char* AValue) = 0;
   virtual int GetFieldValueInt(const char* AField) = 0;
   virtual unsigned int GetFieldSize(const char* AField) = 0;
   virtual TEntry GetField(const char* AField) = 0;
   virtual TEntry GetField(unsigned int AIndex) = 0;
   virtual unsigned int GetNumFields() const = 0;
   virtual bool Validate() = 0;
   virtual void Clear() = 0;
   virtual THdrType Type() const = 0;
   virtual TNITFFormat Version() = 0;

   virtual unsigned int GetNumErrors() const = 0;
   virtual TError ErrorList(unsigned int A) const = 0;

   virtual void SetObject(void *AObj) = 0;
   virtual void* GetObject() = 0;
};

class TCEBaseHeaderIFace;
class TUDCEBaseHeaderIFace;

class TControlledExtensionIFace : virtual public TBaseHeaderIFace
{
public:
   virtual TControlledExtensionIFace& operator=(const TControlledExtensionIFace& Hdr) = 0;
   virtual bool LoadXML(const char* ACEName) = 0;
   virtual void LoadStr(char* ACE, unsigned int ASize) = 0;   //using LoadStr disallows any
   virtual void Delete() = 0;   

   virtual void SetParent(TCEBaseHeaderIFace* const AParent) = 0;
   virtual TCEBaseHeaderIFace *const GetParent() = 0;
};
class TCEBaseHeaderIFace : virtual public TBaseHeaderIFace
{
public:
   virtual TControlledExtensionIFace* const AddCE() = 0;
   virtual void DeleteCE(TControlledExtensionIFace* const ACE) = 0;

   virtual unsigned int CEListSize() = 0;
   virtual TControlledExtensionIFace* const CEList(unsigned int Ai) = 0;

   virtual void SetCELengths() = 0;
};
 
Well, I found what was wrong. The LoadXML() function couldn't find the xml specified. I moved it into the debug folder and problem solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top