failed to create dicomdir

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Roland
Posts: 10
Joined: Wed, 2009-12-02, 03:55

failed to create dicomdir

#1 Post by Roland »

Hi i'm trying to create a dicomdir and having a problem
I'm working with DCMTK 3.5.4 ,VC6.0

here what i'm doing :


{
DicomDirInterface dcmDir;

dcmDir.createNewDicomDir(DicomDirInterface::Ap_Default, "d:\\Temp\\DICOMDIR");

dcmDir.addDicomFile("Image\\Img0001","d:\\Temp");

dcmDir.writeDicomDir()
}

i try to debug ,but an error is found.

I follow up and find that the error is in this function

OFCondition DcmDicomDir::write(const E_TransferSyntax oxfer,
const E_EncodingType enctype,
const E_GrpLenEncoding glenc)

where:
#ifdef HAVE_MKTEMP
mktemp( tempfile );
#endif
DcmOutputFileStream *outStream = new DcmOutputFileStream(tempfile);

the error is the mktemp , do with the tempfile .

what i'm doing wrong ??

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#2 Post by Michael Onken »

Hi,

which operating system does the resulting program run on? As we have heard, mktemp is making problems under Vista (maybe also Windows 7) because there mktemp is usually returning a filename in the root directory which then cannot be written (no rights) from the process. Maybe also the working directory (on XP, not sure about that) is also choosen for the temporary filename, be sure it is writeable.

Best regards,
Michael

Roland
Posts: 10
Joined: Wed, 2009-12-02, 03:55

#3 Post by Roland »

My operating system is XP ,
and the error is the memory of 0x00000010 can not be written

Thanks. :)

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#4 Post by Michael Onken »

Hi,

how much memory is reserverd for the tempfile variable? What does it contain after the mktemp call?

Regards,
Michael

Roland
Posts: 10
Joined: Wed, 2009-12-02, 03:55

#5 Post by Roland »

before the mktemp call, tempfile = d:\\Temp\\DDXXXXXX,
then the mktemp call(system func):

Code: Select all

_TSCHAR * __cdecl _tmktemp (
        _TSCHAR *template
        )
{
        _TSCHAR *string = template;
        unsigned number;
        int letter = _T('a');
        int xcount = 0;
        int olderrno;

        _ASSERTE(template != NULL);
        _ASSERTE(*template != _T('\0'));

        /*
         * The Process ID is not a good choice in multi-threaded programs
         * because of the likelihood that two threads might call mktemp()
         * almost simultaneously, thus getting the same temporary name.
         * Instead, the Win32 Thread ID is used, because it is unique across
         * all threads in all processes currently running.
         *
         * Note, however, that unlike *NIX process IDs, which are not re-used
         * until all values up to 32K have been used, Win32 process IDs are
         * re-used and tend to always be relatively small numbers.  Same for
         * thread IDs.
         */
#ifdef _MT
        number = __threadid();
#else  /* _MT */
        number = _getpid();
#endif  /* _MT */

        while (*string)
                string++;                                          // here ,  string=' ';
 
        /* replace last five X's */
#ifdef _MBCS
        while ((--string>=template) && (!_ismbstrail(template,string))
                 && (*string == 'X') && xcount < 5)    // here , error come out  


#else  /* _MBCS */
        while (*--string == _T('X') && xcount < 5)
#endif  /* _MBCS */
        {
                xcount++;
                *string = (_TSCHAR)((number % 10) + '0');
                number /= 10;
        }

        /* too few X's ? */
        if (*string != _T('X') || xcount < 5)
                return(NULL);

        /* set first X */
        *string = letter++;

        olderrno = errno;       /* save current errno */
        errno = 0;              /* make sure errno isn't EACCESS */

        /* check all the files 'a'-'z' */
        while ((_taccess(template,0) == 0) || (errno == EACCES))
        /* while file exists */
        {
                errno = 0;
                if (letter == _T('z') + 1) {
                        errno = olderrno;
                        return(NULL);
                }

                *string = (_TSCHAR)letter++;
        }

        errno = olderrno;
        return(template);
}

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#6 Post by Michael Onken »

Sorry, I have no special idea. The only thing is that, as far as I know, you must reserve the memory for the filename creation yourself and maybe it's too short. Try initializing the tempfile variable with "char tempfile[50]" or something before using it in mktemp.

Regards,
Michael

Roland
Posts: 10
Joined: Wed, 2009-12-02, 03:55

#7 Post by Roland »

I had to create dicomdir by myself ,
Thanks all the same

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 1 guest