|
Roger Stoltz wrote: A Trim function is expected to trim the object it contains, not returning a trimmed copy of the original object
I am tring to build 'String' class something similar as in C#, in that it doesn't Trim the object itself ! So what should I follow?
Can you help me to create 'String', because I am getting problem in Copy Constructor & Destructor while returning 'String' object in member function.
Should I show you 'String' class? According to your time, check where I am going wrong in 'String' class. OR else just suggest me any book/link so design a proper class.
Thanks for your Help.
|
|
|
|
|
Aniket Salunkhe wrote: Can you help me to create 'String'
Sorry, but my answer is 'no' for two reasons:
1. There are existing string classes like CString from the MFC library and std::string from the STL library that are well known and robust. If you need a string class you should use one of those.
2. If you're writing this string class in order to teach yourself then, in my opinion, the best way to learn something new is by trying it out as in "learning by doing". You will make mistakes that will become valuable experiences to you.
Don't get me wrong, of course you can ask questions to this forum, but you should have a better idea of what you want to do than simply "I want to write a string class, how do I do that". Think about how you want your string class to function and what every member function should do.
Have a look at another string class here[^]. Download the source code and try to figure out how each function works and why it works that way. It might get you some ideas of what to do and perhaps what not to do.
Post questions if you don't understand, but think about it first; if you appear lazy you won't get any answers. Don't continue this thread because the question you first asked has been covered. Start a new thread with a specific problem if you have one.
You will also benefit from others that visit CodeProject more frequently than I do.
Regarding your problems with the copy constructor and the destructor they should look something like below depending on how you treat terminating zeros and such.
String::String( const String& SrcString )
{
if( SrcString.m_string )
{
m_string = new char[SrcString.m_length];
m_length = SrcString.m_length;
memcpy( m_string, SrcString.m_string, m_length );
}
else
{
m_string = NULL;
m_length = 0;
}
}
String::~String()
{
delete [] m_string;
m_string = NULL;
m_length = 0;
} Hope this helps
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Hi,
I have to write a VC++ code which should support to send Fax to the user. Could you please let me know any APIs are available to reuse.
Thanks a lot.
Regards,
Janarthan
|
|
|
|
|
Will you please enter a display name into your profile!
|
|
|
|
|
that's boring the number of anonymous posts we're getting these days
|
|
|
|
|
|
Until the DirectX forum is up and running I guess this is the best place to ask.
I'm creating a 2D scene using Dirct3D9, for the most part I have not had many problems. Triangles, Squares and rectangles are easy to draw, but what about circles? What I am looking for is a method to draw a 2D circle which fades ( alpha blends ) towards the edges.
Any ideas?
|
|
|
|
|
|
Thanks for the link, but the article is for a very outdated version of DirectX.
I actually created my own solution, and it was very simple. I used a TriangleFan arranged in such a way that it creates something like a pie chart. This made my other problem of creating a fade effect even easier to solve.
|
|
|
|
|
Hi all,
I am currently trying to get our application working on Vista. We currently build a dynamic pdf file and attach it to a Outlook message through Simple Mapi. This has worked until now. When I call MapiLogin, it returns an error code of 1924235005. This number changes each time it is run, but it is about the same. This is followed by the error message from Outlook, "An error occurred while attempting to open the Windows Address Book. Unable to find the WAB.DLL MAPI 1.0 [00000220]". This only occurs with Outlook 2000. More recent versions of Outlook do work.
Has anyone else run into this?
Any help would be greatly appreciated.
Thanks in advance.
Greg
|
|
|
|
|
Hi,
I have an Atl Component with an Interface EFCMyForm .(ATL Simple Object -- VS2005)
And a Dialog class CMydialog with ActiveX controls Placed on it. using right Click on Dialog and Insert ActiveX Control
In One of thw Exposed Method I am creating the dialog box CMyDialog
CMydialog g_myDlg;
STDMETHODIMP CEFCMyForm::Create()
{
#ifdef _AFXDLL
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif
g_myDlg.Create(IDD_MY_DLG);
} using CDialog:: Create().
If I take a Global variable I don't have any problem but if I take mydialog obj as member variable as shown below...
CMydialog m_myDlg;
STDMETHODIMP CEFCMyForm::Create()
{
#ifdef _AFXDLL
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif
m_myDlg.Create(IDD_MY_DLG);
} using CDialog:: Create().
then the ActiveX Controls which are placed on the Dialog are not being Shown.
To resolve this If I try to Dyanamically create the ActiveX controls in
CMyDialog::OninitDialog()
{
-----Using Create Control------
CLSID clsid;
HRESULT hr1 = CLSIDFromProgID(OLESTR("EsdGraphCtrl.EsdGraphControl.3.0"),&clsid) ;
if (FAILED(hr1))
{
return FALSE;
}
BOOL blnSuccess;
CRect rc;
rc.left=0;
rc.top=0;
rc.right= 100;
rc.bottom =100;
blnSuccess = m_AxGraphControl.CreateControl(clsid,_T("Graph"),WS_VISIBLE|WS_CHILD,rc,this,100,0,0,0);
if (!blnSuccess)
{
return FALSE;
}
}
Any Suggestions would be helpful
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
hi there genius!!!
I´m actualy programming a routine which needs to detect if the ethernet interface in my system is up or down.
To be more specific; what i exactly need is to know if exist some way to listen to ethernet port and ALERT ME when a ethernet cable/wire is pluged in the PC.
I will be a happy man if u can help me in any of these questions?!
THANX IN ADVANCE
MARCOS!!!
|
|
|
|
|
Have you tried the ISensNetwork interface?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am very much stuck in an urgent assignment and in need of help as i have committed a Excel like Grid to a client.
My requirement is to have a Grid just like Excel and to take input from user using only Win API and GDI etc (No MFC allowed). I have already created the Grid but the problem is how to show the cursor in the rectangular boxes in grid and to take input form user?
One option is to use 'Text Box' control already provided in WinAPI but the problem is that its width would be fixed and only a part of text written in it is viewable to user depending on its width.
What i want is the input functionality just like MS Excel in which the input text is automatically extended to next cell when it exceeds the limit of a cell.
I would really appreciate if any one can provide me with the source code of such a control or could help me out in this difficult task?
Thanks and Regards,
Zeeshan Malik
zeemalik78@yahoo.com
To do what can be done is Intelligence and To do what should be done is Genious
|
|
|
|
|
It's relatively simple to use the caret APIs and catch keystroke messages for simple text
input. Maybe you have some of the code already to use arrow keys to navigate the grid.
Here's an example of a modal text edit loop (with probably more keys checked than you need for
single-line editing). The CaretUp()/CaretDown()/CaretLeft()/CaretRight()/MoveCaret() set the
caret position based on a row/column and the font size (fixed pitch fonts make this easy):
MSG LoopMsg;
bool fRedraw = false;
bool fEditing = true;
while (fEditing)
{
if (::PeekMessage(&LoopMsg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&LoopMsg);
::DispatchMessage(&LoopMsg);
if (LoopMsg.message == WM_LBUTTONDOWN)
{
}
if (WM_KEYDOWN == LoopMsg.message)
{
switch (LoopMsg.wParam)
{
case VK_RETURN:
fEditing = false;
break;
case VK_HOME:
MoveCaret(view, 0, nCurRow);
break;
case VK_END:
MoveCaret(view, nCharColumns, nCurRow);
break;
case VK_PRIOR:
MoveCaret(view, nCurColumn, 0);
break;
case VK_NEXT:
MoveCaret(view, nCurColumn, nCharRows - 1);
break;
case VK_LEFT:
CaretLeft(view);
break;
case VK_RIGHT:
CaretRight(view);
break;
case VK_UP:
CaretUp(view);
break;
case VK_DOWN:
CaretDown(view);
break;
case VK_DELETE:
DeleteChar();
fRedraw = true;
break;
case VK_BACK:
if (nInsertOffset > 0)
{
CaretLeft(view);
DeleteChar();
fRedraw = true;
}
break;
}
}
else if (WM_CHAR == LoopMsg.message)
{
switch (LoopMsg.wParam)
{
case 0x08:
break;
case 0x09:
break;
case 0x0D:
break;
case 0x0A:
break;
case 0x1B:
fEditing = false;
break;
default:
InsertChar((TCHAR)LoopMsg.wParam);
fRedraw = true;
break;
}
}
else if (WM_SETFOCUS == LoopMsg.message)
{
::MessageBeep(-1);
}
else if (WM_KILLFOCUS == LoopMsg.message)
{
fEditing = false;
}
if (fRedraw)
{
fRedraw = false;
HideCaret(view);
ShowCaret(view);
}
}
}
|
|
|
|
|
Hi for all
I'm trying to pass some data between 2 windows. This is the class that I pass between my 2 windows. It's just a single class with a based pointer:
<br />
<br />
#ifndef TESTE_H<br />
#define TESTE_H <br />
#include <windows.h> <br />
void * vValue; <br />
class Teste <br />
{ <br />
public: <br />
Teste(); <br />
~Teste(); <br />
void SetMsg(char * cMsg);<br />
void ExibeMsg(); <br />
Teste __based(vValue) * Single;<br />
private: <br />
char * m_cMsg;<br />
char * m_cClassName;<br />
}; <br />
Teste::Teste()<br />
{<br />
if(m_cClassName == 0)m_cClassName = "Classe Teste";<br />
}<br />
Teste::~Teste(){}<br />
void Teste::SetMsg(char * cMsg)<br />
{<br />
m_cMsg = cMsg;<br />
}<br />
void Teste::ExibeMsg()<br />
{<br />
if(m_cMsg != NULL)MessageBox(NULL, m_cMsg, "msg", MB_OK);}<br />
#endif TESTE_H<br />
This is the code that sends the data and handles the data:
<br />
<br />
case WM_COPYDATA:<br />
{<br />
COPYDATASTRUCT * dataReceived = (COPYDATASTRUCT*)lParam; <br />
Teste * tempTeste = (Teste*)dataReceived->lpData; <br />
Teste * ttt = tempTeste->Single; <br />
char cResult[256] = {0}; <br />
int nCount = 0; <br />
if(ttt != NULL)<br />
{<br />
MessageBox(NULL, "exibindo msg janela 1", "", MB_OK); <br />
ttt->ExibeMsg();<br />
}<br />
break;<br />
}<br />
<br />
case WM_COMMAND:<br />
{ <br />
switch(LOWORD(wParam))<br />
{<br />
case IDC_BUTTON1:<br />
{<br />
char cLength[20], cSize[5]; <br />
if(HIWORD(wParam) == BN_CLICKED)<br />
{<br />
if(GetDlgItemText(hwnd, IDC_EDIT1, cLength, 20) != 0)<br />
{<br />
Teste teste1; <br />
teste1.SetMsg("aaa");<br />
vValue = (void*)&teste1;<br />
COPYDATASTRUCT dataToSend;<br />
dataToSend.cbData= sizeof(void*);<br />
dataToSend.lpData = vValue;<br />
dataToSend.dwData = 0;<br />
HWND tempHwnd = FindWindow(NULL, "Janela 2");<br />
if(tempHwnd != NULL)<br />
{<br />
SendMessage(tempHwnd, WM_COPYDATA, wParam, (LPARAM)&dataToSend);<br />
}<br />
}<br />
else<br />
{<br />
MessageBox(NULL, "EditBox with no text", "info", MB_OK);<br />
}<br />
}<br />
break;<br />
}<br />
}<br />
break;<br />
}<br />
The problem is, when I call the ExibeMsg() func with my object in the WM_COPYDATA message, the application crashes. What I'm doing wrong? Anyone can suggest me a solution?
Thanks for help
|
|
|
|
|
The Memory that you point to, is only valid in the function because it goes out of scope. It is better with static memory or allocated with GlobalAlloc.
Attention: I think with most above written you 'may' run into trouble on the new MS Windows Vista.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: allocated with GlobalAlloc
why don't you just new it ?
|
|
|
|
|
if it is in the same app/process it is OK, but he didnt say that.
In the same app I would use a global (memory) object.
Greetings from Germany
|
|
|
|
|
but GlobalAlloc() is not portable...
|
|
|
|
|
In a site(www.flounder.com), I read this:
"The problem of storing pointers is a little bit misleading. You must not store pointers in the structure you pass, even if they are pointers into the same area you are passing, because when the message is received the recipient has no control over where it is placed, and the pointers are likely to be nonsense. Obviously, you can't store pointers to other areas of your own memory because they will be completely nonsensical in the receiving process; they will be interpreted in its own address space.
But the misleading aspect is that if you have a structure which is entirely self-contained in the data area you are sending over (that is, every pointer refers to another structure in the area you are sending), then you can use based pointers to encode them. Based pointers are actually relative offsets measured from a specific starting point (such as the start of the area being transmitted), and are automatically adjusted by the recipient (as long as you set up the correct base value) so they are valid pointers."
So I have a based pointer in my class that is the same type of the class. This pointer must have to arrive(I think) to the other window safetly.
toxcct, if I use new I lose the control over the pointer in the other window.
|
|
|
|
|
Try use GlobalAlloc()/GlobalFree, but check/test it on Vista. Read the MSDN.
Greetings from Germany
|
|
|
|
|
What about GlobalAlloc()/GlobalFree changed on Vista? I see nothing in the PSDK.
Mark
|
|
|
|
|
Alex Cutovoi wrote: Teste __based(vValue) * Single;
So what address is 4 bytes from vValue ? Unless it is the beginning of ExibeMsg() , there's no way that the following could work:
ttt->ExibeMsg();
What you're doing seems very unreliable and dangerous. What is the receivng window supposed to do with the data it receives?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The code that I put in my question is the same for both windows. It doesn't change. If the way I choose is unreliable and dangerous, what you suggest for me to solve this??
I need a big help
|
|
|
|