|
You are not allocating memory on the heap for the object. The memory you are trying to use is in the local stack defined for the block you are in for that function call. Either dynamically allocate memory for the array, or better, define your char array on the call side, and pass it in to the formatForPrinting call. BTW, why aren't you using CString - it handles all that for you?
|
|
|
|
|
I tried:
char* ret = new char[32];
i presume this is what you mean by dynamically allocating memory.... This results in a load of junk in the array elements which arent used, presuambly because its not initialised. Although it does pass the right thing back as well.
Is it the done thing to allocate the memory on the call side then? I guess thats a better way of doing things..
I might start using CStrings. I have tried to avoid them so I wont have any problems if I go to another platofrm (arent CString just VC++).... I also thought in the long run it might be better if I had the increased control, do you disagree with this?? Im begining to think its more trouble than its worth...
Thanks for your help
Ben
|
|
|
|
|
Well, if you don't like the garbage in it, you can always fix that with ZeroMemory, or memset. As to the your other concern, I think that if you want to do all of your own string type operations without help from MFC, you would be well advised to either, preferably, use the STL string class, or, cook up your own well defined string class. Not wanting to be enslaved to MFC is understandable, but you should be sure that you really need to go to the extra effort of not making it dependent on MFC. Otherwise, you are just makeing extra work for yourself for no good reason.
|
|
|
|
|
If portability is a concern, then use std::string from the STL.
But I think that's just avoiding the issue, which is you just don't understand pointers and memory management yet. (That's not a knock on you; it is a tough subject.) Eventually, if you program C/C++, you will have to use them and understand them.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
Hello, the codegurus around the world.;)
I guess that one mistake is
char* b;
b = game->formatForPrinting()
should be
string.h
.....
int len = strlen (game->formatForPrinting);
char *b = new char[len + 1];
strcpy (b, game->formatForPrinting);
However, I didn't check this at my code, so...
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi all,
I want to know what is best way to appending text in last of editbox ?
m_Edit1.GetWindowText(pString, 50);
strcpy(pAll, pString);
m_Edit1.SetWindowText(pAll);
do you have better idea ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hello, the codegurus around the world.;)
CString sBaseString, sNewString(" This is the text appended!");
m_Edit1.GetWindowText(sBaseString);
sBaseString += sNewString;
m_Edit1.SetWindowText(sBaseString);
or
UpdateData(FALSE);
sBaseString = m_strEdit1;
sBaseString += sNewString;
m_strEdit1 = sBaseString;
UpdateData(TRUE);
However, I didn't check this at my code, so...
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi,
can you write it by using of LPSTR instead CString ?
Thanks ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hello, the codegurus around the world.;)
I will give you some references.
WINUSERAPI
int
WINAPI
GetWindowTextA(
HWND hWnd,
LPSTR lpString,
int nMaxCount);
WINUSERAPI
int
WINAPI
GetWindowTextW(
HWND hWnd,
LPWSTR lpString,
int nMaxCount);
#ifdef UNICODE
#define GetWindowText GetWindowTextW
#else
#define GetWindowText GetWindowTextA
#endif // !UNICODE
<br>
typedef LPSTR LPTCH, PTCH;
typedef LPSTR PTSTR, LPTSTR;
typedef LPCSTR LPCTSTR;
typedef CHAR *LPSTR, *PSTR;
Other hint is to search "Data type" of Platform SDK: Win32 API of MSDN help.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
How can i monitor the time that the connection is taking, meaning that if i have opened a connection to the net and i want to timelimit it lets say for 5 minu. how can i do it?
thanks,
|
|
|
|
|
kick off a timer and kill the connection when it expires?
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Hello, the codegurus around the world.;)
Lauren:
How do we kill the connection of Internet?
DUN, LAN, Cable Modem, xDSL, Wireless DSL?
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
How can i catch the event of click "Enter" Button when the focus is on the ComboBox.
When i click now the "Enter" button the "OK" button is catching the event.
|
|
|
|
|
The most straight forward way is to just modify your dialog's OnOK handler to check if your ComboBox has the focus. If it does, just drop out of the OnOK without doing the EndDialog call.
|
|
|
|
|
This is not correct because when i do that the focus is always on the Dialog window even if the focus was on the combo.
|
|
|
|
|
How are you trying to determine the focus window?
|
|
|
|
|
With the funciton GetFocus()...
|
|
|
|
|
Sorry, I forgot how wacky the combo box is. I beleive the problem is that the CComboBox itself does not have the focus, the edit portion of it does, which is a separate window from the control itself. Thats what you need to be checking the focus for. I forget now how to get a pointer to the edit portion of the combo, but I think if you check around you will find how to get it.
|
|
|
|
|
|
See if this works (it did for me)
void CMyDialog::OnOK()
{
if( GetFocus() == m_Combo.GetDlgItem( 1001 ))
{
// Do combo stuff
return;
}
}
1001 is the id of the CEdit portion of the CComboBox.
|
|
|
|
|
Hello, the codegurus around the world.;)
Which situation do you want to work?
EditBox of ComboBox has the input fouce?
Or List of ComboBox is expaned and some item is selected?
when you push Enter key?
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi there.
I'm trying to put often used functions into a dll. Since my projects make use of mfc I took the mfc-app-wiz. to create the dll. What I got was a class-body (not quite what I'd had in the Petzold years ago
I added a test-method to that class and compiled the dll. Adding it's .lib and header-file to a project got a linker error however (unresolved external) (I created an instance of the dll-class and called the test-method)
So the question is: how do I use mfc-app-wiz generated dlls in my projects?
Any help would be greatly appreciated.
Steffen
|
|
|
|
|
If my guess is right, you are adding the test method to the CMFCDLLAppWizCreatedApp class - this class is not exported, so the method won't be available.
Here's a simple class decl you could add where all the methods are exported:
class _declspec(dllexport) CTest {
public:
CTest();
virtual ~CTest();
};
Then, the bummer is that when you use the header in the consumer app you must use _declspec(dllimport) in the declaration instead. VC/MFC uses macros to get around this, switching on whether _AFXDLL is defined in the build (which you'll probably look at next).
You don't have to export the whole class, so you might want to use _declspec(dllexport) on your existing test method to um... test.
There's all manner of ins and outs to this, depending on the nature of your DLL. In the Petzold 16 bit world, you would have used a .DEF file with an EXPORTS section. This is not necessary in 32 bit, although it is still usefull if you want to do things like hide the functions from the dependency viewer etc.
HTH
|
|
|
|
|
As I saw/heard a lot of stuff on overriding WM_ERASEBKGRND and get OnEraseBkgnd to return FALSE to avoid flickering, I did that. The trouble is, What do you do if there comes a time when you actually want to Erase background upon OnDraw? Particularly if blitting is done with transparency, there would be a problem unless the client is first erased. Once OnEraseBkgnd is coded to return FALSE, it seems that calls like InvalidateRect(NULL,TRUE) won't erase background either.
Is there a general solution for this?
On a different note, how do can I keep receiving WM_MOUSEMOVE message in main frame even if cursor is hovering above something else, like toolbar or dialog box? Or even outside window frame?
Thank you.
|
|
|
|
|
if you want to avoid flickering use a double-buffer for your screen updates ... ie, draw to one off-screen buffer and blit to the screen when finished ... then draw the next frame to another off-screen buffer and blit that ... repeat as necessary
for the mouse stuff you can use SetCapture(...) and EndCapture(...)
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|