|
The following chunk of code is supposed to loop through my CRichEdit control and get each line and show it in a messagebox.. eventually instead this will use a line printing function to print what is in the rich edit control.. heres the code:
void CTextViewer::OnBnClickedPrintbutton()
{
int i, nLineLength, nLineCount = m_edtRichEdit.GetLineCount();
CString strText, strLine;
for (i = 0; i < nLineCount; i++)
{
nLineLength = m_edtRichEdit.LineLength(i);
m_edtRichEdit.GetLine(i, strText.GetBuffer(nLineLength));
AfxMessageBox(strText.GetBuffer(0));
strText.ReleaseBuffer(nLineLength);
}
} heres the error:
Debug Error!
Program : ... blah.exe
DAMAGE: after Normal block (#3741) at 0x002F6B48. debugging throws me into dbgheap.c at _CRTIMP int __cdecl _CrtIsValidHeapPointer(
if i trace through it actually goes through all of the lines, and shows em all on the screen, but as it exits the function it gets this heap error.. any ideas? i copied the richedit example exactly and then modified it, but even unmodified i get the same error.. i thought maybe it was the \n's in my text, but i got rid of all those and have the same prob..
-dz
|
|
|
|
|
Remove GetBuffer(0) from AfxMessageBox call. CString has a LPCTSTR conversion operator.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
still get same series of errors.. i don't really understand this buffer stuff.. i am only familiar with strings.. here is the current look of it:
void CTextViewer::OnBnClickedPrintbutton()
{
int i, nLineLength, nLineCount = m_edtRichEdit.GetLineCount();
CString strText, strLine;
for (i = 0; i < nLineCount-1; i++)
{
nLineLength = m_edtRichEdit.LineLength(i);
m_edtRichEdit.GetLine(i, strText.GetBuffer(nLineLength));
AfxMessageBox(strText);
strText.ReleaseBuffer(nLineLength);
}
}
it is crashing as it exits the function, so im assuming the buffers are somehow messing up the deconstructors?
-dz
|
|
|
|
|
Probably the problem is related to the fact that your buffer should be big enough to hold number of characters in line in first 4 bytes. So you should change two things:
1) increase value passed to GetBuffer by 4
2) use 3-argument version of CRichEditCtrl::GetLine
See EM_GETLINE docs for more information.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Hi
I want to find the default dns server address / default gateway programatically.
Here is a sample output while running ipconfig.exe /all
___________________________________________________________
D:\>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : s
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : Yes
WINS Proxy Enabled. . . . . . . . : Yes
PPP adapter Dishnet:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 202.9.156.173
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0
DNS Servers . . . . . . . . . . . : 202.9.152.11
202.9.145.6
NetBIOS over Tcpip. . . . . . . . : Disabled
___________________________________________________________
Now there it is written DNS servers. How can I find dns servers through code.
Shrishail Rana
|
|
|
|
|
#include <iads.h>
#include <windows.h>
#include <windns.h>
#include <winsock.h>
#include <winerror.h>
#include "stdafx.h"
#include <activeds.h>
#include <stdio.h>
int main(void)
{
PDNS_RECORD pDnsRecord;
DNS_STATUS status;
char szNameBuf[64];
struct hostent *hostinfo;
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
in_addr address;
printf("DNS Server lookup ...!\n");
// Get host by name
if ( WSAStartup(wVersionRequested, &wsaData) )
return 0;
if ( gethostname(szNameBuf,64) )
return 0;
if ( (hostinfo = gethostbyname(szNameBuf)) == NULL )
return 0;
// End Get host by name
// Reverse order
// reverse the byte-order
address.S_un.S_addr = ntohl(*((DWORD*) hostinfo->h_addr_list[0]));
// use "dotted" string format
sprintf(szNameBuf, "%s.in-addr.arpa", inet_ntoa(address));
status =
DnsQuery_A( szNameBuf,
DNS_TYPE_PTR,
DNS_QUERY_BYPASS_CACHE,
NULL,
&pDnsRecord,
NULL );
|
|
|
|
|
Hi,
Is it possible to download ATL 7.0 to use it under VC++ 6.0?
WTL 7.0 is available but not ATL 7.0.
Thanks,
Francisco
|
|
|
|
|
Sadly not.
Michael
Errata 1: p. 154, section 'Defusing'. For 'red wire' read 'blue wire'.
|
|
|
|
|
This is how it's done: I create a CScrollBar object within a window (new / Create / ShowWindow / SetScrollRange), and it looks OK, but although it responds to mouse inputs it doez NOT change its position, but... If I use SetScrollPos it moves to the specified position. The problem is, that it stays there all the time and user cannot move it. It can be used, but when you release your mouse button the tracking box returns to it's previous position. Strange... I suppose I missed something, but I can't figure out what it is.
I would like to use only GetScrollPos/SetScrollPos and in some cases SetScrollRange/SetScrollInfo (when data changes or window resizes)
Krzysztof Szczech [CoY0te]
k_szczech@o2.pl
|
|
|
|
|
This is not a problem - it's a feature. Your program should set the scrollbar position in WM_HSCROLL/WM_VSCROLL handlers.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
It helped. Now i just have to process these LINE/PAGE/THUMB codes.
Thank You.
Krzysztof Szczech [CoY0te]
|
|
|
|
|
I want to I want manipulate it's size when the toolbar was floating .But I found that it can not success when I use function MoveWindow().
how can I do?
Don't look at me in that way!
|
|
|
|
|
I don't know the problem exactly ,but maybe this would help:
WINDOWPLACEMENT Place;
Place.rcNormalPosition.left = ... ;
Place.rcNormalPosition.right = ... ;
Place.rcNormalPosition.top = ... ;
Place.rcNormalPosition.bottom = ... ;
// Window must be a CWnd object
Window->SetWindowPlacement(&Place);
This function allows to manipulate all dimensions of a window simulatenously. I don't know if You use MFC or windows API, so I can't tell You more...
Krzysztof Szczech [CoY0te]
|
|
|
|
|
Floating toolbars are hosted in CMiniFrameWnd windows - so you really need to resize the frame window. To get a pointer to CMiniFrameWnd, call CControlBar::GetDockingFrame, then use MoveWindow.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I want draw text on position of cursor/
How i can quick draw text without full invalidate?
|
|
|
|
|
I don't think that SetROP2 will work for you with [Ext]TextOut or DrawText[Ex]. I'd draw the text to off-screen bitmap, then use BitBlt with SRCINVERT.
Also, you could try creating a path, using ExtTextOut or TextOut, then setting SetROP2 and calling StrokePath/FillPath. Never tried this personally, however.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
|
Hi,
I'm making this DLL that has about 60 exported functions. Some of them work perfectly in the client app, but not all. I've discovered that it's the functions with 'const std::wstring&' parameters that don't work properly. When I compile the client app, I get the following error:
unresolved external symbol "bool __cdecl TASFileDup(class std::basic_string,class std::allocator > const &)"
I have no idea why some of the functions work and others don't. I get no errors or warnings when I compile the DLL.
I've tried writing 'using namespace std' in the client app, but that had no effect. Any suggestions?
Jarle
|
|
|
|
|
If you are not aware of it already: If you pass or return any of these classes by value you must use the DLL version of the CRT (mixing heaps spells d-i-s-a-s-t-e-r).
My guess why only some functions are failing is that it's just these functions that make use of not yet instantiated class templates.
In my experience the std:: types unfortunately fits like a foot in a glove when mentioned in module (such as DLL) interfaces. What you have experienced now is just the tip of the iceberg.
|
|
|
|
|
Can someone help me in the right direction? I am really stuck trying to create my own linked list base class.
The problem shows up when I derive a class from the linked list base class.
Because within the baseclass I want to manage the list and add new nodes, but these are forced be like ' new CBaseClassList'. So that derived classes do not truly inherit the linked list ability, since only base class nodes are added. I hope I made my problem clear. Let my try to explain better in simple code:
class CBaseClassList
{
CBaseClassList *liststart_node;
AddNode();
int basedata;
}
CBaseClassList::AddNode()
{
liststart_node = new CBaseClassList();
}
class CDerivedClass : public CBaseClassList
{
int deriveddata;
DoStuff();
}
CDerivedClass::DoStuff()
{
// Adding a new node from within the derived class will only create
// a node based on the baseclass!!
// So I am not able to use CDerivedClass datamembers
AddNode();
// OK:
liststart_node->basedata = 10;
// impossible:
liststart_node->deriveddata
}
Please note that I really want the baseclass to stay as absract as possible so that I neednt create multiple linked list code in my project and that I can use it for pretty much anything. Just one baseclass linked list to derive and inherrit linked list ability from. I do know about STL, but I need my own baseclass list construction in this project (in relation to fast code).
|
|
|
|
|
Bug wrote:
do know about STL, but I need my own baseclass list construction in this project (in relation to fast code).
In relation to fast code, you should use STL anyway. Unless this is kind of homework, of course.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Why are you not using a template class?
|
|
|
|
|
I'm trying using templates now. Thanks.
|
|
|
|
|
I have a thread function and I define it as global function:
This function get the focused window and change the position of it.
BOOL bdown = false ;
UINT ThreadFunc(LPVOID pparam)
{
WINDOWINFO info;
HWND hwnd;
DWORD dword;
hwnd = (HWND)GetForegroundWindow();
GetWindowThreadProcessId( hwnd , &dword);
AttachThreadInput( dword , GetCurrentThreadId() ,true);
hwnd = GetFocus();
if(hwnd != NULL)
GetWindowInfo( hwnd ,&info );
else
{
hwnd = (HWND)GetForegroundWindow();
GetWindowInfo( hwnd ,&info );
}
if(hwnd!=NULL)
{
int x = info.rcWindow.left;
int y = info.rcWindow.top;
int width = (info.rcWindow.right-info.rcWindow.left);
int height = (info.rcWindow.bottom-info.rcWindow.top) ;
if(bdown)
y -= 90;
else
y += 90;
SetWindowPos(hwnd , HWND_NOTOPMOST , x , y , width ,height , SWP_SHOWWINDOW);
if(bdown)
bdown = false;
else
bdown = true;
Sleep(1000);
}
return 0;
}
I start thread in my OnInitDialog of my class like this:
AfxBeginThread(ThreadFunc, 0);
The problem is that if when I call the function without starting thread it works and change the position but when I start the thread nothing happend.also when I debug my application it change the postion for one time and it seems that it does not called another time.Any idea?
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Your thread function executes once and then returns - the thread finishes. Some kind of loop is missing.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|