GetNetCardID()

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

GetNetCardID()

Post 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
Regards

Chris Millard
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post 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 
regards, saludos

Antonio Linares
www.fivetechsoft.com
ChrisMillard
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Post 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.
Regards

Chris Millard
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post by Antonio Linares »

Chris,

Please replace this and try it again, thanks:

wsprintf( ( void * ) wText

with

wsprintf( ( WCHAR * ) wText
regards, saludos

Antonio Linares
www.fivetechsoft.com
ChrisMillard
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Post 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.
Regards

Chris Millard
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post by Antonio Linares »

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
ChrisMillard
Posts: 12
Joined: Wed Jul 09, 2008 7:07 pm
Location: Manchester, UK

Re: GetNetCardID()

Post 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
Regards

Chris Millard
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post 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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Maurizio
Posts: 705
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: GetNetCardID()

Post by Maurizio »

Antonio

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

the dawnload is expired

Thanks MAurizio
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Maurizio
Posts: 705
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: GetNetCardID()

Post by Maurizio »

Thank Antonio

it's works

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

Re: GetNetCardID()

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GetNetCardID()

Post by Antonio Linares »

Maurizio,

It should be:

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

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

Re: GetNetCardID()

Post by Antonio Linares »

FWH/samples/getmac.prg

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply