|
Visual C++ 6.0
I am trying to open notepad with CreateProcess function.
function returns true.
Then i get CWnd* handle to the window of notepad by using FindWindow(..)
I get a CWnd* handle to the notepad window.
Now.. here is the problem code:
I try to set focus to the notepad by following command
handle->BringWindowToTop();
i get (MFC42D.DLL): 0xC0000005: Access Violation.
please help me resolve this problem
Ritesh
|
|
|
|
|
Do you have the same problem if you build your app for release?
Perhaps the "Mixed DLLs" section in this article[^] can be of interest.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
riteshsv wrote: Then i get CWnd* handle to the window of notepad by using FindWindow(..)
You do realize that this could result in a deadlock situation if Notepad is currently in a blocking situation, don't you?
While probably of less importance to you, it will also fail if your program is internationalized, because the caption will be different.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you use of EnumWindow instead FindWindow?
|
|
|
|
|
Hi guys,
I've got a problem as follow.
Suppose we have a string class named MyString. This class has a constructor to construct a MyString object base on a char * like this:
<br />
class MyString<br />
{<br />
private:<br />
char *m_pData;<br />
int *m_iLength;<br />
<br />
public:<br />
MyString(char *s)<br />
{<br />
m_iLength = strlen(s);<br />
m_pData = new char[m_iLength + 1];<br />
strcpy(m_pData, s);<br />
}<br />
};<br />
And we have a main function like this:
<br />
void main()<br />
{<br />
char *p = new char[5];<br />
MyString s(p);<br />
}<br />
The question is: the p pointer is allocated only 5 char in the memory, but the strlen function can return a value bigger than 5 (depend on where it finds the '\0' char in the memory of pointer). So the MyString object can access unallocated memory. Does it safe? How can we solve this problem?
Best regards.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
nmhuy wrote: So the MyString object can access unallocated memory. Does it safe?
As long as you don't write to the memory you haven't allocated, you're fine as long as strlen() finds a '\0' char within the virtual address space assigned to the process.
You won't get an access violation by reading addresses on the heap even if the memory hasn't been allocated.
nmhuy wrote: How can we solve this problem?
Well, it depends on how you want it to work.
Probably you can guess a maximum length of the strings and provide that as a default parameter to the constructor, e.g:
MyString( const char* pStr, int nMaxLength = 256 );
If the calculated length of the string exceeds the nMaxLength you could either treat is as an error and not copy the string and possibly throw an exception, or only copy nMaxLength chars of it. You would also have the possibility to make a new guess for the maximum string length for each string object constructed if you need to.
BTW, in your example you've declared the length member as a pointer to an integer...
I assume that it's really an integer in your code.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
You're right. I had a typing mistake. m_iLength is an integer.
Thanks for you answer.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
Hey Friends
I need the given below code converted to c++
<dllimport("uxtheme.dll", bestfitmapping:="False," callingconvention:="CallingConvention.Winapi," charset:="CharSet.Unicode," entrypoint:="#65" )=""> _
Private Shared Function SetSystemVisualStyle(ByVal pszFilename As String, ByVal pszColor As String, ByVal pszSize As String, ByVal dwReserved As Integer) As Integer
End Function 'Set the Visual style, for example Luna.msstyles
I tried
HMODULE hmodFonc;
DWORD Ordinal = MAKELONG(0, 65);
FARPROC Proc;
hmodFonc = LoadLibrary(_T("uxtheme.dll"));
if (!hmodFonc) {
_tprintf(_T("Err LoadLibrary: %ld\n"), GetLastError() );
return ;
}
Proc = (FARPROC)GetProcAddress(hmodFonc, (LPCSTR) &Ordinal);
if (!Proc ) {
//_tprintf(_T("Err GetProcAddress: %ld\n"), GetLastError() ); << err 127 ERROR_PROC_NOT_FOUND
return ;
}
However always it is not able to find the proc address.
The function is to change windws xp theme.
Need Help
Regards
|
|
|
|
|
vikrant kpr wrote: I need the given below code converted to c++
I didnt see any VB code in your post. Only a function declaration.??
|
|
|
|
|
yeah that's it
this is working & when called changes the windows theme
|
|
|
|
|
|
Can this function declaration be converted to c++?
the function is calling a function with ordinal number 65 from uxtheme.dll
|
|
|
|
|
vikrant kpr wrote: DWORD Ordinal = MAKELONG(0, 65);
Your parameters to MAKELONG are in the wrong order. Documentation says:
For MAKELONG:
DWORD MAKELONG (WORD wLow, WORD wHigh)
And for the 2nd parameter to GetProcAddress:
If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.
Judy
|
|
|
|
|
Tried that as well
no luck
|
|
|
|
|
|
My app is crashing unexpectedly and I suspect that it is because of the CArray object I am using.
I have a CArray inside a structure, and I have an array of this structure.
For example:
struct type1
{
unsigned char variable1;
unsigned char variable2;
CArray<float, float> DataPtTable;
unsigned char variable3;
};
type1 myArray[5];
Now if I call myArray[2].DataPtTable.Add() or SetSize() , how is the memory allocated? I know it does get reallocated, but does that make calls to members of myArray[2].DataPtTable invalid since it is now pointing somewhere else? Or will it begin to overwrite into memory allocated for variable3, etc?
Thanks.
|
|
|
|
|
Are performing some operations like
type1 stMystruct1;<br />
type1 stMystruct2 = stMystruct1;
?
|
|
|
|
|
The array object remains valid. The memory allocations and reallocations are
internal to the CArray class. That's the whole idea - so you don't have to
worry about it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So the way I am using CArray is correct?
Then the app crashing must be something else. Dam, back to square one.
|
|
|
|
|
acerunner316 wrote: So the way I am using CArray is correct?
From what you've posted, yes.
I can't see the stuff in angle brackets though...
struct type1
{
unsigned char variable1;
unsigned char variable2;
CArray<float, float=""><span style="color: Red;"><???></span> DataPtTable;
unsigned char variable3;
};
type1 myArray[5];</float,>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have two CArray objects.
One is <WORD, WORD>
Other is <float, float>
I know there isn't a problem with that part of the declaration.
|
|
|
|
|
In that case, looks like there's a problem elsewhere.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Where does the programm crash? Use the debugger and write us some previous lines with the point of your failure.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hello,
I have a tab control, contents of which are displayed by a CDialog. This dialog contains different controls on it. I am having following issues :-
1) After I run my app, if I put another window on top of it (say calc.exe) and switch back to my app, I see the area convered by calc.exe is erased!
2) I have a menu which pops up if I do a right control on the header of my Clistctrl .. after the menu goes away, the area covered by the menu is erased and comes back only when I move my mouse over the area...
3) If I hit enter the contents on the tab control (which are displayed by CDialog) go away completely!
Thank you in advance for your help...
|
|
|
|
|
Hello,
You can try to use this message,
BEGIN_MESSAGE_MAP(CButtonDlg, CDialog)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL CDialog::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnEraseBkgnd(pDC);
}
This member function is called to erase the background when any changes happens in window like resize or move.
I guess i will work.... Try this.... Good Luck...
Thanks and Regards.
SANTHOSH V
|
|
|
|