我正在尝试将 DCMTK 3.6.4(一个 C++ 库)集成到 C# 环境中。虽然我已经成功包装了 DLL
为此,我采用了 dcmsend 的代码,将其包装在一个 'extern "C" {}' 中,将 '_declspec(dllexport)' 放在 main 方法之前,然后将其导出到一个 DLL。然后我使用此代码从 C# 调用此 DLL。
这是DLLImport:
[DllImport("dcmsend.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall, EntryPoint = "main")]
public static extern int dcmsendMain(int argc, string[] argv);
我这样称呼方法;ip、端口和文件名都是字符串,并且都是有效的。
dcmsendMain(5, new string[] { "dcmsend", "-v", ip, port, filename });
当我只调用一次上述方法时,它会输出以下文本:
I: checking input files ...
I: starting association #1
I: initializing network ...
I: negotiating network association ...
I: Requesting Association
I: Association Accepted (Max Send PDV: 16372)
I: sending SOP instances ...
W: DcmItem: Length of element (7fe0,0010) is not a multiple of 2 (VR=OW)
I: Sending C-STORE Request (MsgID 1, SC)
I: Received C-STORE Response (Success)
I: Releasing Association
I:
I: Status Summary
I: --------------
I: Number of associations : 1
I: Number of pres. contexts : 1
I: Number of SOP instances : 1
I: - sent to the peer : 1
I: * with status SUCCESS : 1
但是,在同一会话中调用该方法的所有后续时间,即使文件名不同,也会产生以下输出:
W: no data dictionary loaded, check environment variable: DCMDICTPATH
I: checking input files ...
I: starting association #1
I: initializing network ...
I: negotiating network association ...
I: Requesting Association
I: Association Accepted (Max Send PDV: 16372)
I: sending SOP instances ...
W: DcmItem: Length of element (7fe0,0010) is not a multiple of 2 (VR=OW)
E: DcmSequenceOfItems: Parse error in sequence (7fe0,0010), found (fffe,e000) instead of sequence delimiter (fffe,e0dd)
E: cannot send SOP instance from file: IM-0001-0000.dcm: Sequence Delimitation Item missing
F: cannot send SOP instance: Sequence Delimitation Item missing
I: Aborting Association
正如输出所示,后续操作也没有正确发送。
我该如何解决这个问题?