|
dear neville
stop shuving your ED, it is not the place. THANKS FOR YOUR HELP
|
|
|
|
|
when i run this code,message box appear "out of memory error".
someone please explain me.Why?
following my code--->>
void CIPAddressDlg::OnButton1()
{
CListBox *pList = (CListBox*) GetDlgItem(IDC_LIST2);
pList->ResetContent();
PMIB_IPNETTABLE pIPNetTable = NULL;
PMIB_IPNETROW pIPNetRow;
in_addr ia;
char *szTypes[4] = {"Other", "Invalid", "Dynamic", "Static"};
GetIpNetTable((PMIB_IPNETTABLE) m_pBuffer, &m_ulSize, TRUE);
m_pBuffer = new BYTE[m_ulSize];
if (NULL != m_pBuffer)
{
pList->AddString("Start get ip net table");
m_dwResult = GetIpNetTable((PMIB_IPNETTABLE) m_pBuffer, &m_ulSize, TRUE);
if (m_dwResult == NO_ERROR)
{
pIPNetTable = (PMIB_IPNETTABLE) m_pBuffer;
for ( unsigned int x = 0; x < pIPNetTable->dwNumEntries; x++)
{
pIPNetRow = &(pIPNetTable->table[x]);
m_strText.Format(" Index: %lu\r\n", pIPNetRow->dwIndex);
pList->AddString(m_strText);
m_strText.Format("MAC address length: %lu\r\n", pIPNetRow->dwPhysAddrLen);
pList->AddString(m_strText);
m_strText.Format(" MAC address: %02x-%02x-%02x-%02x-%02x-%02x\r\n",
pIPNetRow->bPhysAddr[0],
pIPNetRow->bPhysAddr[1],
pIPNetRow->bPhysAddr[2],
pIPNetRow->bPhysAddr[3],
pIPNetRow->bPhysAddr[4],
pIPNetRow->bPhysAddr[5]);
pList->AddString(m_strText);
ia.S_un.S_addr = pIPNetRow->dwAddr;
m_strText.Format(" IP address: %s\r\n", inet_ntoa(ia));
pList->AddString(m_strText);
m_strText.Format(" Type: %s\r\n", szTypes[pIPNetRow->dwType - 1]);
pList->AddString(m_strText);
}
}
else
{
m_strText.Format("GetIpNetTable() failed.Result = %lu\r\n", m_dwResult);
pList->AddString(m_strText);
}
delete [] m_pBuffer;
}
}
|
|
|
|
|
vc-programmer- wrote:
GetIpNetTable((PMIB_IPNETTABLE) m_pBuffer, &m_ulSize, TRUE);
m_pBuffer = new BYTE[m_ulSize];
This is strange
typedef struct _MIB_IPNETTABLE {
DWORD dwNumEntries; // number of entries in table
MIB_IPNETROW table[ANY_SIZE]; // array of ARP entries
} MIB_IPNETTABLE, *PMIB_IPNETTABLE;
Le Ridder Noir
Considderd to be the worlds fastest knoppenbonker.
three years of working experience with the worlds fastest copie paster(about 2000 lines a minute).
And experience with the one and only NewEra Guru and Crystal Ace.
|
|
|
|
|
The problem is that m_ulSize (assuming that's a class member) is default-initialised by the debug memory allocator to 0xcccccccc, and you've not set it the first time you use it. GetIpNetTable says that's big enough (and incidentally writes the table to the garbage pointer you probably provided as the first argument) and doesn't set m_ulSize to anything. You then try to get new to allocate a huge buffer, which fails and produces the 'out of memory' error.
In C and C++, you must always initialise every variable you use. Failing to do this inevitably leads to some problem where you've used an uninitialised value.
Since the lifetime of the buffer pointed to by m_pBuffer is the length of this method (you delete it at the end), I'd make m_pBuffer a local variable instead. I'd also make m_ulSize a local variable, along with m_strText.
Something you've not considered is that the size of the table can change between calls to GetIpNetTable. If another ARP request occurs between the calls, the size will change. A common way of handling this problem is simply to use a while loop, quitting when the error is no longer ERROR_INSUFFICIENT_BUFFER.
A fixed version follows:
void CIpNetTableDlg::OnButton1()
{
CListBox *pList = (CListBox*) GetDlgItem(IDC_LIST2);
pList->ResetContent();
PMIB_IPNETTABLE pIPNetTable = NULL;
PMIB_IPNETROW pIPNetRow;
in_addr ia;
char *szTypes[4] = {"Other", "Invalid", "Dynamic", "Static"};
BYTE* pBuffer = NULL;
ULONG ulSize = 0;
DWORD dwError = GetIpNetTable((PMIB_IPNETTABLE) pBuffer, &ulSize, TRUE);
CString strText;
while ( ERROR_INSUFFICIENT_BUFFER == dwError )
{
delete[] pBuffer;
pBuffer = new BYTE[ulSize];
if ( pBuffer == NULL )
break;
dwError = GetIpNetTable((PMIB_IPNETTABLE) pBuffer, &ulSize, TRUE);
}
if ( dwError == NO_ERROR )
{
pIPNetTable = (PMIB_IPNETTABLE) pBuffer;
for ( unsigned int x = 0; x < pIPNetTable->dwNumEntries; x++)
{
pIPNetRow = &(pIPNetTable->table[x]);
strText.Format(" Index: %lu", pIPNetRow->dwIndex);
pList->AddString(strText);
strText.Format("MAC address length: %lu", pIPNetRow->dwPhysAddrLen);
pList->AddString(strText);
strText.Format(" MAC address: %02x-%02x-%02x-%02x-%02x-%02x",
pIPNetRow->bPhysAddr[0],
pIPNetRow->bPhysAddr[1],
pIPNetRow->bPhysAddr[2],
pIPNetRow->bPhysAddr[3],
pIPNetRow->bPhysAddr[4],
pIPNetRow->bPhysAddr[5]);
pList->AddString(strText);
ia.S_un.S_addr = pIPNetRow->dwAddr;
strText.Format(" IP address: %s", inet_ntoa(ia));
pList->AddString(strText);
strText.Format(" Type: %s", szTypes[pIPNetRow->dwType - 1]);
pList->AddString(strText);
}
}
else
{
strText.Format("GetIpNetTable() failed.Result = %lu", m_dwResult);
pList->AddString(strText);
}
delete [] pBuffer;
}
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Is it that GetKeyState can be used only for Toggle keys and control keys like alt,ctrl, Esc , Enter .etc...
Can i use GetKeyState function to get the state of alphabet keys like A - Z or a -z... If so how ?? The argument passed should be the scan code of the character or Virtual Key codes ??? Plz help...thank u
|
|
|
|
|
You need to test if the Shift Key is down - VK_SHIFT from memory. Also CapsLock.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Can someone explain me how to do this ?? plz....with a simple sample code...thank u
|
|
|
|
|
Sure:
#define KEY_DOWN( X ) ( (X) & 0x8000 )
BOOL
kb_shift_down()
{
return KEY_DOWN( GetKeyState( VK_SHIFT ) ) != 0;
}
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Thanks for ur patience friend...But still my doubt was how to get the key state of alphabet keys...ie A-Z or a-z ...
should i give as GetKeyState('A') or
GetKeyState(Scancode of the character)
Thank u
|
|
|
|
|
|
Yes , i can understand friend...but this case works out in a single machine..But in Client and Server concept it fails..I use the same GetKeyState() fn to retrieve the keystate...I check for its return value...
getKey = ::GetKeyState(vk);
if(getKey & 0xF000)
printf("%c pressed 0xF000\n",tempbuffer[c]);
else if(getKey & 0x000F)
printf("%c releases 0x000F\n",tempbuffer[c]);
else if(getKey & 0x0001 == 0x0001)
printf("%c Key is toggled\n",tempbuffer[c]);
else if( getKey & 0x8000 == 0x8000)
printf("%c Key is pressed\n",tempbuffer[c]);
else
printf("%c key is neither pressed nor toggled",tempbufferc]);
}
For the above cases
for some of the characters condn. fails and so the message
"Key is neither pressed nor toggled " message gets printed.
What can i do for this ?
Thank u
|
|
|
|
|
When using cdhtmldialog in MFC, the default html file is embedded in the resource. But can I load the html file somewhere in my local machine? thanks for reading.
|
|
|
|
|
|
In VC6, you could add an "Active Document Server" to your project, which would open an in-place-editor in the Devstudio IDE. (With all thebenefits like automatic saving when starting a build)
Can anything similar be done in VC7.1? ADS don't seem to work at all. How?
I never really know a killer from a savior boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
If I want to detect the activity(Playing or Recording) of audio device, how can I do?
Is there any Windows API function, Service, or Driver solution?
In addition, how to detect the activity of devices like bluetooth, wireless...etc
|
|
|
|
|
Hi folks,
I have cretaed an SDI application in vc++.
Now i want to change the font of text in the title bar.
How do i do that?
|
|
|
|
|
use CWnd::SetWindowText() function.....
hope that helpz.....
cheerz.....
|
|
|
|
|
Dear rateep,
Setwindowtext() only displays the desired text in the title bar. But my requirement is to change the font of that text.
So please help me find the solution.
Regards,
srinipkweb
|
|
|
|
|
vote 1...
SetWindowText() sets a caption, not the font
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I think the only way you're going to do that is by painting the frame window yourself. In other words by intercepting the WM_NCPAINT, and painting the non client areas (which include the title bar) yourself
|
|
|
|
|
HI Garth,
Thanks for the response.
But will you please give the exact code for painting the frame and its location within the application code.
|
|
|
|
|
See here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
someone help me, how to code app to play internet radio?
thanks
Nho'c Ti`
|
|
|
|
|
I'm trying to draw a line over a bitmap that is not coming from one of the corners of a pixel,
It can be from the center or any other place as well as the corners of a pixel, currently
if you draw a line, using LineTo(int,int) what happens is the line doesn't start from the
center of the pixel it starts from typically the left upper corner of the pixel,
given a line say that is drawn in paint by pixels, what i want to do is draw a real line (vector type not raster)
that doesn't concern it's self with the actual pixel, similar to a trace program for raster to vector graphics (Adobe Streamline).
they have bitmapped lines, then they draw vector line types over the top of the bitmapped ones,
and when you look at the line it looks as if it was centered on the pixels if it was a vertical or horizontal.
I want to do the same thing....
I was looking at LineDDA but that didn't work I tried LineTO and that didn't work, LineToEx() as well if I have say pixels
50,50 to 150,50 the line that you draw is on the left side of the pixels and is not centered...?
I basically have a bitmap that displays fine, it is in a scrollview and moves, zooms, pans and the scroll perfectly
int py=GetScrollPos(SB_VERT);
CSize sz(GetTotalSize());
// TODO: calculate the total size of this view
int x=(int)( ima->GetWidth()*m_pDoc->m_ZoomFactor);
int y=(int)(ima->GetHeight()*m_pDoc->m_ZoomFactor);
SetScrollSizes(MM_TEXT, CSize(x,y));
Now I realize I am using MM_TEXT so can you create another Mapped cordinate system on top of a bitmap, and how do you do this?
HEre is the basic idea of what i do to draw a bitmap, now I want to draw on top of the bitmap to (but not actually in the bitmap )
(* TAKE A LOOK AT ADOBE streamline *) that is what I want to do....
void OnDraw(CDC* pDC)
{
CVtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
BOOL bPrinting = pDC->IsPrinting();
CMemDC* pMemDC = NULL;
if (!bPrinting)
pDC = pMemDC = new CMemDC(pDC);
/* more stuff */
SetStretchBltMode(hdc,COLORONCOLOR);
SetDIBitsToDevice(hdc, x, y, cx, cy, 0, 0, 0, cy,info.pImage,(BITMAPINFO*)pDib,DIB_RGB_COLORS);
/*all done now */
delete pMemDC;
}
Any ideas, I'm sure this is very easy.... a simple source code example of a line would be greatly appreciated.
(I will extend this too arcs as well latter)
|
|
|
|
|
Dear All,
I want to develop a tool for the Fault Tree Analysis[FTA].
Now,I can only draw a simple static fault tree using my FTA tool,and with less analysis of minimal cutset.
For further research,I plan to:
(1)Add more analysis;
(2)Draw dynamic fault tree using the new dynamic gates;
(3)Use Markov Chain;
But I don't know the relationship between the static fault tree and the dynamic one,i.e. how to handle them in my FTA tool? and how to use Markov Chain?
If you are familiar with any software packages that can take care of these kinds of things please let me know about them.
If you are interested in FTA,could you please tell me some useful web sites?
If you are developing the FTA tool,would you please give me some examples/source codes about them?
Any information about these will be very highly appreciated.
Thanks in advance.
***
We are making progress everyday.
|
|
|
|
|