473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using iscsidsc.dll in Csharp

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 GetIScsiInitiatorNodeName in the following
way:

[DLLImport("iscsidsc.dll")]
public static extern Int32 GetIScsiInitiatorNodeName(StringBuilder
InitiatorNodeName);

StringBuilder NodeName = new StringBuilder(256);
GetIScsiInitiatorNodeName(NodeName);
textBox1.Text = NodeName.ToString();

The next one I was trying to get to work is AddIScsiSendTargetPortal,
but it requires the passing of pointers to structures.
Following is the information from MSDN:
HRESULT WINAPI AddIScsiSendTargetPortal(
__in_opt PTCHAR InitiatorName,
__in_opt ULONG InitiatorPortNumber,
__in_opt PISCI_LOGIN_OPTIONS LoginOptions,
__in_opt ISCSI_SECURITY_FLAGS SecurityFlags,
PISCSI_TARGET_PORTAL Portal
);

I have created it in c# as follows:
[DLLImport("scsidsc.dll")]
public static extern Int32 AddIScsiSendTargetPortal(
StringBuilder,
ulong InitiatorPortNumber,
ref ISCSI_LOGIN_OPTIONS LoginOptions,
UInt64 SecurityFlags,
ref ISCSI_TARGET_PORTAL Portal
);

Structures are as follows:
[StructLayout(LayoutKind.Sequential)]
public struct ISCSI_LOGIN_OPTIONS {
public ulong Version;
public uint InformationSpecified;
public uint LoginFlags;
public uint AuthType;
public byte HeaderDigest;
public byte DataDigest;
public ulong MaximumConnections;
public ulong DefaultTime2Wait;
public ulong DefaultTime2Retain;
public ulong UsernameLength;
public ulong PasswordLength;
[MarshalAs(UnmanagedType.LPTStr)]
public string Username;
[MarshalAs(UnmanagedType.LPTStr)]
public string password;
}

[StructLayout(LayoutKind.Sequential)]
public struct ISCSI_TARGET_PORTAL {
[MarshalAs(UnamanagedType.ByValTStr, SizeConst=256)]
public string SymbolicName;
[MarshalAs(UnamanagedType.ByValTStr, SizeConst=256)]
public string Address;
public ushort Socket
}

When trying to call AddIScsiSendTargetPortal I do it as follows:
ISCSI_TARGET_PORTAL Portal = new ISCSI_TARGET_PORTAL();
Portal.Address = new string(new char[256]);
Portal.SymbolicName = new string(new char[256]);
ISCSI_LOGIN_OPTIONS LoginOptions = new ISCSI_LOGIN_OPTIONS();
LoginOptions.Username = new string(new char[32]);
LoginOptions.Password = new string(new char[32]);
LoginOptions.UsernameLength=32;
LoginOptions.PasswordLength=32;

AddIScsiSendTargetPortal("localhost,0xFFFFFFFFFFFF FFFF,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
Nov 19 '08 #1
0 2651

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug | last post by:
I need to make the VB.NET object callable from a program called Trade Station. It is a stock analysis and trading tool that is very importiant to my company. They have a scripting languge called...
8
by: Dennis C. Drumm | last post by:
I have ordered the book .NET Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller which I think will help answer some of my questions I have regarding making custom...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
5
by: a | last post by:
Is there a performance hit if I have many "using" statements that are unnecessary? For example: using System.Collections; when nowhere in my code I'm using System.Collections namespace. I'm...
1
by: rajani | last post by:
How to create control panel applet in CSharp. I know that a dll renamed as .cpl with cplapplet function exported has to be created which is not possible using csharp. Any help is appreciated. ...
1
by: Ricardo Lezana Bastante | last post by:
Hola a todos: ¿Como se puede acceder a Outlook Express desde un programa c#? Gracias Ricardo.
4
by: clintonG | last post by:
When using Visual Studio.NET I observe adding a new Web Form may have default References added such as... References o- System o- System.Data o- System.Drawing o- System.Web o- System.XML
2
by: news.microsoft.com | last post by:
Hi: I work in Csharp's parser files by LEX/YACC.Now I have only CSharp-lex.l and CSharp.y file,but they not have CSharp'comment Parse. this is a part of CSharp-lex.l. ........................
5
by: Deleo | last post by:
Hello, i still have my snmp in .net problem. But i thought i would write the snmp program in c++ and make a COM. Now i want to be able to use that COM in .net C# so i thought about using the COM+...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.