Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

some problem with NetGetAnyDCName()

Posted on 2001-07-29
8
498 Views
Last Modified: 2013-12-03
Hi folks,

i try to do:


NET_API_STATUS retc;
LPBYTE * Servername = NULL;

retc = NetGetAnyDCName(
     NULL,
     NULL,
     Servername
     );

if( retc == NERR_Success)
{
    // DO STUFF
}
else
{
  switch(retc)
  {
    case ERROR_NO_LOGON_SERVERS:
      m_ResultText.Format("No domain controllers could be found\r\n");
      break;
    case ERROR_NO_SUCH_DOMAIN:
      m_ResultText.Format("The specified domain is not a trusted domain.\r\n");
      break;
    case ERROR_NO_TRUST_LSA_SECRET:
      m_ResultText.Format("The client side of the trust relationship is broken.\r\n");
      break;
    case ERROR_NO_TRUST_SAM_ACCOUNT:
      m_ResultText.Format("The server side of the trust relationship is broken or the password is broken.\r\n");
      break;
    case ERROR_DOMAIN_TRUST_INCONSISTENT:
      m_ResultText.Format("The server that responded is not a proper domain controller of the specified domain.\r\n");
      break;
    default:
      m_ResultText.Format("Can't find a domain controller for domain(%d)\r\n", retc);
    }
    MessageBox( m_ResultText, MB_OK);
}

but when i run, i always get: "Can't find a domain controller for domain (-1073741819)" which as you can see, is the default switch condition, because retc is "-1073741819"!!

i don;t get it - if i specify the PDC, i can use NetUserEnum() with no problems at all.  but i want to first use NetGetAnyDCName() or NetGetDCName() to find them first so that the user need not enter it manually...

any ideas guys?


0
Comment
Question by:slamhound
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6332716
The error code acually is C0000005 (-1073741819) - ERROR_ACCESS_VIOLATION.
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6332728
MAke it read

NET_API_STATUS retc;
LPBYTE Servername = NULL;

retc = NetGetAnyDCName(
    NULL,
    NULL,
    &Servername
    );

and it will work...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6332731
To elaborate - this API takes a pointer to a pointer to store the actually allocated address in. When coding

NET_API_STATUS retc;
LPBYTE * Servername = NULL;

retc = NetGetAnyDCName(
    NULL,
    NULL,
    Servername
    );


you're syntacrically correct, as you're passing a BYTE**. But, as this pointer points to NULL, 'NetGetAnyDCName()' tries to store the value at the position NULL, thus leading to the accvio that is probably caught in a SEH frame. You can think of it as it is doing

GetNamr ( char** ppsz)
{
 *ppsz = "name";
}

If you'd call that using your method, it' be like '*NULL = "name";'
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Author Comment

by:slamhound
ID: 6332733
jkr,

Oooo-Kay!

well that makes some sense then...  but i am logged in as domain admin - i will start poking about some, any tips for me?

thanks for that!

regards.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6332737
>>but i am logged in as domain admin - i will start poking
>>about some, any tips for me?

Read my answer :o)
All you have to do is to change your code to read


NET_API_STATUS retc;
LPBYTE Servername = NULL;

retc = NetGetAnyDCName(
   NULL,
   NULL,
   &Servername
   );
0
 
LVL 10

Author Comment

by:slamhound
ID: 6332755
yeah, i'd written that last one at the same time you were preparing your second response - didn;t see it until after i had submitted! ;-)

thanks for that - makes perfect sense.  what i was thinking is that the function would take my pointer and set it to the value of the buffer created by th net_api....

i can see where i went wrong.  

back soon.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6332764
>>what i was thinking is that the function would take my
>>pointer and set it to the value of the buffer created by
>>th net_api....

That's what it does. But in order to do that, this function needs the address of a pointer, and not a pointer to a pointer. I know, the docs are a bit fuzzy about that.
0
 
LVL 10

Author Comment

by:slamhound
ID: 6332768
thanks a bunch :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Standards for file storage. 3 31
Get the most recent file to copy into a sql table with ssis 2 108
C# LINQ ForEach() question 6 48
Input parameteres to DragOver 2 19
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question