Interop Issues

rali08

Member
Joined
Nov 1, 2006
Messages
8
Programming Experience
1-3
I am trying to use this old c dll
I loaded it in c# and created a dll which i use in vb.net to reference

i created these structs in hte C# dll

[StructLayout( LayoutKind.Sequential,
CharSet=CharSet.Ansi ) ]
public struct RdciKeysRecord
{
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=21)]
public string document_number ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string patient ;/* It is any unique identifier which the external system
can assign to a patient.It is not necessarily same as the
'patient position id' or the 'patient name'.*/
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string dci_short_name ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=9)]
public string dci_date ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string dci_time ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=21)]
public string visit_name ;
public int subevent_number ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string site ; /* It is any unique identifier which the external system
can assign to a site.It is not necessarily same as the
'site id' or the 'site name'.*/
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string investigator ; /* It is any unique identifier which the external system
can assign to an investigator.It is not necessarily same as the
'investigator id' or the 'investigator name'.*/

public int blank_flag ; /* value is: TRUE or FALSE */
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=201)]
public string comment ; /* Audit Changes MP 6/20/02 To audit key changes */
public AuditInfo audit ;
public int audit_only_flag; /* value is: TRUE or FALSE */
/* End of Audit Changes */
}


[StructLayout( LayoutKind.Sequential,
CharSet=CharSet.Ansi ) ]
public struct RdciRecord
{
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=21)]
public string document_number;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=16)]
public string recvd_dci_status_code;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string patient; /* It is any unique identifier which the external system
can assign to a patient.It is not necessarily same as the
'patient position id' or the 'patient name'.*/
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string dci_short_name;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=31)]
public string dci_name;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=9)]
public string dci_date;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=7)]
public string dci_time;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=21)]
public string visit_name;
public int visit_number ;
public int subevent_number ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string site; /* USED OC one'*/
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=11)]
public string investigator; /* USED OC one'*/
public int blank_flag ; /* value is: TRUE or FALSE */
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=201)]
public string comment;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string received_dci_entry_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=31)]
public string entered_by;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string end_ts;
public int data_lock_flag ; /* valiue is TRUE or FALSE */
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string data_lock_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string accessible_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string last_status_change_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string last_new_ver_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string modification_ts;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=31)]
public string modified_by;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=15)]
public string log_in_ts;
public AuditInfo audit ; /* Audit Changes MP 6/20/02 To audit key changes */
}


Then they had a sample c++ program that i mimicked. IT had a memset call that i tried to mimick in vb.net



VB.net code:

p_objTarget2 = Marshal.AllocHGlobal(Marshal.SizeOf(rdci_rec))
api.CopyMemory(p_objTarget2, 0, Marshal.SizeOf(
New class1.RdciRecord))
Marshal.PtrToStructure(p_objTarget2, rdci_rec)
Marshal.FreeHGlobal(p_objTarget2)

p_objTarget3 = Marshal.AllocHGlobal(Marshal.SizeOf(rdci_keys_Rec))
api.CopyMemory(p_objTarget3, 0, Marshal.SizeOf(
New class1.RdciKeysRecord))
Marshal.PtrToStructure(p_objTarget3, rdci_keys_Rec)
Marshal.FreeHGlobal(p_objTarget3)

i get the following error on the bold line

An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The structure must not be a value class

I know this is a long thread but please this is very critical for me to get done. thanks for all the help

 
Back
Top