I'm looking for a better understanding of whats going on with the code i write. I have come across something that I thought I understood but its not working as expected. Its hard to explain so let me show the code first..
This works as expected..(save replacing the strings with valid domain, username and password)
When I try to replace the last two bytes in the structure with a short datatype it no longer works..i.e:
Am i misunderstandin g something? The Int16 class is a short datatype which is only two bytes (I thought)..so replacing the two bytes with the short should be exactly the same. What is breaking this?
(Yes I know i could just pass the Guid type in and it would work but im looking to understand the code to stop just grabing solutions off the net.)
Code:
[DllImport("activeds.dll", EntryPoint = "ADsOpenObject", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int IntADsOpenObject(string path, string userName, string password, int flags,ref MyGuid iid, [MarshalAs(UnmanagedType.Interface)] out object ppObject);
struct MyGuid
{
public Int32 Data1;
public Int16 Data2;
public Int16 Data3;
public Byte Data4_1;
public Byte Data4_2;
public Byte Data4_3;
public Byte Data4_4;
public Byte Data4_5;
public Byte Data4_6;
public Byte Data4_7;
public Byte Data4_8;
}
static void Main(string[] args)
{
//Guid l = new Guid("00000000-0000-0000-C000-000000000046");
object obj = null;
MyGuid g = new MyGuid();
g.Data4_1 = 192;
g.Data4_8 = 70;
int j = IntADsOpenObject("LDAP://thedomain.com", "username", "password", 1, ref g, out obj);
Console.WriteLine(j.ToString());
}
When I try to replace the last two bytes in the structure with a short datatype it no longer works..i.e:
Code:
[DllImport("activeds.dll", EntryPoint = "ADsOpenObject", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int IntADsOpenObject(string path, string userName, string password, int flags,ref MyGuid iid, [MarshalAs(UnmanagedType.Interface)] out object ppObject);
struct MyGuid
{
public Int32 Data1;
public Int16 Data2;
public Int16 Data3;
public Byte Data4_1;
public Byte Data4_2;
public Byte Data4_3;
public Byte Data4_4;
public Byte Data4_5;
public Byte Data4_6;
public Int16 Data4_7_8;//Same number of bytes?
//public Byte Data4_7;
//public Byte Data4_8;
}
static void Main(string[] args)
{
//Guid l = new Guid("00000000-0000-0000-C000-000000000046");
object obj = null;
MyGuid g = new MyGuid();
g.Data4_1 = 192;
g.Data4_7_8 = 70;
int j = IntADsOpenObject("LDAP://thedomain.com", "username", "password", 1, ref g, out obj);
//No longer works
Console.WriteLine(j.ToString());
}
(Yes I know i could just pass the Guid type in and it would work but im looking to understand the code to stop just grabing solutions off the net.)
Comment