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.
geting C-Find data out?
Moderator: Moderator Team
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:
c# can then access the Dicom records returned by C-Find using OutputText()
Is there a better way to do this?
Taking the code of FindSCU I added the global variable:
ostringstream is a sting that behaves like a stream. When I open the association I clear the string like this:#include <iostream>
#include <tchar.h>
#include <sstream>
#include <string>
ostringstream g_outStreamTEXT;
Then in the progressCallBack, when the data is returned in the responseIdentifiers DcmDataSet, I print the data to the ostringstream:g_outStreamTEXT.str("");
Then I have a dllexport function which allows access to this string as follows:responseIdentifiers->print(g_outStreamTEXT);
Then compile this as a Dll and import it into a c# windows form application. In C# the following code is required:extern "C" __declspec(dllexport) int OutputDcmDatasetTEXT(char * output)
{
strcpy(output, g_outStreamTEXT.str().c_str());
return(0);
}
c# passes a byte array to the c++ dicom code, which treats it like a char pointer and copies the data to it.[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# can then access the Dicom records returned by C-Find using OutputText()
Is there a better way to do this?
-
- OFFIS DICOM Team
- Posts: 1461
- Joined: Tue, 2004-11-02, 17:22
- Location: Oldenburg, Germany
- Contact:
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.Is there a better way to do this?
Who is online
Users browsing this forum: No registered users and 1 guest