VC++: entry GetComputerNameExA couldn't be found in kernel32.dll

Hello experts,
my VC+++ program I designed to run in NT4, W2K, WXP, W2K3.
The program is compiled in W2K using VS.Net 2003 (unmanaged).
If I'm executing the program in NT4, I get the message
  "entry GetComputerNameExA couldn't be found in kernel32.dll"
Now I'm looking for a way to prevent this.
Currently I'm checking for NT4 and ignore executing this API,
but this is not sufficient.

Does anyone know what I need to change?
If required please supply some code.

  Thank you HStrix
 
HStrixAsked:
Who is Participating?
 
jkrCommented:
Sorry, my fault - that should be

typedef BOOL WINAPI (*FPTR_GetComputerNameEx)(int,LPTSTR, LPDWORD);

so that the calling convention matches.
0
 
jkrCommented:
>>Now I'm looking for a way to prevent this

Don't rely on 'GetComputerNameEx()' being present on NT, load it dynamically. and use different means, e.g.

typedef BOOL (*FPTR_GetComputerNameEx)(int,LPTSTR, LPDWORD);

FPTR_GetComputerNameEx pGetComputerNameEx = (FPTR_GetComputerNameEx) GetProcAddress(GetModuleHandle("kernel32.dll"),"GetComputerNameExA");

if (pGetComputerNameEx != NULL) { // available

  pGetComputerNameEx(...);

} else { // NT, unavailable, use different functionality

  GetComputerName(...);
}

That will depend on what info you need from this API.
0
 
HStrixAuthor Commented:
Thank you jkr,
I tried your code and get the following error (in W2K):
---
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
---
My code is:
---
typedef BOOL (*FPTR_GetComputerNameEx)(int,LPTSTR, LPDWORD);
...
...
...
FPTR_GetComputerNameEx pGetComputerNameEx = (FPTR_GetComputerNameEx) GetProcAddress(GetModuleHandle("kernel32.dll"),"GetComputerNameExA");

char  buffer[256] = "";
char  szDescription[8][32] = {"NetBIOS",
        "DNS hostname",
        "DNS domain",
        "DNS fully-qualified",
        "Physical NetBIOS",
        "Physical DNS hostname",
        "Physical DNS domain",
        "Physical DNS fully-qualified"};
 int cnf = 0;
 DWORD dwSize = sizeof(buffer);
CString infoDomainAD;
CString infoFQMN;
cnf = 2;
COMPUTER_NAME_FORMAT cnf_Domain = (COMPUTER_NAME_FORMAT) cnf;
//if (!GetComputerNameEx(cnf_Domain, buffer, &dwSize))      // <== this worked in W2K        
if (!pGetComputerNameEx(cnf_Domain, buffer, &dwSize))       // <== here error above occured
   infoDomainAD = "Error detecting DnsDomain";
} else infoDomainAD = buffer;
---
Can you help me out?

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
HStrixAuthor Commented:
Thanks jkr again,
a slight modifcation
   typedef BOOL (WINAPI *FPTR_GetComputerNameEx)(int,LPTSTR, LPDWORD);
and it worked.
0
 
jkrCommented:
Argh, weekends ;o)
0
 
HStrixAuthor Commented:
Never mind, important is => you helped me out and it works now!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.