|
Hello,
does anybody know how to get the unique LAN-ID from MFC C++?
I have to code a license control tool...
Thank you for answers!
Andreas Niedermeier
==----===
|
|
|
|
|
You can use the physical address of your net adapter
int CTcpCfg::GetMacAddress(LPMAC_ADDRESS pMacAddr)
{
NCB ncb;
UCHAR uRetCode;
int num = 0;
LANA_ENUM lana_enum;
memset(&ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&lana_enum;
ncb.ncb_length = sizeof(lana_enum);
//ÏòÍø¿¨·¢ËÍNCBENUMÃüÁî,ÒÔ»ñÈ¡µ±Ç°»úÆ÷µÄÍø¿¨ÐÅÏ¢,ÈçÓжàÉÙ¸öÍø¿¨
//ÿÕÅÍø¿¨µÄ±àºÅµÈ
uRetCode = Netbios(&ncb);
if (uRetCode == 0)
{
num = lana_enum.length;
//¶ÔÿһÕÅÍø¿¨,ÒÔÆäÍø¿¨±àºÅΪÊäÈë±àºÅ,»ñÈ¡ÆäMACµØÖ·
for (int i = 0; i < num; i++)
{
ASTAT Adapter;
if(GetAddressByIndex(lana_enum.lana[i],Adapter) == 0)
{
pMacAddr[i].b1 = Adapter.adapt.adapter_address[0];
pMacAddr[i].b2 = Adapter.adapt.adapter_address[1];
pMacAddr[i].b3 = Adapter.adapt.adapter_address[2];
pMacAddr[i].b4 = Adapter.adapt.adapter_address[3];
pMacAddr[i].b5 = Adapter.adapt.adapter_address[4];
pMacAddr[i].b6 = Adapter.adapt.adapter_address[5];
}
}
}
return num;
}
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
Hello;
I'm in trouble with setitem method of CListCtrl. Actually, i have set the item value, but it has not get the correct value at following code part.
<br />
int n=0, idx=0;<br />
CString pbBuffer;<br />
char chngval;<br />
char hexval[2];<br />
char* out;<br />
out = (char*)malloc(sizeof(char) * 41);<br />
memset(out, 0x00000000, sizeof(char) * 41);<br />
<br />
while(m_cPeriodList.GetCount()!=idx)<br />
{<br />
m_cPeriodList.GetText(idx, pbBuffer);<br />
n=wcstol(pbBuffer, '\0', 10);<br />
memset(hexval, 0, sizeof(hexval));<br />
for (int i=1; i>=0; i--) {<br />
chngval="0123456789ABCDEF"[((n >> i*4) & 0xF)];<br />
memcpy(hexval+(1-i), &chngval, sizeof(char));<br />
}<br />
hexval[2]='\0';<br />
idx++;<br />
strcat(out, hexval);<br />
}<br />
<br />
int zerocounter=(40-(idx*2))/2;<br />
for(int temp_idx=0; zerocounter!=temp_idx; temp_idx++)<br />
strcat(out, "00");<br />
<br />
lvi->mask = LVIF_TEXT;<br />
lvi->iSubItem = 3;<br />
lvi->iItem = 0;<br />
lvi->pszText = (LPTSTR)(LPCTSTR)out;<br />
m_list->SetItem(lvi);<br />
szTemp.Empty();<br />
<br />
free(out);<br />
Everythings going fine until "lvi->pszText = (LPTSTR)(LPCTSTR)out;". At this statement, the out value has "B0B0B0B0", but lvi->pszText show own value like "?????????????". What does it mean?
Thank you
|
|
|
|
|
Why are you mixing C and C++ ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Just a sample for myself. Sorry.
|
|
|
|
|
I've changed my code to C++ and life is good now.
INT iHexIdx=0; // Hex convertion loop index
LONG lRowIdx=0; // Row index pointer
LONG lRowLongValue=0; // Converted row value
CString rTemp; // Temporary value
CString rString; // Listbox selected item text
// Loop until end of list
while(m_cPeriodList.GetCount()!=lRowIdx)
{
// Get text from listbox
m_cPeriodList.GetText(lRowIdx, rString);
// Convert CString listbox value to LONG
lRowLongValue = _wtoi(rString.GetBuffer(rString.GetLength()));
// Convert byte to hex
for(iHexIdx=1; iHexIdx>=0; iHexIdx--)
rTemp.Insert((rTemp.GetLength()+(1-iHexIdx)),("0123456789ABCDEF"[((lRowLongValue >> iHexIdx*4) & 0xF)]));
// Increase row index
lRowIdx++;
}
// Fill empty bytes with 0
for(iHexIdx=rTemp.GetLength(); iHexIdx<=40; iHexIdx++)
rTemp.Insert(iHexIdx, _T("0"));
// Set comment
lvi->mask = LVIF_TEXT;
lvi->iSubItem = 3;
lvi->iItem = 0;
lvi->pszText = (LPTSTR)(LPCTSTR)rTemp;
m_list->SetItem(lvi);
|
|
|
|
|
How to Handle Escape button in Modeless Dialog
Thanks
Uday
|
|
|
|
|
You will need to use the IsDialogMessage function in your message loop to dispatch your message to the dialog rather than DispatchMessage.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
What's the fastest and easiest way to convert a BSTR to a MFC CString ?
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
donno whether this is the fastest or easiest, but I've been coding it like this:
CString str = static_cast<LPCTSTR>( bstr );
|
|
|
|
|
Does that work ? I don't see how it can.....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
_bstr_t is a wrapper class that does the conversion for you, so you can do this:
CString s((_bstr_t)BSTR);
This will create a _bstr_t, which will return a char * to the CString constructor.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
sorry i forgot, that bstr is of type _bstr_t. u r rite, Chris.
|
|
|
|
|
No worries
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thanks!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
the best & easy way to conver BSTR to string is use the com_util helper as follows:
_bstr_t tmpBSTR = _com_util::ConvertStringToBSTR(szString);
or the other way around:
CString szString = _com_util::ConvertBSTRToString((BSTR)tmpBSTR);
you can check out the definitions of this functions in
COMUTIL.H
hope this helps ya
Yaron
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
Nope, the best and easiest way to construct a CString from a BSTR is to use the LPCWSTR constructor that CString has. So:
CString str( (LPCWSTR)bstr );
should do what you want. Note that this works because a BSTR is also a LPCWSTR (although a LPCWSTR is not necessarily a BSTR!). This method means that no temporary copies will be made, the Unicode-to-MBCS conversion will be made inside CString and no unnecessary string manipulation happens. Using _bstr_t will also work but with the overhead of a temporary copy of both the _bstr_t and the char* (_bstr_t will first construct itself from BSTR, then it will make an MBCS version and then CString will make a copy of it).
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
The casting is unneeded here, since:
typedef wchar_t *LPCWSTR;
typedef wchar_t *BSTR;
There is no need for casting, unless bstr is not a pure BSTR.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Correct. It does however make it clear what constructor we are using - but then again we might not care
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
It is a gratuitious cast and has the potential to break the code in the future. NEVER use an explicit cast unless you have to.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
CString str = bstr;
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
Hello,
How to I know if a pidl or a path is a shortcut? I know how to resolve
the path by using IShellLink but I would like to detect if it's a shortcut
before resolve it.
Thanks!
|
|
|
|
|
I press F1 in the editor window. However, it displayed very often "The page cannot be displayed" or "Cannot find server". It makes the help system not usable. Isn't it the help is in my harddisk after installation of VS.NET ?? How can i solve this problem ?
|
|
|
|
|
I use Visual C++ 6.0 and I want to display thai font on dialog box. So I open resource and write thai font on dialog box. When I compile program the dialog box can not show thai font. It display _________ . Do you know how to solve my problem?
Thank you.
|
|
|
|