FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Pocket PC GetNetCardID()
Posts: 12
Joined: Wed Jul 09, 2008 07:07 PM
GetNetCardID()
Posted: Thu Feb 12, 2009 01: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: Thu Feb 12, 2009 04: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 (xpp): Select all Collapse
<div class="xpp" id="{CB}" style="font-family: monospace;"><ol><li style="" class="li1"> </li><li style="" class="li2">#include "FWCE.ch"</li><li style="" class="li1"> </li><li style="" class="li2">function Main()</li><li style="" class="li1"> </li><li style="" class="li2">   local aInfo := GetNetCardID()</li><li style="" class="li1">   </li><li style="" class="li2">   if ValType( aInfo ) == "C"</li><li style="" class="li1">      MsgInfo( aInfo )</li><li style="" class="li2">   else</li><li style="" class="li1">      MsgInfo( aInfo[ 1 ] )</li><li style="" class="li2">   endif      </li><li style="" class="li1"> </li><li style="" class="li2">return nil</li><li style="" class="li1"> </li><li style="" class="li2">// FiveTech Software (c) 2009</li><li style="" class="li1"> </li><li style="" class="li2">#pragma BEGINDUMP</li><li style="" class="li1"> </li><li style="" class="li2">#include <Windows.h></li><li style="" class="li1">#include <iphlpapi.h></li><li style="" class="li2"> </li><li style="" class="li1">#include <hbapi.h></li><li style="" class="li2">#include <hbapiitm.h></li><li style="" class="li1"> </li><li style="" class="li2">char * WideToAnsi( WCHAR * cWide );</li><li style="" class="li1"> </li><li style="" class="li2">static PIP_ADAPTER_INFO pAdapterInfo = NULL; // Contains pointer to</li><li style="" class="li1">                                             // current adapter info</li><li style="" class="li2">static void GetMACaddress( void )</li><li style="" class="li1">{</li><li style="" class="li2">  IP_ADAPTER_INFO AdapterInfo[ 16 ];       // Allocate information</li><li style="" class="li1">                                           // for up to 16 NICs</li><li style="" class="li2">  DWORD dwBufLen = sizeof( AdapterInfo );  // Save memory size of buffer</li><li style="" class="li1"> </li><li style="" class="li2">  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo</li><li style="" class="li1">            AdapterInfo,                 // [out] buffer to receive data</li><li style="" class="li2">            &dwBufLen);                  // [in] size of receive data buffer</li><li style="" class="li1">  WCHAR wText[ 40 ];</li><li style="" class="li2">  char * szResult;</li><li style="" class="li1">  PHB_ITEM pText = hb_itemNew( NULL );</li><li style="" class="li2">  </li><li style="" class="li1">  pAdapterInfo = AdapterInfo;</li><li style="" class="li2"> </li><li style="" class="li1">  do </li><li style="" class="li2">  {</li><li style="" class="li1">     wsprintf( ( void * ) wText, L"%02X-%02X-%02X-%02X-%02X-%02X",</li><li style="" class="li2">               ( unsigned char * ) pAdapterInfo->Address[ 0 ],</li><li style="" class="li1">               ( unsigned char * ) pAdapterInfo->Address[ 1 ],</li><li style="" class="li2">               ( unsigned char * ) pAdapterInfo->Address[ 2 ],</li><li style="" class="li1">               ( unsigned char * ) pAdapterInfo->Address[ 3 ],</li><li style="" class="li2">               ( unsigned char * ) pAdapterInfo->Address[ 4 ],</li><li style="" class="li1">               ( unsigned char * ) pAdapterInfo->Address[ 5 ] );</li><li style="" class="li2"> </li><li style="" class="li1">     szResult = WideToAnsi( ( WCHAR * ) wText ); </li><li style="" class="li2">     hb_itemPutCL( pText, szResult, strlen( szResult ) );</li><li style="" class="li1">     hb_xfree( szResult );</li><li style="" class="li2">     hb_arrayAdd( hb_param( -1, HB_IT_ANY ), pText ); </li><li style="" class="li1"> </li><li style="" class="li2">     if( pAdapterInfo->Next )         </li><li style="" class="li1">        pAdapterInfo = pAdapterInfo->Next;    // Progress through</li><li style="" class="li2">     else                                     // linked list</li><li style="" class="li1">        pAdapterInfo = NULL;</li><li style="" class="li2"> </li><li style="" class="li1">  } while( pAdapterInfo );                    // Terminate if last adapter</li><li style="" class="li2">}</li><li style="" class="li1"> </li><li style="" class="li2">HB_FUNC( GETNETCARDID ) // --> nMac netcard ID number</li><li style="" class="li1">{</li><li style="" class="li2">   hb_reta( 0 );</li><li style="" class="li1">   GetMACaddress();</li><li style="" class="li2"> </li><li style="" class="li1">   if( hb_arrayLen( hb_param( -1, HB_IT_ANY ) ) == 1 )</li><li style="" class="li2">      hb_retc( hb_parc( -1, 1 ) );</li><li style="" class="li1">}</li><li style="" class="li2"> </li><li style="" class="li1">#pragma ENDDUMP</li><li style="" class="li2"> </li></ol></div>
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 12
Joined: Wed Jul 09, 2008 07:07 PM
Re: GetNetCardID()
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: Fri Feb 13, 2009 07: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
Posts: 12
Joined: Wed Jul 09, 2008 07:07 PM
Re: GetNetCardID()
Posted: Fri Feb 13, 2009 09: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.
#include <hbapiitm.h>

extern "C"

char * WideToAnsi( WCHAR * cWide );


It now works perfectly, thank you again.
Regards



Chris Millard
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: Fri Feb 13, 2009 09: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
Posts: 12
Joined: Wed Jul 09, 2008 07:07 PM
Re: GetNetCardID()
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: 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
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: GetNetCardID()
Posted: Mon May 31, 2010 03:59 PM

Antonio

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

the dawnload is expired

Thanks MAurizio

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: 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
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: GetNetCardID()
Posted: Tue Jun 01, 2010 09:20 AM

Thank Antonio

it's works

Maurizio

Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: GetNetCardID()
Posted: Fri Oct 01, 2010 09: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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: Tue Mar 05, 2013 06:16 PM

Maurizio,

It should be:

hb_retc( hb_parvc( -1, 1 ) );

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GetNetCardID()
Posted: Tue Mar 05, 2013 06:20 PM
FWH/samples/getmac.prg

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion