Avatar of WTarlton
WTarlton

asked on 

Help with an API function im trying to write

I am trying to write an API function and was wondering if somebody can look it over and let me know what I am doing wrong. I am trying to return a handle and it just returns 0 every time. I have scoured the net but can't find any examples at all


    Private Structure DS_SCHEMA_GUID_MAPA
        Dim GUID As Guid
        Dim GUIDType As Long
        Dim pName As String
    End Structure


    Private Declare Function DsMapSchemaGuidsA Lib "ntdsapi" (ByVal hDS As Long, ByVal cGuids As Long, ByRef rGuids As Guid, ByRef ppGuidMap As DS_SCHEMA_GUID_MAPA) As Long
    Private Declare Function DsBindA Lib "ntdsapi" (ByVal DomainControllerName As String, ByVal DnsDomainName As String, ByRef phDS As IntPtr) As Long



    Private Sub testy()
        Dim retVal As Long
        Dim MyHost As String = System.Net.Dns.GetHostName
        Dim handle As IntPtr
        Dim t As New Guid("{2BEC133B-AE2B-4C32-A3F5-036149C4E671}")
        Dim temp As New DS_SCHEMA_GUID_MAPA

        retVal = DsBindA(vbNull, vbNull, handle)
        MsgBox(retVal.ToString)
        MsgBox(handle.ToString)
        DsMapSchemaGuidsA(handle, 0, t, temp)

        MsgBox(temp.pName)
    End Sub

retVal returns a code but this reference http://msdn.microsoft.com/en-us/library/ms675931(VS.85).aspx does not say what events are which code? Where can I obtain this information?

Handle returns 0. Probably because I have an error code in retval but no way to tell whats being thrown back to me


Im a bit lost on this if somebody would please help me!!

Visual Basic.NETMicrosoft Development

Avatar of undefined
Last Comment
WTarlton
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Sorry I forgot the structure, this needs to change too.

    Private Structure DS_SCHEMA_GUID_MAPA
        Dim GUID As Guid
        Dim GUIDType As Integer
        Dim pName As String
    End Structure

Open in new window

do you mean, you want to know the value of each error code?
if retval=0 then funcion succeded (ERROR_SUCCESS)
 
Avatar of WTarlton
WTarlton

ASKER

FernandoSoto: the retval is working correctly now

jaime_olivares: yes I need to know the error codes. right now it's returning a 1359 but I have no clue at all what that number means. Is there a list of all the possible errors somewhere?

Also the handle is still returning 0
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

According to the documentation 1359 is a ERROR_INTERNAL_ERROR  An internal error occurred. Not much help.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi WTarlton;

Have you tried to place the name of the DomainControllerName in the command in place of sending null to see if that works? For example:

retVal = DsBindA("\\FAB-DC-01", vbNull, handle)

Fernando
Avatar of WTarlton
WTarlton

ASKER

FernandoSoto: yes I have tried both ways same error each time
Avatar of WTarlton
WTarlton

ASKER

jaime_olivares: yes that is exactly what I was looking for!

Are you guys on a domain? Does this function work for you?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Do get the same error? If so have you tried running the executable on another system?
Avatar of WTarlton
WTarlton

ASKER

FernandoSoto: I just tried it again and it worked that time. I got a handle returned to me with no errors for retval.

temp.pname is still however blank im not sure if this is because it cannot find the GUID im passing or not but I think it's working now!
Avatar of WTarlton
WTarlton

ASKER

Im getting a handle of 66326896 does this seem like the right kind of value?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

I am not, but when I run the code with the first two parameters as Nothing I get an error code
ERROR_NO_SUCH_DOMAIN integer value 1355 and when I use a domain name I get an error code ERROR_ACCESS_DENIED integer value 5.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Try this command in place of the one you are using.

DsMapSchemaGuidsA(handle, 1, t, temp)
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

That handle look fine to me.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Make sure you also implement the DsFreeSchemaGuidMapA otherwise you will end up with memory leaks.

Private Declare Sub DsFreeSchemaGuidMapA Lib "ntdsapi" ( _
    ByVal pGuidMap As DS_SCHEMA_GUID_MAPA _
)
 
 
DsFreeSchemaGuidMapA(temp)

Open in new window

Avatar of WTarlton
WTarlton

ASKER

DsMapSchemaGuidsA(handle, 1, t, temp) does nothing. Exact same results.

I also implemented the DsFreeSchemaGuidMapA  function
Avatar of WTarlton
WTarlton

ASKER

Im thinking the problem lies somewhere in the cGuids part of this call???

 Private Declare Function DsMapSchemaGuidsA Lib "ntdsapi" ( _
          ByVal hDS As IntPtr, _
          ByVal cGuids As Integer, _
          ByRef rGuids As Guid, _
          ByRef ppGuidMap As DS_SCHEMA_GUID_MAPA _
            ) As Integer
Avatar of WTarlton
WTarlton

ASKER

Ive also noticed this

typedef struct {  GUID guid;  DWORD guidType;  LPTSTR pName;
} DS_SCHEMA_GUID_MAP,  *PDS_SCHEMA_GUID_MAP;

What type is a LPTSTR in vb.net?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

In the documentation for DsMapSchemaGuids it states that rGuids should be "Pointer to an array of GUID values for the objects to be mapped."

http://msdn.microsoft.com/en-us/library/ms676008(VS.85).aspx

I am thinking that the DsMapSchemaGuidsA should be this:

    Private Declare Function DsMapSchemaGuidsA Lib "ntdsapi" ( _
        ByVal hDS As IntPtr, _
        ByVal cGuids As Integer, _
        ByRef rGuids() As Guid, _
        ByRef ppGuidMap As DS_SCHEMA_GUID_MAPA _
    ) As Integer

Define the GUID like this:

