Board index » cppbuilder » AV - Stack getting trashed - HELP!
|
Borland Lover
CBuilder Developer |
AV - Stack getting trashed - HELP!2006-04-22 06:57:03 AM cppbuilder39 I need to use the following code to get the MAC address on Win XP and 2k3. It should work fine.... However, when execution gets to the lines (marked below) the stack gets completely trashed. I have isolated the problem into a test app. You can reproduce it by creating a new BCB project, drop a button on the form and add this code. Does it work on your system? Please help! BCB6 Patched. TIA ---------------- #include <winsock2.h> #include "Iptypes.h" #include "Iphlpapi.h" typedef ULONG (*TGetAdaptersAddresses)(ULONG Family, ULONG Flags, PVOID Reserved, PIP_ADAPTER_ADDRESSES pAdapterAddresses, PULONG pOutBufLen); void __fastcall TForm10::Button1Click(TObject *Sender) { HINSTANCE hinst = LoadLibrary("Iphlpapi.dll"); AnsiString AMacAddress = EmptyStr; if(NULL != hinst) { try { try { TGetAdaptersAddresses pGetAdaptersAddresses = (TGetAdaptersAddresses)GetProcAddress(hinst, "GetAdaptersAddresses"); if(NULL != pGetAdaptersAddresses) { IP_ADAPTER_ADDRESSES * pAddresses = NULL; try { ULONG outBufLen = 0; // Make an initial call to GetAdaptersAddresses to get the // size needed into the outBufLen variable if (pGetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) { if (pAddresses) GlobalFree(pAddresses); pAddresses = (IP_ADAPTER_ADDRESSES*)new unsigned char[outBufLen]; } // Make a second call to GetAdapters Addresses to get the actual data we want if (pGetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &outBufLen) == NO_ERROR) { // successful, unsigned char * MACData = pAddresses->PhysicalAddress; ////////<<---------------- As this next loop executes - the stack gets trashed !!! WHY??? DWORD i; for (i = 0; i < pAddresses->PhysicalAddressLength; i++) AMacAddress = AMacAddress + Format("%.2X:", ARRAYOFCONST(( MACData[i] ))); AMacAddress = AMacAddress.Delete(AMacAddress.Length(), 1); // take off the last colon } } __finally { if (pAddresses) delete [] pAddresses; } } } catch(...) { AMacAddress = "UNKNOWN MAC ADDR"; } } __finally { FreeLibrary(hinst); } } MessageDlg(AMacAddress, mtWarning, TMsgDlgButtons() << mbOK, 0); } |
