Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

some problem with NetGetAnyDCName()

Posted on 2001-07-29
8
Medium Priority
?
505 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 800 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 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