Solved

some problem with NetGetAnyDCName()

Posted on 2001-07-29
8
501 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
[X]
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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

734 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