Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-05-13
6
Medium Priority
?
715 Views
Last Modified: 2007-12-19
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
 
0
Comment
Question by:HStrix
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16674117
>>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
 

Author Comment

by:HStrix
ID: 16674311
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
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 16674340
Sorry, my fault - that should be

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

so that the calling convention matches.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:HStrix
ID: 16674570
Thanks jkr again,
a slight modifcation
   typedef BOOL (WINAPI *FPTR_GetComputerNameEx)(int,LPTSTR, LPDWORD);
and it worked.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16674573
Argh, weekends ;o)
0
 

Author Comment

by:HStrix
ID: 16674591
Never mind, important is => you helped me out and it works now!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

569 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