|
Hy, since most of you have probably been programming in MFC for a very long time, I was wondering if you could give me some tips on how to improve my programming skills in C++. Thanks
Alessandra
|
|
|
|
|
first tip :
MFC != C++
second tip :
initialize all variables.
third tip :
check that all pointers are valid before using them.
...
|
|
|
|
|
Maximilien wrote: check that all pointers are valid before using them.
I'm of the opinion that that is a bad idea. For example, consider code that follows the following pattern throughout:
if (p)
{
p->SomeFunction();
}
Many people (most people, in fact) get into the habit of doing this even when it is a bug for p to be NULL. Assuming p should never be NULL the extra check turns a crash at the point of the problem into some obscure problem later down the track as the function SomeFunction was never called. I’ve seen this many, many times. A better approach is as follows:
assert(p);
p->SomeFunction();
In a debug build we assert and in a release build you get a crash dump (because naturally everyone collects crash dumps from MS…) which points you at the problem.
As for IsBadReadPointer and friends, see here[^].
Steve
|
|
|
|
|
I did not offer anything else than "check the pointers" either you use asserts, if or some exceptions, you need to do it anyway.
Stephen Hewitt wrote: As for IsBadReadPointer and friends, see here[^].
I never use or used those functions.
|
|
|
|
|
Alessandra77 wrote: ...tips on how to improve my programming skills in C++
Fourth tip:
live it, breathe it, love it.
|
|
|
|
|
fifth tip:
go get a break (and use that time to buy a book)
|
|
|
|
|
Maybe you think its not necessary but always provide comments for your code ,use of become names for variables,your program must check exception
|
|
|
|
|
Thanks to you all!
Alessandra
|
|
|
|
|
You're welcome
|
|
|
|
|
Hello,
I think if I have an object of CDatabase class,to which if a proper connection string is given then it enables me to access a database from a server whose OS is windows xp.
But if the OS is Unix or linux then what changes I have to bring about in my program written in VC++ for windows.
I have a different OS only on the server .
Will the code wriiten on the server using CSocket class work ?
Where am I going wrong.Which topics should I cover?
Thanks
Prithaa
|
|
|
|
|
it doesn't matter what OS runs on the remote dataabase server because Sockets are made to communicate through IP protocol so fully independant of the implementation
|
|
|
|
|
Hello,
Thanks
Which topics should I cover to understand databases and remote access of data
Prithaa
|
|
|
|
|
I am a new poster, and a long time reader... that sounds so familiar... and cheesy.
Anyhow, I am experiencing some strange errors while compiling my application for 64 bit, and have tried google without much luck.
One of the more consfusing problems I am running into is with the following line that compiles fine in 32 bit, but not 64 bit, and am looking for advice or direction (even a smack in the head - if its obvious).
Here is the line, and the compile error, as well as the definition of the function being called...
definitions
WINMMAPI MMRESULT WINAPI timeSetEvent( IN UINT uDelay, IN UINT uResolution,<br />
IN LPTIMECALLBACK fptc, IN DWORD_PTR dwUser, IN UINT fuEvent);<br />
void TSstringSocket::SelectTimer(UINT wTimerID, UINT msg, ULONG_PTR dwUser, DWORD dw1, DWORD dw2) {<br />
...<br />
}<br />
Code
UINT m_timerID;<br />
m_timerID = timeSetEvent( 100, wTimerRes, SelectTimer, (ULONG_PTR)this, TIME_PERIODIC );<br />
Error
Error 162 error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void (__cdecl *)(UINT,UINT,ULONG_PTR,DWORD,DWORD)' to 'LPTIMECALLBACK' c:\Documents and Settings\mikec\Desktop\tix64\Backend\BaseObjects\TSstringSocket.cpp 217 <br />
Any ideas?
Mike Curry
-- modified at 11:17 Tuesday 13th February, 2007
|
|
|
|
|
So what does SelectTimer() look like?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Its very lengthy, but I will post the definition...
void TSstringSocket::SelectTimer(UINT wTimerID, UINT msg, ULONG_PTR dwUser, DWORD dw1, DWORD dw2)
I probably should have posted that earlier, sorry
|
|
|
|
|
Mike Curry - Canada wrote: void TSstringSocket::SelectTimer(UINT wTimerID, UINT msg, ULONG_PTR dwUser, DWORD dw1, DWORD dw2)
Does this match what a LPTIMECALLBACK is?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't think so, however under the 32 bit compile it seems to work without issue.
|
|
|
|
|
i think i'm reading this correctly...
the 4th param on your type declaration, "DWORD_PTR dwUser", that's going to be a 64 bit pointer in x64, but you've apparently defined your function to take a DWORD (which remains 32-bits in x64) ?
|
|
|
|
|
A timecallback is (UINT,UINT,DWORD_PTR,DWORD_PTR,DWORD_PTR)
|
|
|
|
|
I want to retrieve information from secured(requires user name and
password) web service. I can connect it with .NET using
NetworkCredentials class. But when I tried it with C++, I cannot even
send the username and password. I analyze the network activity with
Ethereal, the code doesn't send any authentication information. So the
server send HTTP 401 Authectication error back.
I'm searching web since last friday. I read and tried all I found.
What am i doing wrong?
Thanks for your help.
class CSampleBasicAuth : public CBasicAuthObject, public IAuthInfo
{
public :
void setUserName()
{
username = L"foo";
password = L"bar";
}
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
...
void CWSdenemeDlg::OnBnClickedOk()
{
CString strMessage;
CoInitialize(NULL);
CWebService *ws = new CWebService();
ws->CleanupClient();
CAtlHttpClient &httpClient = ws->m_socket;
CSampleBasicAuth authObject;
authObject.setUserName();
httpClient.AddAuthObj(ATL_HTTP_AUTHTYPE_BASIC, &authObject,
&authObject);
bool val = httpClient.NegotiateAuth(true);
WSInputClass in;
in.member = ...
WSOutputClass* out = new WSOutputClass();
HRESULT hr = (HRESULT) ws->process(in, out);
if(FAILED(hr)){
switch(ws->GetClientError( ))
{
...
case SOAPCLIENT_SEND_ERROR :
strMessage="SOAPCLIENT_SEND_ERROR";
...
}
MessageBox(strMessage);
}
}
|
|
|
|
|
xelontr wrote: HTTP 401 Authectication
hum, are you sure you provide the correct Id + password there ? behaves as if you didn't
|
|
|
|
|
Yes, I send the right id and password. I also tried the web service with the HttpClient demo from Visual Studio. It is not working too. I didn't send any authentication information. I looked the network activity with Ethereal.
With .NET(C#) code I can see the authentication line in Ethereal, but with C++ no authentication line is seen.
Also there is strange thing in .NET. I discovered that the .NET code tries the web service twice(not tries it within code, in code the access to the web service was made once) First it tries without Authentication information, and server gives Authectication error(HTTP 401). Then it tries with Authentication information, and server returns successful message(HTTP 200).
I really doesn't understand anything.
Any idea
|
|
|
|
|
I solved the problem. The code is worked with the following line
httpClient.SetSilentLogonOk(true);
To send the password information out of the intranet SetSilentLogonOK method must be called.
Thanks
|
|
|
|
|
Hi all
I just want to know, what could be more complicated among these two topics..Stega(.JPG AND .MP3) or 3d Game Engine using Visual C++.
I am asking this because i am not that great programmer, i am learning and trying hard to bnecome good programmer but this is one thing which comes with practice.But project comes every yr. So i have to create a final yr project for my uni. Still time is there for about 6 months. So need to know what should be good option for me.
And if its stega then where should i start implementing it. Is there any book with C++ explaing the same or something similar.
Please guide me the right path.
Thanks a lot
|
|
|
|
|
there's an excelent series about steganography written around here by Corinna John[^], but it's in C#, so you'll have to adapt it if you still want it.
see here, in the security section[^] if you want the other articles by Corinna
|
|
|
|