ViTALiTY Posted May 7, 2013 at 01:36 PM Report #506081 Posted May 7, 2013 at 01:36 PM (edited) Basicamente precisava de um código que fosse buscar o MAC address do computador. O código para Linux já tenho a funcionar, para Windows não: #include <winsock2.h> #include <iphlpapi.h> #include <string.h> void PrintMACaddress (BYTE *addr) { int i; for (i = 0; i < 8; i++) { printf ("%x ", *addr++); } } static 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(AdapterInfo, &dwBufLen); // [in] size of receive data buffer if (dwStatus != ERROR_SUCCESS) { printf ("GetAdaptersInfo failed. err=%d\n", GetLastError ()); return; } PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to current adapter info do { PrintMACaddress(pAdapterInfo->Address); // Print MAC address pAdapterInfo = pAdapterInfo->Next; // Progress through linked list } while (pAdapterInfo); // Terminate if last adapter } int main() { GetMACaddress (); } Os erros: C:\Users\***\Desktop\testewindows7\main.c||In function 'PrintMACaddress':| C:\Users\***\Desktop\testewindows7\main.c|11|warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]| C:\Users\***\Desktop\testewindows7\main.c||In function 'GetMACaddress':| C:\Users\***\Desktop\testewindows7\main.c|23|warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]| C:\Users\***\Desktop\testewindows7\main.o:main.c|| undefined reference to `GetAdaptersInfo@8'| ||=== Build finished: 1 errors, 2 warnings (0 minutes, 3 seconds) ===| Desde já obrigado. Edited May 7, 2013 at 01:58 PM by pmg pastebin.com/wGWQtA5H copiado para o tópico
HappyHippyHippo Posted May 7, 2013 at 01:49 PM Report #506083 Posted May 7, 2013 at 01:49 PM 1º - aumenta o nível de warnings do teu compilador 2º - não ignores nenhuma mensagem de warnign do teu compilador 3º - faz include do header stdio.h IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
ViTALiTY Posted May 7, 2013 at 02:12 PM Author Report #506098 Posted May 7, 2013 at 02:12 PM 1º - aumenta o nível de warnings do teu compilador 2º - não ignores nenhuma mensagem de warnign do teu compilador 3º - faz include do header stdio.h Incluir o header diminuiu a lista de erros, obrigado. Fiquei-me só com este, que não faço ideia como resolver... C:\Users\***\Desktop\testewindows7\main.o:main.c|| undefined reference to `GetAdaptersInfo@8'| ||=== Build finished: 1 errors, 0 warnings (0 minutes, 3 seconds) ===|
pikax Posted May 7, 2013 at 02:14 PM Report #506101 Posted May 7, 2013 at 02:14 PM tens que fazer link da lib: "Iphlpapi.lib" mais info Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
ViTALiTY Posted May 7, 2013 at 02:23 PM Author Report #506105 Posted May 7, 2013 at 02:23 PM tens que fazer link da lib: "Iphlpapi.lib" mais info Obrigado pela resposta. Então basicamente adicionar: #include <stdlib.h> #pragma comment(lib, "IPHLPAPI.lib") ao programa? Continua com o mesmo erro... 😕
pikax Posted May 7, 2013 at 02:25 PM Report #506106 Posted May 7, 2013 at 02:25 PM qual e' o compilador? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
ViTALiTY Posted May 7, 2013 at 02:26 PM Author Report #506107 Posted May 7, 2013 at 02:26 PM qual e' o compilador? É o CodeBlocks. 🙂
pikax Posted May 7, 2013 at 02:31 PM Report #506109 Posted May 7, 2013 at 02:31 PM se nao me engano, o pragma comment nao funciona no C::B, o codigo no site da MS e' para o VS. Vai as configuracoes do codeBlocks e adiciona a lib no linker Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now