GetNetCardID()

GetNetCardID()

Postby ChrisMillard » Thu Feb 12, 2009 1:08 pm

I have seen references to this function in the FiveWin forum. But I get an unresolved external with FWPPC.

Am I missing something or is this function not available.

Is there a simple way to get the MAC Address, or will I have to attempt to write a wrapper for SendARP in C. My C skills are limited unfortunately.

Cheers

Chris Millard
Regards

Chris Millard
ChrisMillard
 
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Postby Antonio Linares » Thu Feb 12, 2009 4:06 pm

Chris,

Here you have a working example.

In order to compile it you need to copy this mprapi.h to c:\vce\include\arm\mprapi.h:
http://www.mediafire.com/?sharekey=f67b ... 6e282a0ee8

Also, you have to link this vce library:
echo %vcdir%\lib\arm\iphlpapi.lib >> msvc.tmp

Test.prg
Code: Select all  Expand view
  1.  
  2. #include "FWCE.ch"
  3.  
  4. function Main()
  5.  
  6.    local aInfo := GetNetCardID()
  7.    
  8.    if ValType( aInfo ) == "C"
  9.       MsgInfo( aInfo )
  10.    else
  11.       MsgInfo( aInfo[ 1 ] )
  12.    endif      
  13.  
  14. return nil
  15.  
  16. // FiveTech Software (c) 2009
  17.  
  18. #pragma BEGINDUMP
  19.  
  20. #include <Windows.h>
  21. #include <iphlpapi.h>
  22.  
  23. #include <hbapi.h>
  24. #include <hbapiitm.h>
  25.  
  26. char * WideToAnsi( WCHAR * cWide );
  27.  
  28. static PIP_ADAPTER_INFO pAdapterInfo = NULL; // Contains pointer to
  29.                                              // current adapter info
  30. static void GetMACaddress( void )
  31. {
  32.   IP_ADAPTER_INFO AdapterInfo[ 16 ];       // Allocate information
  33.                                            // for up to 16 NICs
  34.   DWORD dwBufLen = sizeof( AdapterInfo );  // Save memory size of buffer
  35.  
  36.   DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
  37.             AdapterInfo,                 // [out] buffer to receive data
  38.             &dwBufLen);                  // [in] size of receive data buffer
  39.   WCHAR wText[ 40 ];
  40.   char * szResult;
  41.   PHB_ITEM pText = hb_itemNew( NULL );
  42.  
  43.   pAdapterInfo = AdapterInfo;
  44.  
  45.   do
  46.   {
  47.      wsprintf( ( void * ) wText, L"%02X-%02X-%02X-%02X-%02X-%02X",
  48.                ( unsigned char * ) pAdapterInfo->Address[ 0 ],
  49.                ( unsigned char * ) pAdapterInfo->Address[ 1 ],
  50.                ( unsigned char * ) pAdapterInfo->Address[ 2 ],
  51.                ( unsigned char * ) pAdapterInfo->Address[ 3 ],
  52.                ( unsigned char * ) pAdapterInfo->Address[ 4 ],
  53.                ( unsigned char * ) pAdapterInfo->Address[ 5 ] );
  54.  
  55.      szResult = WideToAnsi( ( WCHAR * ) wText );
  56.      hb_itemPutCL( pText, szResult, strlen( szResult ) );
  57.      hb_xfree( szResult );
  58.      hb_arrayAdd( hb_param( -1, HB_IT_ANY ), pText );
  59.  
  60.      if( pAdapterInfo->Next )        
  61.         pAdapterInfo = pAdapterInfo->Next;    // Progress through
  62.      else                                     // linked list
  63.         pAdapterInfo = NULL;
  64.  
  65.   } while( pAdapterInfo );                    // Terminate if last adapter
  66. }
  67.  
  68. HB_FUNC( GETNETCARDID ) // --> nMac netcard ID number
  69. {
  70.    hb_reta( 0 );
  71.    GetMACaddress();
  72.  
  73.    if( hb_arrayLen( hb_param( -1, HB_IT_ANY ) ) == 1 )
  74.       hb_retc( hb_parc( -1, 1 ) );
  75. }
  76.  
  77. #pragma ENDDUMP
  78.  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby ChrisMillard » Fri Feb 13, 2009 12:36 am

Thankyou for the quick response, I have had a go this evening but get the following errors when compiling

p:\vce\include\arm\mprapi.h(120) : warning C4068: unknown pragma
p:\vce\include\arm\mprapi.h(1746) : warning C4068: unknown pragma

CEFUNC.prg(1100) : error C2664: 'wsprintfW' : cannot convert parameter 1 from 'void *' to 'unsigned short *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
NMAKE : fatal error U1077: 'p:\vce\bin\clarm' : return code '0x2'

Line 1100 is the pAdapterInfo->Address[ 4 ] line of wsprintf although I have had problems before with line numbers not matching the problem in embedded C.

I have tried // the two lines in mprapi.h this removed the warnings but still get the fatal error.
Regards

Chris Millard
ChrisMillard
 
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Postby Antonio Linares » Fri Feb 13, 2009 7:22 am

Chris,

Please replace this and try it again, thanks:

wsprintf( ( void * ) wText

with

wsprintf( ( WCHAR * ) wText
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby ChrisMillard » Fri Feb 13, 2009 9:08 am

Got an unresolved external:

CEFUNC.obj : error LNK2019: unresolved external symbol "char * __cdecl WideToAns
i(unsigned short *)" (?WideToAnsi@@YAPADPAG@Z) referenced in function "void __cd
ecl GetMACaddress(void)" (?GetMACaddress@@YAXXZ)

I have seen this before and figured out that placing extern "C" after the includes, solves this problem.
Code: Select all  Expand view
#include <hbapiitm.h>

extern "C"

char * WideToAnsi( WCHAR * cWide );


It now works perfectly, thank you again.
Regards

Chris Millard
ChrisMillard
 
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Postby Antonio Linares » Fri Feb 13, 2009 9:14 am

Chris,

> It now works perfectly, thank you again.

Is it properly showing the MAC address ?

Thanks for your feedback :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby ChrisMillard » Fri Feb 13, 2009 11:22 am

Yes the function correctly returns a two element array with the MAC address of the Ethernet adapter and of the Bluetooth adapter.

My device is a TouchStar Technologies, TouchPC Falcon runing Win CE 5.0
Regards

Chris Millard
ChrisMillard
 
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Postby Antonio Linares » Fri Feb 13, 2009 11:25 am

Chris,

>
Yes the function correctly returns a two element array with the MAC address of the Ethernet adapter and of the Bluetooth adapter.
>

very good :-)

Thanks for your feedback :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby Maurizio » Mon May 31, 2010 3:59 pm

Antonio

is it possible have the file c:\vce\include\arm\mprapi.h:

the dawnload is expired

Thanks MAurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: GetNetCardID()

Postby Antonio Linares » Mon May 31, 2010 10:27 pm

Maurizio,

Here it is from VC98 include folder:
http://www.mediafire.com/?zzjnzgzntex

I think it is the one that we used then
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby Maurizio » Tue Jun 01, 2010 9:20 am

Thank Antonio

it's works

Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: GetNetCardID()

Postby Maurizio » Fri Oct 01, 2010 9:03 am

Hello Antonio ,
with the last version (February 2010) I have this warning , and the function GetNetCArdId return a blank string .


Harbour 2.0.0 (Rev. 13372)
Copyright (c) 1999-2010, http://www.harbour-project.org/
Compiling 'macadr.prg' and generating preprocessed output to 'macadr.ppo'...
Lines 1851, Functions/Procedures 1
Generating C source output to 'macadr.c'... Done.
Microsoft (R) C/C++ Optimizing Compiler Version 12.20.9615 for ARM
Copyright (C) Microsoft Corp 1984-2002. All rights reserved.
macadr.c
macadr.prg(80) : warning C4020: 'hb_parc' : too many actual parameters

At line 80 I have -->> hb_retc( hb_parc( -1, 1 ) );

Regards MAurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: GetNetCardID()

Postby Antonio Linares » Tue Mar 05, 2013 6:16 pm

Maurizio,

It should be:

hb_retc( hb_parvc( -1, 1 ) );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetNetCardID()

Postby Antonio Linares » Tue Mar 05, 2013 6:20 pm

FWH/samples/getmac.prg

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 9 guests