Backstory:
I took up learning C/C++ a couple months ago when I was in a game hacking forum. Since then I have changed my interests and no longer desire to make exploits for games for personal reasons.

At the moment I am studying
Programming Windows 5th Edition by: Charles Petzold

It is a very good book, I am almost 700 Pages In and I understand it completely.

What concerns me is that it was made I estimate around 11 Years ago.

Q1: Should I continue studying this even though it could be a bit outdated?

I am also currently using Visual Studio 2010 Beta2 and I see that there are any different ways to make an application ie. MFC - WFA
Which I have no idea how to use ( WFA ) but I've seen similar apps uses from a friend who uses VB.

Q2: What is the best most up to date method to code in C\C++ so that I don't end up left behind on anything ( and why ).

My current study is of
http://en.wikibooks.org/wiki/Programming:Windows_Programming
Which I found recommended and will look into to see if it will answer some of my questions since my range in computer knowledge itself is very short.

Q3: The most I have made that even resembles any kind of use is a simple console app that converts files into a C Byte Array. Why am I not able to make anything useful will my knowledge of C\C++.
Example app I made for a friend to send text to a minimized notepad

#include <Windows.h>
    #include <iostream>
    #include <conio.h>

    using namespace std;

    #define ClearScreen() system( "CLS" )

    class _Notepad
    {
    public:
    _Notepad()
    {
    ZeroMemory( &Buffer, sizeof( Buffer ) );
    pt.x = 1;
    pt.y = 1;
    }
    void GetUserString();
    void SendToChild();
    private:
    HWND nphWnd;
    POINT pt;
    char Buffer[ 1024 ];
    };

    void _Notepad::GetUserString()
    {
    while( 1 )
    {
    ClearScreen();

    printf( "Enter the string to put into notepad\n: " );
    cin.getline( Buffer, sizeof( Buffer ) );

    if ( !( nphWnd = FindWindow( "Notepad", NULL ) ) )
    {
    printf( "\nPlease turn on notepad..." );
    Sleep( 3000 );
    continue;
    }

    if ( strlen( Buffer ) )
    break;

    cout << "\nYou have entered a empty reply, please try again..." << endl;
    Sleep( 3000 );
    }
    SendToChild();
    }

    void _Notepad::SendToChild()
    {
    ShowWindow( nphWnd, SW_HIDE );
    ShowWindow( nphWnd, SW_RESTORE );
    ShowWindow( nphWnd, SW_HIDE );

    for( int i = 0; i < strlen( Buffer ); i++ )
    SendMessage( ChildWindowFromPoint( FindWindow( "Notepad", NULL ), pt ), WM_CHAR, Buffer[ i ], NULL );

    ShowWindow ( nphWnd, SW_SHOWMINIMIZED );
    ClearScreen();
    }

    void main()
    {
    _Notepad np;

    np.GetUserString();

    printf( "Complete..."    );
    getch();
    }

It is fairly simply but doesn't do much of anything.

Whenever I try to learn more about dealing and using pointers ( for classes, functions, data ) I always manage to find a way to screw up ( crashes, invalid ) or insufficient knowledge leading me to not use them unless absolutely required by a Windows function.

Q4: What can I do to properly learn and use pointers/memory since previous studies have left me stranded.


I have some other questions but not to go into thread overloading or details, I'll just end it here.

I would appreciate some full reply's with recommendations, wisdom, and advice to better further my interest and skill.

Recommended Answers

All 6 Replies

>Q1: Should I continue studying this even though it could be a bit outdated?
Yes, the Win32 API is still relevant. But be sure to use MSDN to keep yourself up-to-date on the latest additions, because as you said, that book is somewhat old.

>Q2: What is the best most up to date method to code in C\C++
>so that I don't end up left behind on anything ( and why ).

You'll get left behind. That's the nature of the beast, I'm afraid. Just pick things you need or are interested in and keep up-to-date there, then refresh yourself as necessary for everything else.

>Q3: The most I have made that even resembles any kind of use is
>a simple console app that converts files into a C Byte Array. Why
>am I not able to make anything useful will my knowledge of C\C++.

Programming is hard. Knowledge only takes you so far, which means you need to practice and get more experience applying that knowledge.

>Q4: What can I do to properly learn and use pointers/memory
>since previous studies have left me stranded.

This is a difficult question to answer. Can you be more specific?

Well for an example of pointers, I tried to make a simple macro for recording and replaying mouse movement and actions.
I have made one before but this time I wanted to make it so that the
size of the recording array is dynamic depending on the time it takes them to finish their recording.

struct _Mouse
{
public:
int x, y;
}*Mouse;

if ( Still recording )
Mouse = Alloc_One_More_Array();

The problem I had was that the allocated address was dynamic so it would mean that I would need to copy all the memory from the old pointer into a new pointer with the 1 extra space.

Doubling the amount of memory I would need to use for it.

And predefining the amount to record can be irritating to the user.

I also ended up with a lot of garbage and crashes.

Allocate a large temporary chunk of memory when recording starts. If you need more space, allocate another temporary chunk -- not one at a time -- to save time. Keep track of your chunks.
When you stop recording, Allocate one more chunk just large enough to hold the entire recording and move the recording into it, deallocate the temporary memory.

This can be more elegant, but it should get you started. Also, look into reallocate commands. They may help, too.

You could also use the standard template library containers like vector, deque, list, etc. These are very handy, and vectors almost match arrays for performance. They are much harder to break (though still very possible), and can save you a lot of heart ache. If you want a simple solution, and a dynamically sized container, these are the way to go:

http://www.cplusplus.com/reference/stl/

Also, for my own two cents, I would drop MFC like a hot rock and learn up on WPF. To really keep up to speed on Windows programming, you should embrace the .NET framework. I would say, your old text still has a mountain of valuable knowledge, but you should supplement it with something up-to-date.

I would drop MFC like a hot rock and learn up on WPF

A caveat to that is in order to access the managed libraries one must code in C++/CLI which is in some cases more similar in syntax to C# and yet has its own syntactic quirks like handles.
The current express edition (and I think the standard edition) has WinForms capability and a designer but I don't believe either edition has a WPF designer for C++ (so you can't take advantage of the XAML). I checked on the 2010 version and it doesn't seem to have it either.
And so my font of knowledge has run dry. ;) Executing a net search on any of the keywords should get you lots more information.
Dusktreader's advice is sound and looking towards the future is the best idea. The moral of the story is look into what baggage a particular technology brings along with it.

Thank you for the reply's ^_^

Allocate a large temporary chunk of memory when recording starts. If you need more space, allocate another temporary chunk -- not one at a time -- to save time. Keep track of your chunks.
When you stop recording, Allocate one more chunk just large enough to hold the entire recording and move the recording into it, deallocate the temporary memory.

This can be more elegant, but it should get you started. Also, look into reallocate commands. They may help, too.

Is there not a more efficient way than making chunks?

you should embrace the .NET framework

From what I have read, the .Net framework is a set of libaries and files that hold functions and information so that in order for anyone to use your program, all they would have to do is install that version of the framework.

Also that it is more secure, but that is as far as my knowledge on what .Net is goes.

Edit:
I see a lot of threads of requesting information or help ( such as mine ), but what if I wanted to release something ( interesting small app w/ source ) for others to examine ie. Code Snippets Index
Where and how would I go about doing this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.