//=====================================================================
// SendDICOM.cpp : Defines the entry point for the DLL application.
//
// Created by yeti 2011
//=====================================================================
#include "stdafx.h"
#include "SendDICOM.h"
#include "osconfig.h" /* make sure OS specific configuration is included first */
#define INCLUDE_CSTDLIB
#define INCLUDE_CSTDIO
#define INCLUDE_CSTRING
#define INCLUDE_CERRNO
#define INCLUDE_CSTDARG
#define INCLUDE_CCTYPE
#include "ofstdinc.h"
BEGIN_EXTERN_C
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
END_EXTERN_C
#ifdef HAVE_GUSI_H
#include <GUSI.h>
#endif
#include "ofstring.h"
#include "dimse.h"
#include "diutil.h"
#include "dcdatset.h"
#include "dcmetinf.h"
#include "dcfilefo.h"
#include "dcdebug.h"
#include "dcuid.h"
#include "dcdict.h"
#include "dcdeftag.h"
#include "cmdlnarg.h"
#include "ofconapp.h"
#include "dcuid.h" /* for dcmtk version name */
#include "dicom.h" /* for DICOM_APPLICATION_REQUESTOR */
#include "dcostrmz.h" /* for dcmZlibCompressionLevel */
#include "dcasccfg.h" /* for class DcmAssociationConfiguration */
#include "dcasccff.h" /* for class DcmAssociationConfigurationFile */
#ifdef ON_THE_FLY_COMPRESSION
#include "djdecode.h" /* for dcmjpeg decoders */
#include "djencode.h" /* for dcmjpeg encoders */
#include "dcrledrg.h" /* for DcmRLEDecoderRegistration */
#include "dcrleerg.h" /* for DcmRLEEncoderRegistration */
#endif
#ifdef WITH_OPENSSL
#include "tlstrans.h"
#include "tlslayer.h"
#endif
#include "WINSOCK.H"
#ifdef WITH_ZLIB
#include <zlib.h> /* for zlibVersion() */
#endif
static E_TransferSyntax opt_networkTransferSyntax = EXS_Unknown;
static OFBool opt_proposeOnlyRequiredPresentationContexts = OFFalse;
static OFBool opt_combineProposedTransferSyntaxes = OFFalse;
static OFCmdUnsignedInt opt_repeatCount = 1;
static OFBool opt_haltOnUnsuccessfulStore = OFTrue;
static OFCmdUnsignedInt opt_inventPatientCount = 25;
static OFCmdUnsignedInt opt_inventStudyCount = 50;
static OFCmdUnsignedInt opt_inventSeriesCount = 100;
static OFBool opt_inventSOPInstanceInformation = OFFalse;
static OFBool opt_correctUIDPadding = OFFalse;
static OFBool unsuccessfulStoreEncountered = OFFalse;
static OFBool opt_verbose = OFFalse;
static OFBool opt_showPresentationContexts = OFFalse;
static OFBool opt_debug = OFFalse;
static OFBool opt_abortAssociation = OFFalse;
static OFCmdUnsignedInt opt_maxReceivePDULength = ASC_DEFAULTMAXPDU;
static OFCmdUnsignedInt opt_maxSendPDULength = 0;
T_DIMSE_BlockingMode opt_blockMode = DIMSE_BLOCKING;
int opt_dimse_timeout = 0;
int opt_acse_timeout = 30;
static int lastStatusCode = STATUS_Success;
static OFString studyIDPrefix("SID_"); // StudyID is SH (maximum 16 chars)
static OFString accessionNumberPrefix; // AccessionNumber is SH (maximum 16 chars)
static OFString patientIDPrefix("PID_"); // PatientID is LO (maximum 64 chars)
static OFString patientNamePrefix("OFFIS^TEST_PN_"); // PatientName is PN (maximum 16 chars)
static OFCondition
addStoragePresentationContexts(T_ASC_Parameters *params, OFList<OFString>& sopClasses);
static OFCondition
cstore(T_ASC_Association * assoc, const OFString& fname);
static OFBool
isaListMember(OFList<OFString>& lst, OFString& s);
static OFCondition
addPresentationContext(T_ASC_Parameters *params,
int presentationContextId, const OFString& abstractSyntax,
const OFList<OFString>& transferSyntaxList,
T_ASC_SC_ROLE proposedRole = ASC_SC_ROLE_DEFAULT);
static OFCondition
addPresentationContext(T_ASC_Parameters *params,
int presentationContextId, const OFString& abstractSyntax,
const OFString& transferSyntax,
T_ASC_SC_ROLE proposedRole = ASC_SC_ROLE_DEFAULT);
static OFCondition
storeSCU(T_ASC_Association * assoc, const char *fname);
static void
replaceSOPInstanceInformation(DcmDataset* dataset);
static void
progressCallback(void * /*callbackData*/,
T_DIMSE_StoreProgress *progress,
T_DIMSE_C_StoreRQ * /*req*/);
static OFString
makeUID(OFString basePrefix, int counter);
static int
secondsSince1970();
static OFString
intToString(int i);
static OFBool
updateStringAttributeValue(DcmItem* dataset, const DcmTagKey& key, OFString& value);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int IncInt(int params)
{
return params+1;
}
//int IniNet
/*==========================================================*/
//Created by hgb 20061229
//result value:
//0: success
//-1: not foud file
//-2:
//-3:
//-4:
//-5:
/*==========================================================*/
int __stdcall SendDCM(LPSTR ourTitle, LPSTR peerTitle,
LPSTR scpIP, LPSTR scpPort, LPSTR FileName)
{
char sopClassUID[128];
char sopInstanceUID[128];
OFList<OFString> fileNameList;
OFList<OFString> sopClassUIDList;
OFList<OFString> sopInstanceUIDList;
T_ASC_Network *net;
T_ASC_Parameters *params;
DIC_NODENAME localHost;
DIC_NODENAME peerHost;
T_ASC_Association *assoc;
//TCHAR tcsModulePath[_MAX_PATH];
//::GetModuleFileName(NULL, tcsModulePath, _MAX_PATH);
//CString strCurDir = tcsModulePath;
//strCurDir = strCurDir.Left(strCurDir.ReverseFind(TEXT('\\'))+1);
//char currentFilename[strCurDir.GetLength()+1];
//strcpy(currentFilename, strCurDir.GetBuffer());
//char *currentFilename = strCurDir;
#ifdef HAVE_GUSI_H
GUSISetup(GUSIwithSIOUXSockets);
GUSISetup(GUSIwithInternetSockets);
#endif
#ifdef HAVE_WINSOCK_H
WSAData winSockData;
/* we need at least version 1.1 */
WORD winSockVersionNeeded = MAKEWORD( 1, 1 );
WSAStartup(winSockVersionNeeded, &winSockData);
#endif
/*
CFileFind find;
if(find.FindFile(FileName))
{
return -1; // not found the file
}
*/
if (access(FileName, R_OK)!=0)
return -2; // did't access file
if (!DU_findSOPClassAndInstanceInFile(FileName, sopClassUID, sopInstanceUID))
return -101;
if (!dcmIsaStorageSOPClassUID(sopClassUID))
return -102;
else
{
//fileNameList.push_back(FileName);
sopClassUIDList.push_back(sopClassUID);
sopInstanceUIDList.push_back(sopInstanceUID);
OFCondition cond = ASC_in
使用dctmtk实现DICOM文件的发送(StoreSCU)
于 2011-08-28 23:05:06 首次发布