|
|
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.
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#pragma comment(lib, "Netapi32.lib")
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]);
}
static void GetMACaddress(void)
{
unsigned char MACData[8];
WKSTA_TRANSPORT_INFO_0 *pwkti;
DWORD dwEntriesRead;
DWORD dwTotalEntries;
BYTE *pbBuffer;
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
"\\server",
0,
&pbBuffer,
MAX_PREFERRED_LENGTH,
&dwEntriesRead,
&dwTotalEntries,
NULL);
assert(dwStatus == NERR_Success);
pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer;
for(DWORD i=1; i< dwEntriesRead; i++)
{
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);
}
dwStatus = NetApiBufferFree(pbBuffer);
assert(dwStatus == NERR_Success);
}
int _tmain(int argc, _TCHAR* argv[])
{
GetMACaddress();
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
|
|
|
|
|
Prefix a string literal with L to make it Unicode, eg L"\\\\server001"
Note that you need to escape backslashes in a literal, so to create two backslashes you write \\\\
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
tried that using : char *netbios = L"\\\\server";
...but, compiler says this : error C2440: 'initializing' : cannot convert from 'unsigned short [10]' to 'char *'
...at this line in my source:
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
netbios,
0,
&pbBuffer,
MAX_PREFERRED_LENGTH,
&dwEntriesRead,
&dwTotalEntries,
NULL);
kinda new to conversions, all help is appreciated. thanks in advance
salut
|
|
|
|
|
|
hey mike, thanks for the heads up on that. It seems I am doing it wrong, because the compiler still says the same thing as I said in my last post. It can not convert an unsigned short * to char*. But, when I send a char* to the function, it raises an assertion failure. Have you actually tested the variable, to see if it works? It doesn't for me. thanks
salut
|
|
|
|
|
Anyone have some code to beautify xml??
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hi everyone!
I need to compute a *PRECISE AND ACCURATE* BOUNDING rectangle around a text
I tried with several methods with Windows32 API(s)
- GetTextExtentPoint32
- DrawText (with DT_CALCRECT)
- GetCharWidth32 (Obtaining the width of every char of the string)
I'm using MM_ANISOTROPIC mapping into my device context and seems that the X-Extension of the text is always different by the effective text drawned into the device. This happen when the zoom/scale factor is different by 1.0
What i'm doing of wrong?
Please help me
Thank you
Furno Gianluca
|
|
|
|
|
All,
I have written a COM Object in C++. I have a C# application that calls this COM object. One method in the COM object requires a variable to be modified to inform C# of an error. I create a variable of type Object in C Sharp and pass it by reference to the COM method. The com method receives this variable as a VARIANT*. In my C++ method I use variant_t to assign the integer value I want and assign it to the VARIANT* passed to the COM Method. This seems to work well in Debug mode but in Release I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in CSharp Test Harness.exe
Additional information: Object reference not set to an instance of an object.
Can anyone help unscramble what I am doing wrong or offer a suggestion as to how to code this properly.
Kind regards
Dave
|
|
|
|
|
Hello everybody,
i have a problem with the OnEnable method : once it is used, the normal
display of the CWnd item doesn't work well (not fully grayed if disabled). A
possible workaround is the call the CWnd::RedrawWindow() inside the OnEnable
method, but it works only with VC++8, and i developp with VC++7.
Does anyone of you have a fix for this problem with VC++7 ?
Thanks
Gilles06600
|
|
|
|
|
What is that "CWnd item" which "doesn't work well"? A control?
Did you call the base class OnEnable method, like for example:
void CMyButton::OnEnable(BOOL bEnable)
{
CButton::OnEnable(bEnable);
}
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
you are right, to get the default enabling/disabling behavior of the CWnd, i have to call the base class method. I thought that the OnEnable method was just an empty shell provided by the MFC framework to put some extra code, but i was wrong. It really does some process.
So thank you for your help, my problem is solved
Gilles06600
|
|
|
|
|
It just calls the default window procedure which does its job:
_AFXWIN_INLINE void CWnd::OnEnable(BOOL)
{ Default(); }
LRESULT CWnd::Default()
{
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
return DefWindowProc(pThreadState->m_lastSentMsg.message,
pThreadState->m_lastSentMsg.wParam, pThreadState->m_lastSentMsg.lParam);
}
You are welcome!
Ovidiu
|
|
|
|
|
it's a colorful icon or say it's 256 colors;
I want to load this icon to be a gray one!
is it existing a way to load ?
or it's impossible, on the other hand ,we shall prepare a gray one !
can it to be a gray one?
if it will do, how I load it?
waiting for answers!
Just my interest for these common things
|
|
|
|
|
If you want a monochrome icon then no sweat.
Call ::LoadImage and pass LR_MONOCHROME as load option.
HICON hIcon = (HICON)::LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDI_ICO_256COLOR),
IMAGE_ICON,
0, 0,
LR_MONOCHROME);
If you want a grayscale one, better is to "prepare" it yourself. There are tools that convert color icons to grayscale and Irfan View[^]is a free one.
Import the gray icon in your project resources, then load it like any others.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
helloy all
i need some programs about gedir algorithm
in c++ language
or any links about it
thanks for all
|
|
|
|
|
Hello !
Who can tell me how to distinguish the following case:
case1: Prog.exe is started by double click.
case2: Prog.exe is started by operating system.
case3: prog.exe is started by other program.(for example: ShellExecute())
Distinguish means in the prog, to distinguish.
Thanks!
|
|
|
|
|
It's a very interesting question, but I'm not sure there is a way. Just for curiosity, why do you want to distinguish them?
Best,
Jun
|
|
|
|
|
, the requirement is that:
There is a program (let's name it A.exe), if user double click the A.exe, it doesn't reponse, by other words, user can't start it by double click.
But the A.exe can be started by another program B.exe, and
after user setting, the A.exe can start when the user log in the system(XP or vista).
Best Regards,
|
|
|
|
|
I'm not quite clear about this requirement:
chenxiujie wrote: after user setting, the A.exe can start when the user log in the system(XP or vista).
Best,
Jun
|
|
|
|
|
If you require prog.exe to be started with a parameter, you'll foil all double click attempts. For instance, "prog.exe" just terminates, but "prog.exe /run" makes it run.
--
100% natural. No superstitious additives.
|
|
|
|
|
Hi guys, I've got a quick question.
I have the Borland 5.5 C++ compiler and in order to compile standard C++ code, you type 'BCC32 filename.cpp' in the command screen to compile "filename".
In order to compile a Visual C++ application, you need to add a parameter or setting to that command.
My question is which one is it? I've done it before so I know how it's done, but I've forgotten the exact line and I can't seem to find it on the huge place we call the internet.
Thanks for answering such a stupid question in advance!
|
|
|
|
|
cl /EHsc sample.cpp
Maxwell Chen
|
|
|
|
|
Hmm
That doesn't seem to work.
"cl" is not recognised as being an application, command or batchfile and I'm positive that what I'm referring to was this:
<br />
"BCC32" line "sample.cpp"<br />
with "line" being the extra line which I have forgotten. I think there was a "-" preceding the line, but I'm not sure.
QUite frustrating to have forgotten the line, but my copmiler won't compile a Visual C++ app without the little line.
Thanks for your help anyways!
|
|
|
|
|
Peter Charlesworth wrote: That doesn't seem to work.
"cl" is not recognised as being an application, command or batchfile
You have to run vcvars32.bat to initialize those environment settings before your invoking CL.exe command.
From MSDN Library:
The vcvars32.bat file sets the appropriate environment variables to enable 32-bit command-line builds.
Maxwell Chen
|
|
|
|