Dim t() As Guid = {New Guid("{2BEC133B-AE2B-4C32-A3F5-036149C4E671}")}

and call DsMapSchemaGuidsA like this:

DsMapSchemaGuidsA(handle, 1, t, temp)

 
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

To your statement, "What type is a LPTSTR in vb.net?", The LPTSTR is a C/C++ data type  that  has a meaning as follows:

If UNICODE support is enabled in the program then LPTSTR is a 32-bit pointer to a null-terminated string of 16-bit UNICODE characters.

If UNICODE support is NOT enabled in the program then LPTSTR is a 32-bit pointer to a null-terminated string of 8-bit ANSI characters.

This will be taken care of by the windows interop service

Avatar of WTarlton
WTarlton

ASKER

Giving it a shot. This line causes an error

Dim t() As Guid = {New Guid("{2BEC133B-AE2B-4C32-A3F5-036149C4E671}")}
try with:
Dim t() As Guid = {New Guid("2BEC133B-AE2B-4C32-A3F5-036149C4E671")}
Avatar of WTarlton
WTarlton

ASKER

Isnt that the exact same thing as I pasted above?
Avatar of WTarlton
WTarlton

ASKER

Still same error :/
Avatar of WTarlton
WTarlton

ASKER

The error I get is

Value of type System.Guid cannot be converted into a 1 dimensnal array of system.guid


it doesnlt like it to be defined in the dim statement for some reason ive tried a few dff things havent figued it out
Avatar of WTarlton
WTarlton

ASKER

I got it figured out
ok, try with this:
Dim t As Guid() = {New Guid("2BEC133B-AE2B-4C32-A3F5-036149C4E671")}
Avatar of WTarlton
WTarlton

ASKER

That made no difference declaring that stuff as an array. Whats wierd is when I call temp.guid.tostring after the function runs is returns like half of some strange guid nothing like what I passed
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

You did not make the change to the function as well.

    Private Declare Function DsMapSchemaGuidsA Lib "ntdsapi" ( _
        ByVal hDS As IntPtr, _
        ByVal cGuids As Integer, _
        ByRef rGuids() As Guid, _                        '<========= Change to this
        ByRef ppGuidMap As DS_SCHEMA_GUID_MAPA _
    ) As Integer

Avatar of WTarlton
WTarlton

ASKER

Here is what it returns

 001eeebc-0000-0000-0000-000000000000

but put temp.pname returns nothing
Avatar of WTarlton
WTarlton

ASKER

Yea I changed the function
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

What is the value of retVal after this line execute?

retVal = DsBindA(vbNull, vbNull, handle)
Avatar of WTarlton
WTarlton

ASKER

that errors out but im not using that now i have the actual domain controller name and FQDN plugged in and get a 0 retval and i am receiving a handle
Avatar of WTarlton
WTarlton

ASKER

If i do it with the vbnulls I get RPS server is unavailable
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

What does cGuids return in temp.cGuids?
Avatar of WTarlton
WTarlton

ASKER

This  001eeebc-0000-0000-0000-000000000000

Im not sure what that is because im passing this 2BEC133B-AE2B-4C32-A3F5-036149C4E671
Avatar of WTarlton
WTarlton

ASKER

This function sucks because there is nothing on it on the web. I can't find any articles or help files or anybody else who has had the same issues
Avatar of WTarlton
WTarlton

ASKER

Mabye im making this more complicated than I need. Let me explain what im trying to do.

I need to search all active directory by providing a GUID and return the guids friendly name. Mabye a vbscript would work better that is implemented with my app?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Sorry I had to step out for a while.

Lets see what error is returned from DsMapSchemaGuidsA if any. Try replacing your line of code for these.

        retVal = DsMapSchemaGuidsA(handle, 1, t, temp)
        MessageBox.Show("retVal = " & retVal.ToString())

Fernando
Avatar of WTarlton
WTarlton

ASKER

retval is 0 so no error
Avatar of WTarlton
WTarlton

ASKER

I found this other function but it is vbscript it is exactly what im trying to do

' This code illustrates how to bind to the default computers container.
' ------ SCRIPT CONFIGURATION ------
strDomain = ""   ' e.g. apac.rallencorp.com
strWKGUID = "" ' e.g. "aa312825768811d1aded00c04fd8d5cd"
                              ' for the default Computers container
' ------ END CONFIGURATION ---------
     
set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
set objCompContainer = GetObject("LDAP://" )
WScript.Echo objCompContainer.Get("distinguishedName")

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

I think it translates to this, but not sure. I ran it on my system but I get can't create active component.

        ' This code illustrates how to bind to the default computers container.
        ' ------ SCRIPT CONFIGURATION ------
        Dim strDomain As String = "\\FQDN "   ' e.g. apac.rallencorp.com
        Dim strWKGUID As String = "2BEC133BAE2B4C32A3F5036149C4E671" ' e.g. "aa312825768811d1aded00c04fd8d5cd"
        ' for the default Computers container
        ' ------ END CONFIGURATION ---------

        Dim objRootDSE As Object = GetObject("LDAP://" & strDomain & "/RootDSE")
        Dim objCompContainer As Object = GetObject("LDAP://")

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Are you sure you have the correct GUID, 2BEC133B-AE2B-4C32-A3F5-036149C4E671?  The reason I ask is that the documentation states that the pname can be a null string if  "DsMapSchemaGuids was unable to map the GUID to a display name."

http://msdn.microsoft.com/en-us/library/ms676283(VS.85).aspx
Avatar of WTarlton
WTarlton

ASKER

Yea im sure I have the right guid because I can cut and paste it into the vbscript and it will pull up the correct object. I converted the above script into vb and it is now working from within my application. Still wish I could have gotten the API to work but an LDAP query will have to work.

Thanks for all your help
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo