help about write to dicom file! Thanks!!

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
myching
Posts: 12
Joined: Wed, 2005-09-21, 09:58

help about write to dicom file! Thanks!!

#1 Post by myching »

I use the fellowing example code to write a dicom file :

char uid[100];
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_PatientsName, "Doe^John");
/* ... */
// dataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pixelLength);
OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianImplicit);
if (status.bad())
cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;


in VC enviroment ,I debug it OK.But When I run it,I get a lots of error,mainly about "_CrtIsValidHeapPointer" ,such as
"
Debug Assertion Failed!

Program :....\dicomdemo.exe
File dbgheap.c
Line:1044
Expression:_CrtIsValidHeapPointer(pUserData)
.........
"

when i ignore them, I get a dicom file. but why these error occur?


Any one can help me?thanks!!

Alexander Fedotov
Posts: 53
Joined: Thu, 2005-04-14, 15:07
Location: St. Petersburg, Russia

Re: help about write to dicom file! Thanks!!

#2 Post by Alexander Fedotov »

[quote="myching"]
When I run it,I get a lots of error,mainly about "_CrtIsValidHeapPointer" ,such as
"
Debug Assertion Failed!

Program :....\dicomdemo.exe
File dbgheap.c
Line:1044
Expression:_CrtIsValidHeapPointer(pUserData)
.........
[/quote]


You can find an explanation in dbgheap.c:
------------------------------
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
------------------------------

And in MSDN:
------------------------------
The following example uses _CrtIsValidHeapPointer to verify a pointer points to memory in the local heap (the heap created and managed by this instance of the C run-time library — a DLL can have its own instance of the library, and therefore its own heap, outside of the application heap). This assertion catches not only null or out-of-bounds addresses, but also pointers to static variables, stack variables, and any other nonlocal memory.

_ASSERTE(_CrtIsValidPointer( myData );

------------------------------

So, you have a problem with the memory managment.

Alexander.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest