By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,165 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,165 IT Pros & Developers. It's quick & easy.

I need help with creating a Dll so I can call using COM interop

P: n/a
Hi, I got the following code in a project for creating dll but I'm getting
compiling error. I copied the code (from Main()) from Ineternet but becuase
I don't know how COM interop and how to code to create a dll that I'm sure
the code looks weird to those know how. Can someone tell me how to arrange
the code I have below so it would compile into a dll that I can call later?
Thank you.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.DirectoryServices;

namespace IDsAdminCreateObject
{
static void Main()

{

IDsAdminCreateObject co = new DsAdminCreateObject() as IDsAdminCreateObject;
object nativedsObject = new
DirectoryEntry("LDAP://cn=users,dc=yourdomain,dc=local").NativeObject;
co.Initialize(nativedsObject, null, "user");
object newObject = co.CreateModal(DsAdminCreateObject.GetDeskTopWindo w());

}

[ComImport, Guid("53554A38-F902-11d2-82B9-00C04F68928B"),

InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]

public interface IDsAdminCreateObject

{

/// <summary>
/// Need to initialize before popping up the new object wizard
/// </summary>
/// <param name="ADsContainerObj">initialized dir object Container object
eg: cn=users,DC=domain,dc=local</param>
/// <param name="ADsCopySource">can be null, specifies original object if
you want a copy!</param>

/// <param name="ClassName">contains "User", "group", "contact",
"inetOrgPerson" etc</param>
void Initialize( [MarshalAs(UnmanagedType.IDispatch)] object ADsContainerObj,
[MarshalAs(UnmanagedType.IDispatch), Optional(),
DefaultParameterValue(null)] object ADsCopySource,
[MarshalAs(UnmanagedType.LPWStr)] string ClassName);

/// <summary>
/// Returns native ActiveDirectory object
/// </summary>
/// <param name="hwndParent">handle to parent window, specify 0
(mostly)</param>
[return: MarshalAs(UnmanagedType.IDispatch)]
object CreateModal(IntPtr hwndParent);

}

/// <summary>

/// Have our CLSID_DsAdminCreateObject be imported by .NET
/// </summary>
[ComImport, Guid("E301A009-F901-11d2-82B9-00C04F68928B")]
public class DsAdminCreateObject

{

/// we just needed a pointer to a window, if you run this code within a
Windows Form, you can fetch a handle to it and hand it over to CreateModal!
[DllImport("user32", EntryPoint = "GetDesktopWindow", ExactSpelling = true,
SetLastError = false)]
public static extern IntPtr GetDeskTopWindow();
}

}

--
Thanks.
May 11 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.