|
I try to create a dynamic char-array and then copy a certain number of chars from another string to it:
<br />
char *tempLabel = new char[labelLen];
strncpy(tempLabel, label, labelLen);
When I step through the code the variables contains:
After line 1:
label = "resolutionXììììììììì....aso" (is an [128]-array)
tempLabel = "ìììììììììììýýýý" (as you see, 4 chars too much)
labelLen= 11;
After line 2:
label = "resolutionXììììììììì....aso"
tempLabel = "resolutionXýýýý" (Still too big!)
labelLen= 11;
Why??? I don't want those 'ý'-s, what's wrong? Does anyone have a clue?
|
|
|
|
|
if(labelLen>0)
{
char *tempLabel = new char[labelLen+1]; //Line 1 make room for \0
strncpy(tempLabel, label, labelLen); //Line 2
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Try this:
char *tempLabel = new char[labelLen]; //your Line 1
memset(tempLabel, (int)'\0', labelLen);
strcpy(tempLabel, label); //Line 2
MS
|
|
|
|
|
This is exactly how buffer overruns are exploited (i.e., using strcpy ).
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
This is exactly how buffer overruns are exploited
I would say how they are caused not exploited.
INTP
|
|
|
|
|
Fair enough, but the point remains.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks guys!
Really stupid of me to forget about that '\0'. I should remember that by now...
|
|
|
|
|
BOOL CBeginDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
m_pScene = new CScene( AfxGetMainWnd()->m_hWnd );
return TRUE;
}
Program exit when execute AfxGetMainWnd(),what's wrong!
|
|
|
|
|
When your application starts, the main window isn't already created when OnNewDocument is called the first time. Try this and it will work:
BOOL CBeginDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
if(AfxGetApp()->m_pMainWnd!=0L)
{
m_pScene = new CScene( AfxGetMainWnd()->m_hWnd );
}
return TRUE;
}
Hope this helps
MS
|
|
|
|
|
Hi there,
Because the MainFrame isn't the active window yet - AfxGetMainWnd will return a NULL pointer in which you use without testing.
Why is it that you are initialising your object with the Main window anyway? The object can use the AfxGetMainWnd when it needs access without you setting the value in the constructor. If you are setting the object to use a particular HWND, then set it to NULL in the constructor, then when the object needs the HWND test if it's NULL - if yes then perform AfxGetMainWnd otherwise use the HWND it has.
Hope this helps,
Andy
|
|
|
|
|
I have bought some ActiveX controls from Global Majic about 6 months ago (only get 3 months support), but when I deploy my application I get an Assertion error (its build for Release).
I dont see in the deployment (Visual Studio .Net 2002) how the OC are deployed.
Do I need to register them on the target PC?
Or is the Assertion proble a Red Herring?
|
|
|
|
|
Normally you just have to copy the .ocx file on the target computer and register it using regsvr32.exe.
|
|
|
|
|
OK, thanks. I just wondered if the deployment process would do this.
|
|
|
|
|
I want develop Firewall But how to use Windows Platform SDK. I want Help is it . Your can't explaint or detail about web to detail about Windows Platform SDK . Where i can find it .
|
|
|
|
|
The platform SDK ships with your Visual Studio installation, you don´t need to install it.
You can download the latest version from MS or install from an MSDN CD, it can be necessary if you need to use really new features, or uncommon APIs that don´t ships with VStudio, but usually it is the case for less than 1% of the programs you need to develop.
GuimaSun
www.nexsun.com.br
NEXSUN TechZone
|
|
|
|
|
Errrrrrrrrrr.
If your talking about VC6 - that was shiped in 98. If you set WINVER to 0x500 to target Win 98 and 2k, you will get a message saying that the headerd included with VC6 are for the BETA versions of these OS's.
Yes, you don't need to install the new platform SDK for most things. But the one that comes with VC6 can only really be used to offically target NT and 95.... Anything that 98 has and 95 doesn't, you should use a newer SDK.
|
|
|
|
|
Get it from http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
|
|
|
|
|
I want to develop a VC application which can tell me the name of process or the application generating ARP Requests.
|
|
|
|
|
I am developing a ports scanner for networks. Is there any way to find out what service is running on an open port, i ll be just scanning the popular ports e.g ftp,telnet,http etc, given u have the Admin rights of the domain and what if you don't have the admin rights of the domain.
|
|
|
|
|
Some addon type of programs monitor the host program, and once it is created, they add a control to the program. The control is then a child of the host program (as observed using Spy++). If we close the monitor program, then the host program gives an illegal operation error.
How is this done, and how can we programmatically and safely remove the monitor program?
|
|
|
|
|
Is it possible to get executable's name using it's handle?
|
|
|
|
|
Use This
DWORD GetModuleFileNameEx(
HANDLE hProcess, // handle to process
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // maximum characters to retrieve
);
DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // file name of module
DWORD nSize // size of buffer
);
~Rahuraman.K
|
|
|
|
|
Thanks, GetModuleFileNameEx works but again it needs processid.
|
|
|
|
|
Okay, so call GetCurrentProcessId() first.
|
|
|
|
|
Hi All,
I am writing a MFC program. It has a splitter window which contains 2 CView and CFormView derived Views. I wrote it based on the acticle written by pt315 "Splitter Window Tutorial".(http://www.codeproject.com/splitter/splitterwindowtutorial.asp"
The program up and running in VC7 debug mode. However, when I run the .exe file built by VC7, it seems cannot create the CView derived View and the program abort with 2 messagebox, "Error setting up left view" and "Fail to create empty document".
And I dont have any idea about why it fail when running by .exe.
I attached the code where the problem occur. Could anyone provide me some advice why this is happened?
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) <br />
{<br />
<br />
CRect cr;<br />
GetWindowRect( &cr );<br />
<br />
if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )<br />
{<br />
MessageBox( "Error setting up m_mainSplitter", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
if ( !m_mainSplitter.CreateView( 0, 0, RUNTIME_CLASS(CMPVIEWERView),<br />
CSize(cr.Width()/2, cr.Height()), pContext ) )<br />
{<br />
MessageBox( "Error setting up left view", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CSTATVIEW),<br />
CSize(cr.Width()/2, cr.Height()), pContext ) )<br />
{<br />
MessageBox( "Error setting up right view", "ERROR", MB_OK | MB_ICONERROR );<br />
return FALSE;<br />
}<br />
<br />
m_bInitSplitter = true;<br />
<br />
CMPVIEWERView * mpv ;
mpv = (CMPVIEWERView *) m_mainSplitter.GetPane(0,0); <br />
mpv->m_pStatView = (CSTATVIEW *) m_mainSplitter.GetPane(0, 1);<br />
<br />
m_pMPVIEWERView = mpv;<br />
<br />
return TRUE;<br />
}
|
|
|
|