Page 1 of 1

GetNetCardID()

Posted: Thu Feb 12, 2009 1:08 pm
by ChrisMillard
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

Re: GetNetCardID()

Posted: Thu Feb 12, 2009 4:06 pm
by Antonio Linares
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

 #include "FWCE.ch" function Main()    local aInfo := GetNetCardID()      if ValType( aInfo ) == "C"      MsgInfo( aInfo )   else      MsgInfo( aInfo[ 1 ] )   endif       return nil // FiveTech Software (c) 2009 #pragma BEGINDUMP #include <Windows.h>#include <iphlpapi.h> #include <hbapi.h>#include <hbapiitm.h> char * WideToAnsi( WCHAR * cWide ); static PIP_ADAPTER_INFO pAdapterInfo = NULL; // Contains pointer to                                             // current adapter infostatic void GetMACaddress( void ){  IP_ADAPTER_INFO AdapterInfo[ 16 ];       // Allocate information                                           // for up to 16 NICs  DWORD dwBufLen = sizeof( AdapterInfo );  // Save memory size of buffer   DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo            AdapterInfo,                 // [out] buffer to receive data            &dwBufLen);                  // [in] size of receive data buffer  WCHAR wText[ 40 ];  char * szResult;  PHB_ITEM pText = hb_itemNew( NULL );    pAdapterInfo = AdapterInfo;   do   {     wsprintf( ( void * ) wText, L"%02X-%02X-%02X-%02X-%02X-%02X",               ( unsigned char * ) pAdapterInfo->Address[ 0 ],               ( unsigned char * ) pAdapterInfo->Address[ 1 ],               ( unsigned char * ) pAdapterInfo->Address[ 2 ],               ( unsigned char * ) pAdapterInfo->Address[ 3 ],               ( unsigned char * ) pAdapterInfo->Address[ 4 ],               ( unsigned char * ) pAdapterInfo->Address[ 5 ] );      szResult = WideToAnsi( ( WCHAR * ) wText );      hb_itemPutCL( pText, szResult, strlen( szResult ) );     hb_xfree( szResult );     hb_arrayAdd( hb_param( -1, HB_IT_ANY ), pText );       if( pAdapterInfo->Next )                 pAdapterInfo = pAdapterInfo->Next;    // Progress through     else                                     // linked list        pAdapterInfo = NULL;   } while( pAdapterInfo );                    // Terminate if last adapter} HB_FUNC( GETNETCARDID ) // --> nMac netcard ID number{   hb_reta( 0 );   GetMACaddress();    if( hb_arrayLen( hb_param( -1, HB_IT_ANY ) ) == 1 )      hb_retc( hb_parc( -1, 1 ) );} #pragma ENDDUMP 

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 12:36 am
by ChrisMillard
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.

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 7:22 am
by Antonio Linares
Chris,

Please replace this and try it again, thanks:

wsprintf( ( void * ) wText

with

wsprintf( ( WCHAR * ) wText

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 9:08 am
by ChrisMillard
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

#include <hbapiitm.h>

extern "C"

char * WideToAnsi( WCHAR * cWide );
It now works perfectly, thank you again.

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 9:14 am
by Antonio Linares
Chris,

> It now works perfectly, thank you again.

Is it properly showing the MAC address ?

Thanks for your feedback :-)

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 11:22 am
by ChrisMillard
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

Re: GetNetCardID()

Posted: Fri Feb 13, 2009 11:25 am
by Antonio Linares
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 :-)

Re: GetNetCardID()

Posted: Mon May 31, 2010 3:59 pm
by Maurizio
Antonio

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

the dawnload is expired

Thanks MAurizio

Re: GetNetCardID()

Posted: Mon May 31, 2010 10:27 pm
by Antonio Linares
Maurizio,

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

I think it is the one that we used then

Re: GetNetCardID()

Posted: Tue Jun 01, 2010 9:20 am
by Maurizio
Thank Antonio

it's works

Maurizio

Re: GetNetCardID()

Posted: Fri Oct 01, 2010 9:03 am
by Maurizio
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

Re: GetNetCardID()

Posted: Tue Mar 05, 2013 6:16 pm
by Antonio Linares
Maurizio,

It should be:

hb_retc( hb_parvc( -1, 1 ) );

Re: GetNetCardID()

Posted: Tue Mar 05, 2013 6:20 pm
by Antonio Linares
FWH/samples/getmac.prg

Image