findAndGetOFStringArray difference between 3.5.5_20090818 and 3.5.5_20091222

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
prakash
Posts: 50
Joined: Mon, 2008-05-19, 10:34
Contact:

findAndGetOFStringArray difference between 3.5.5_20090818 and 3.5.5_20091222

#1 Post by prakash »

Hi,

Previously i was 3.5.5 - 200909018 dcmtk library with the following functionality and it was working absolutely fine.

OFString GetStringValue;
_DcmFileFormat.getDataset()->findAndGetOFStringArray(DCM_SOPClassUID, GetStringValue);
sprintf(GetCharValue, "%s", GetStringValue);
pDemographicInfo->SOPClassUID=SysAllocString(CComBSTR(GetCharValue));

Value:"1.3.567.43535645.546"

_DcmFileFormat.getDataset()->findAndGetOFStringArray(DCM_SpecificCharacterSet, GetStringValue);
sprintf(GetCharValue, "%s", GetStringValue);
pDemographicInfo->SpecificCharacterSet=::SysAllocString(CComBSTR(GetCharValue));

Value:"ISO_IR 100"

I am getting correct values with that(3.5.5 - 200909018)library

Now i have changed to 3.5.5 - 20091222 library and using the same code i am getting SpecificCharacterSet value as"ISO_IR 10035645.546"


Why i am getting this kind of values. Does i need to modify any thing in code. Please suggest..

Thnaks in advance

J. Riesmeier
DCMTK Developer
Posts: 2512
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

#2 Post by J. Riesmeier »

This line here is the reason for your problems:

Code: Select all

sprintf(GetCharValue, "%s", GetStringValue);
GetStringValue is an instance of a C++ string class (same interface than standard string), so you have to call the method c_str() in order to get the char*. Your code used to work in previous versions since internally the string value was always null-terminated. Now, the OFString is implemented in a more standard/optimized way and, therefore, the code does not work anymore. It probably also did never work with the standard string class (i.e. when HAVE_STD_STRING is defined).

Btw, why don't you just use findAndGetString()?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest