geting C-Find data out?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
seabhcan
Posts: 7
Joined: Fri, 2007-05-04, 16:04

geting C-Find data out?

#1 Post by seabhcan »

I'm writing a wrapper for the dcmnet code in order to make a dll accessible from c# or java.

Does anybody know an elegant way to get the c-find results out? At the moment they are writing to cout.

seabhcan
Posts: 7
Joined: Fri, 2007-05-04, 16:04

#2 Post by seabhcan »

Here's the solution I've come up with, but I'm open to suggestions of improvements:

Taking the code of FindSCU I added the global variable:
#include <iostream>
#include <tchar.h>
#include <sstream>
#include <string>

ostringstream g_outStreamTEXT;
ostringstream is a sting that behaves like a stream. When I open the association I clear the string like this:
g_outStreamTEXT.str("");
Then in the progressCallBack, when the data is returned in the responseIdentifiers DcmDataSet, I print the data to the ostringstream:
responseIdentifiers->print(g_outStreamTEXT);
Then I have a dllexport function which allows access to this string as follows:
extern "C" __declspec(dllexport) int OutputDcmDatasetTEXT(char * output)
{
strcpy(output, g_outStreamTEXT.str().c_str());
return(0);
}
Then compile this as a Dll and import it into a c# windows form application. In C# the following code is required:
[DllImport("DICOMDLLtest.dll", CharSet=CharSet.Ansi)]
private static extern int OutputDcmDatasetTEXT([MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer);

public static string OutputText()
{
byte[] str=new byte[2000];
OutputDcmDatasetTEXT(str);
return System.Text.Encoding.ASCII.GetString(str);
}
c# passes a byte array to the c++ dicom code, which treats it like a char pointer and copies the data to it.

c# can then access the Dicom records returned by C-Find using OutputText()

Is there a better way to do this?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#3 Post by Marco Eichelberg »

Is there a better way to do this?
This depends on what you want to or can do with DICOM data on the C# level. You could of course serialize the C-FIND dataset into a DICOM object (byte stream) and pass that to the C# side, or you could create an API that would allow the C# code to access individual attribute values of the C-FIND response dataset (through callbacks). The latter would certainly be more reliable than parsing the output of DcmDataset::print(). And, by the way, there is no reason why a dataset dump should not be longer than 2000 bytes, thus crashing your code. Fixed size buffers are a bad idea most of the time.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest