Hi,
I am trying to use iscsidsc.dll in a csharp program, but have a lot of
trouble with it.
One thing I have working is GetIScsiInitiat orNodeName in the following
way:
[DLLImport("iscs idsc.dll")]
public static extern Int32 GetIScsiInitiat orNodeName(Stri ngBuilder
InitiatorNodeNa me);
StringBuilder NodeName = new StringBuilder(2 56);
GetIScsiInitiat orNodeName(Node Name);
textBox1.Text = NodeName.ToStri ng();
The next one I was trying to get to work is AddIScsiSendTar getPortal,
but it requires the passing of pointers to structures.
Following is the information from MSDN:
HRESULT WINAPI AddIScsiSendTar getPortal(
__in_opt PTCHAR InitiatorName,
__in_opt ULONG InitiatorPortNu mber,
__in_opt PISCI_LOGIN_OPT IONS LoginOptions,
__in_opt ISCSI_SECURITY_ FLAGS SecurityFlags,
PISCSI_TARGET_P ORTAL Portal
);
I have created it in c# as follows:
[DLLImport("scsi dsc.dll")]
public static extern Int32 AddIScsiSendTar getPortal(
StringBuilder,
ulong InitiatorPortNu mber,
ref ISCSI_LOGIN_OPT IONS LoginOptions,
UInt64 SecurityFlags,
ref ISCSI_TARGET_PO RTAL Portal
);
Structures are as follows:
[StructLayout(La youtKind.Sequen tial)]
public struct ISCSI_LOGIN_OPT IONS {
public ulong Version;
public uint InformationSpec ified;
public uint LoginFlags;
public uint AuthType;
public byte HeaderDigest;
public byte DataDigest;
public ulong MaximumConnecti ons;
public ulong DefaultTime2Wai t;
public ulong DefaultTime2Ret ain;
public ulong UsernameLength;
public ulong PasswordLength;
[MarshalAs(Unman agedType.LPTStr )]
public string Username;
[MarshalAs(Unman agedType.LPTStr )]
public string password;
}
[StructLayout(La youtKind.Sequen tial)]
public struct ISCSI_TARGET_PO RTAL {
[MarshalAs(Unama nagedType.ByVal TStr, SizeConst=256)]
public string SymbolicName;
[MarshalAs(Unama nagedType.ByVal TStr, SizeConst=256)]
public string Address;
public ushort Socket
}
When trying to call AddIScsiSendTar getPortal I do it as follows:
ISCSI_TARGET_PO RTAL Portal = new ISCSI_TARGET_PO RTAL();
Portal.Address = new string(new char[256]);
Portal.Symbolic Name = new string(new char[256]);
ISCSI_LOGIN_OPT IONS LoginOptions = new ISCSI_LOGIN_OPT IONS();
LoginOptions.Us ername = new string(new char[32]);
LoginOptions.Pa ssword = new string(new char[32]);
LoginOptions.Us ernameLength=32 ;
LoginOptions.Pa sswordLength=32 ;
AddIScsiSendTar getPortal("loca lhost,0xFFFFFFF FFFFFFFFF,ref
LoginOptions, 0, ref Portal);
The code compiles, but when run I get the following error:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
I have tried several different ways of defining the function and the
structures, but so far without any luck.
I would really like some help on how to get this working.
Thanks in advance
Regards
Jimmy Dansbo
I am trying to use iscsidsc.dll in a csharp program, but have a lot of
trouble with it.
One thing I have working is GetIScsiInitiat orNodeName in the following
way:
[DLLImport("iscs idsc.dll")]
public static extern Int32 GetIScsiInitiat orNodeName(Stri ngBuilder
InitiatorNodeNa me);
StringBuilder NodeName = new StringBuilder(2 56);
GetIScsiInitiat orNodeName(Node Name);
textBox1.Text = NodeName.ToStri ng();
The next one I was trying to get to work is AddIScsiSendTar getPortal,
but it requires the passing of pointers to structures.
Following is the information from MSDN:
HRESULT WINAPI AddIScsiSendTar getPortal(
__in_opt PTCHAR InitiatorName,
__in_opt ULONG InitiatorPortNu mber,
__in_opt PISCI_LOGIN_OPT IONS LoginOptions,
__in_opt ISCSI_SECURITY_ FLAGS SecurityFlags,
PISCSI_TARGET_P ORTAL Portal
);
I have created it in c# as follows:
[DLLImport("scsi dsc.dll")]
public static extern Int32 AddIScsiSendTar getPortal(
StringBuilder,
ulong InitiatorPortNu mber,
ref ISCSI_LOGIN_OPT IONS LoginOptions,
UInt64 SecurityFlags,
ref ISCSI_TARGET_PO RTAL Portal
);
Structures are as follows:
[StructLayout(La youtKind.Sequen tial)]
public struct ISCSI_LOGIN_OPT IONS {
public ulong Version;
public uint InformationSpec ified;
public uint LoginFlags;
public uint AuthType;
public byte HeaderDigest;
public byte DataDigest;
public ulong MaximumConnecti ons;
public ulong DefaultTime2Wai t;
public ulong DefaultTime2Ret ain;
public ulong UsernameLength;
public ulong PasswordLength;
[MarshalAs(Unman agedType.LPTStr )]
public string Username;
[MarshalAs(Unman agedType.LPTStr )]
public string password;
}
[StructLayout(La youtKind.Sequen tial)]
public struct ISCSI_TARGET_PO RTAL {
[MarshalAs(Unama nagedType.ByVal TStr, SizeConst=256)]
public string SymbolicName;
[MarshalAs(Unama nagedType.ByVal TStr, SizeConst=256)]
public string Address;
public ushort Socket
}
When trying to call AddIScsiSendTar getPortal I do it as follows:
ISCSI_TARGET_PO RTAL Portal = new ISCSI_TARGET_PO RTAL();
Portal.Address = new string(new char[256]);
Portal.Symbolic Name = new string(new char[256]);
ISCSI_LOGIN_OPT IONS LoginOptions = new ISCSI_LOGIN_OPT IONS();
LoginOptions.Us ername = new string(new char[32]);
LoginOptions.Pa ssword = new string(new char[32]);
LoginOptions.Us ernameLength=32 ;
LoginOptions.Pa sswordLength=32 ;
AddIScsiSendTar getPortal("loca lhost,0xFFFFFFF FFFFFFFFF,ref
LoginOptions, 0, ref Portal);
The code compiles, but when run I get the following error:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
I have tried several different ways of defining the function and the
structures, but so far without any luck.
I would really like some help on how to get this working.
Thanks in advance
Regards
Jimmy Dansbo