Click here to Skip to main content
15,893,722 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Unhandled Exception when outputting strings Pin
capricious_00124-Jun-06 13:16
capricious_00124-Jun-06 13:16 
AnswerRe: Unhandled Exception when outputting strings Pin
Jun Du24-Jun-06 13:22
Jun Du24-Jun-06 13:22 
AnswerRe: Unhandled Exception when outputting strings [modified] Pin
Sam Hobbs24-Jun-06 15:35
Sam Hobbs24-Jun-06 15:35 
AnswerRe: Unhandled Exception when outputting strings Pin
Stephen Hewitt24-Jun-06 17:41
Stephen Hewitt24-Jun-06 17:41 
QuestionRe: Unhandled Exception when outputting strings Pin
capricious_00125-Jun-06 2:10
capricious_00125-Jun-06 2:10 
Questionasp help Pin
khasiguy24-Jun-06 9:42
khasiguy24-Jun-06 9:42 
AnswerRe: asp help Pin
Michael Dunn24-Jun-06 12:29
sitebuilderMichael Dunn24-Jun-06 12:29 
QuestionGet MAC help Pin
borono24-Jun-06 9:42
borono24-Jun-06 9:42 
hey, I need some help passing a char. When the app. starts, it has an assertion failure, because the NetWkstaTransportEnum() function fails when I pass the netbios name of a server on my network to it. If I use NULL, it outputs the local MAC address.

// GetMACNETBIOS.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>


#pragma comment(lib, "Netapi32.lib")

// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
	printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
		MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}

// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
	unsigned char MACData[8];						// Allocate data structure for MAC (6 bytes needed)

	WKSTA_TRANSPORT_INFO_0 *pwkti;					// Allocate data structure for Netbios
	DWORD dwEntriesRead;
	DWORD dwTotalEntries;
	BYTE *pbBuffer;
    
	//MessageBox(NULL,netbios,0,0);

	// Get MAC address via NetBios's enumerate function
	NET_API_STATUS dwStatus = NetWkstaTransportEnum(
		"\\server",					// [in]  server name :: <-- fails here, if NULL, returns local MAC OK
		0,							// [in]  data structure to return
		&pbBuffer,					// [out] pointer to buffer
		MAX_PREFERRED_LENGTH,		// [in]  maximum length
		&dwEntriesRead,				// [out] counter of elements actually enumerated
		&dwTotalEntries,			// [out] total number of elements that could be enumerated
		NULL);						// [in/out] resume handle

	assert(dwStatus == NERR_Success);

	pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer;		// type cast the buffer

	for(DWORD i=1; i< dwEntriesRead; i++)			// first address is 00000000, skip it
	{												// enumerate MACs and print
		swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx", 
			&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
		PrintMACaddress(MACData);
	}

	// Release pbBuffer allocated by above function
	dwStatus = NetApiBufferFree(pbBuffer);
	assert(dwStatus == NERR_Success);
}

int _tmain(int argc, _TCHAR* argv[])
{

	GetMACaddress();							// Obtain MAC address of adapters

	return 0;
}


I think I may need to do a unicode conversion, but am not sure how. It may not even be that, as well. So, I need help passing the netbios name of a remote server (e.g. \\SERVER001), to the NetWkstaTransportEnum() function. All help is very much appreciated, thanks in advance.

salut
AnswerRe: Get MAC help Pin
Michael Dunn24-Jun-06 12:32
sitebuilderMichael Dunn24-Jun-06 12:32 
GeneralRe: Get MAC help Pin
borono24-Jun-06 15:00
borono24-Jun-06 15:00 
GeneralRe: Get MAC help Pin
Michael Dunn24-Jun-06 15:32
sitebuilderMichael Dunn24-Jun-06 15:32 
GeneralRe: Get MAC help Pin
borono24-Jun-06 15:54
borono24-Jun-06 15:54 
QuestionBeautify XML Pin
Ed K24-Jun-06 7:33
Ed K24-Jun-06 7:33 
QuestionHELP! * Accurate Text Extent needing * Pin
Furno Gianluca24-Jun-06 7:09
Furno Gianluca24-Jun-06 7:09 
QuestionC# and C++ and COM variables Pin
Dave_Roach24-Jun-06 6:35
Dave_Roach24-Jun-06 6:35 
QuestionCWnd::OnEnable and CWnd display Pin
Gilles0660024-Jun-06 5:52
Gilles0660024-Jun-06 5:52 
QuestionRe: CWnd::OnEnable and CWnd display Pin
ovidiucucu25-Jun-06 5:24
ovidiucucu25-Jun-06 5:24 
AnswerRe: CWnd::OnEnable and CWnd display Pin
Gilles0660026-Jun-06 0:39
Gilles0660026-Jun-06 0:39 
GeneralRe: CWnd::OnEnable and CWnd display Pin
ovidiucucu29-Jun-06 2:44
ovidiucucu29-Jun-06 2:44 
QuestionHow to display a gray icon Pin
xuwenq8824-Jun-06 5:31
xuwenq8824-Jun-06 5:31 
AnswerRe: How to display a gray icon Pin
ovidiucucu25-Jun-06 5:06
ovidiucucu25-Jun-06 5:06 
Questioni need gedir simulation Pin
nadeemali24-Jun-06 5:24
nadeemali24-Jun-06 5:24 
QuestionHow to distinguish start method Pin
chenxiujie24-Jun-06 3:05
chenxiujie24-Jun-06 3:05 
AnswerRe: How to distinguish start method Pin
Jun Du24-Jun-06 3:57
Jun Du24-Jun-06 3:57 
GeneralRe: How to distinguish start method Pin
chenxiujie24-Jun-06 14:08
chenxiujie24-Jun-06 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.