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

Finding Machine IDs

$
0
0
Is there a way I can extract Machine / Hardware ID and OS Version using VC++?

quick answer pls

$
0
0
My program works, but when I run the program again it and type new input. The screen also prints the input from the previous iteration.

Code:

  #include <iostream>
#include <string>
using namespace std;
int main ()
{
        string ans;
string uno;
string dos;
string tres;
int length ;

do {
cout << "Enter random words" << endl;
getline (cin , uno);

cout <<"Type your name"<<endl;
getline (cin , dos);

length = uno.length()-1;

for (int i=length; i >= 0; i--)
{  tres+=uno.at(i);
}

tres.insert(tres.size() / 2, dos);
       
cout<<tres<<endl;

cin.clear();
system ("cls");

cout <<"Would you like to run this program again(yes/no)"<<endl;
cin>>ans;
}while (ans=="yes");

cin.clear();
system ("pause");
return 0;
}

How to delete records in .txt file

$
0
0
So i get the concept of how to do this but i'm just not doing it right.
I have to ask the user if they want to delete any records. The user can enter -1 to finish deleting records. I have to write the remaining records in an output file.

SO i have this, but 1) it doesn't let me enter more than 1 id, and 2 it doesnt output anything to my output.txt.
Help please? What am I doing wrong?

records.txt
6
123 Jose Garcia 99
345 Luis Garcia 87
234 Jazlyn Soriano 79
456 Carter Sander 95
567 Natalia Soto 67
789 Isabel Santana 80

Code:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;

class Student
{
private:
        int id;
        string firstName;
        string lastName;
        int examGrade;
public:
        Student();
        Student(int, string, string, int);
        void setall(int, string, string, int);
};

int main()
{
        fstream gradebook;
        fstream temp;
        gradebook.open("C://Users//Esmeralda//Desktop//Records.txt",ios::in);
        temp.open("C://Users//Esmeralda//Desktop//Output.txt",ios::out);
        if (gradebook.fail())
                {
                        cout << "Error opening file" << endl;
                        exit(0);
                }

        int size;
        gradebook >> size;

        Student *records;
        records = new Student[size];
        int id;
        string firstName;
        string lastName;       
        int examGrade;
        int remove;
        string line;

        for (int i=0; i<size;i++)
        {
                gradebook >> id >> firstName >> lastName >> examGrade;
                records[i]=Student(id, firstName, lastName, examGrade);
                cout << id << "\t" <<  firstName << "\t" << lastName << "\t" <<  examGrade << endl;
        }
       
        cout << "Please enter the ID of the student to be deleted." << endl << "To exit, please type -1." << endl;
        cin >> remove;
        while (getline(gradebook,line))
                {
                        if (remove == id)
                        {
                                temp << remove << endl;
                                size--;                       
                        }
                        else
                                exit(0);
                }
        gradebook.close();
        temp.close();

        delete [] records;
        system("pause");
        return 0;
}
Student::Student()
{
        id= 0;
        firstName=" ";
        lastName=" ";
        examGrade=0;
}
Student::Student(int theId, string theFirstName, string theLastName, int theGrade)
{
        setall(theId, theFirstName, theLastName, theGrade);
}
void Student::setall(int theId, string theFirstName, string theLastName, int theGrade)
{
        if(theId>999 || theId<100)
                exit(1);
        else
                id=theId;

        firstName = theFirstName;

        lastName = theLastName;

        if(theGrade>101 || theGrade<0)
                exit(1);
        else
                examGrade=theGrade;
}

Trouble getting C++ program to print list using Iterator and Operator Overloading

$
0
0
Hello All, First time here. I was hoping you could help me with my program. I'm trying to use the given Iterators to overload my = operator to print my list to screen. I keep getting Link2019 errer though and have narrowed the problem down to my print operator. I'm wondering if it has anything to do with the fact that my operator is in private part of class? I'm new to this concept.

Code:

#include    "List.h"

// methods for Node all
//ME

Node::Node( const string &s, Node * p, Node * z) : word( s ), next( p ), prev(z)                //constructor
{
    word = s;              // init. word data with a copy of s
    next = p;              // next pointer points to p
        prev = z;                                //prev pointer points to z
}

const string &Node::get_word( ) const        // get a const reference to word
{
    return word;                                                //returns curent objects data
}
 
Node *Node::get_next( ) const        // get a Node * (value of next)
{
        return next;                                //returns current objects pointer to next
}

                           
Node *Node::set_next( Node * p )        // set next to a new value
{
    next = p;              // next points to p
    return next;
}

Node *Node::get_prev( ) const        // get a Node * (value of next)
{
        return prev;                                //returns current objects pointer to next
}

Node *Node::set_prev( Node * z )        // get a Node * (value of next)
{
        prev = z;
        return prev;                                //returns current objects pointer to next
}




//****************************************************************************8
// methods for List


List::List( )              // constructor: init. head and tail
{
    cout << "List::List( )\n";

    head = tail = 0;
}


List::List( const List &rhs )        //Copy Constructor
{
        copy_list( rhs );
}


List::~List( )              // destructor: deallocate the list
{
    cout << "List::~List( )\n";
        delete_list( );
}


void List::copy_list( const List &rhs )                //Given
{
    head = tail = 0;
                            // copy rhs' list into this
    for( Node *p = rhs.head; p; p = p->get_next( ) )
    {
        push_back( p->get_word( ) );
    }
}


void List::push_back( const string &s )
{
                            // p points to a new node
    Node *p = new Node( s, 0, tail );

    if( tail == 0 )        // tail not pointing to a node yet?
    {
        head = tail = p;    // head & tail point to new node in the list
    }
    else
    {                      // tail->next points to new node
        tail->set_next( p );
        tail = p;          // tail points to last node in the list
    }
}


void List::pop_back( )
{
        if( tail )                                // tail points to a node?
        {
                Node *tmp = tail;
                tail      = tail->get_prev( );

                delete tmp;                        // delete node to be removed

                if( tail == 0 )                // no more elements in the list?
                {
                        head = 0;
                }
                else
                {
                        tail->set_next( 0 );
                }
        }
}

// other methods for List...

void List::delete_list( )        //ME
{

    for( Node *p = head; p; )
    {
        Node *tmp = p;      // remember current pointer
        p = p->get_next( ); // advance p to the next Node
        delete tmp;        // deallocate tmp
        cout << "Deleted\t" << tmp << "\tnext is\t" << p << '\n';
    }
}

void List::push_front( const string &s )        //ME
{
Node *p = new Node(s,0,head);

    if( head == 0 )        // head not pointing to a node yet?
    {
        head = tail = p;    // head & tail point to new node in the list
    }
    else
    {                      // head->next points to new node
               
                p -> set_next(head);
                head = p;

    }
}

void List::pop_front( )                //ME
{
 Node* temp; 
    if(head == NULL) 
    { 
        cout<<"\nLinked list is empty"; 
        return; 
    } 
    if(head->get_next() == NULL)      //to check if only one node is present 
    { 
        temp = head; 
        head = NULL; 
        //cout<<"\nDeleted node: "<<temp->data; 
        free(temp); 
      } 
    else            //If more than one nodes are present 
    { 
        temp = head; 
        head = head->get_next(); 
        //cout<<"\nDeleted node: "<<temp->data; 
        free(temp); 
      } 
}

List::Iterator List::begin( ) const        // beginning of a linked list ME
{
    return List::Iterator( head );
}

List::Iterator List::end( ) const        // end of a linked list ME
{
    return List::Iterator( NULL );
}




// methods for Iterator
                            // constructor: init. an Iterator
List::Iterator::Iterator( Node *p )
{
    current = p;   
       
}

                            // get a const ref to word
const string &List::Iterator::operator *( ) const
{
    return current->get_word( );
}

                            // get a const ref to word
void List::Iterator::operator ++( )
{
    if( current )
    {
        current = current->get_next( );
    }
}

                            // current != p
bool List::Iterator::operator !=( const Iterator &iter ) const
{
    return current != iter.current;
}

List &List::operator =( const List &s )
{
        List::Iterator iter;

    for( iter = s.begin( ); iter != s.end( ); ++iter )
    {
        cout << "List *iter = " << *iter << "\n";
    }
        return  (*this);
       
}

Here is my header file, I'm not allowed to change it though.

Code:

#include    <iostream>
#include    <iomanip>
#include    <string>
using namespace std;


class Node
{
  public:
    Node( const string &, Node *, Node * );

    const string &get_word( ) const;// get a const reference to word
    Node  *get_next( ) const;      // get a Node * (value of next)
    Node  *set_next( Node * );    // set next to a new value
    Node  *get_prev( ) const;      // get a Node * (value of prev)
    Node  *set_prev( Node * );    // set prev to a new value

  private:
    string  word;
    Node    *next;
    Node    *prev;
};


class List
{
  public:
    List( );                        // constructor
    List( const List & );          // copy constructor
    ~List( );                      // destructor
                                    // push a node to the back of list
    void push_back( const string & );
                                    // push a node to the front of list
    void push_front( const string & );
                                    // pop  a node from the back  of list
    void pop_back( );
                                    // pop  a node from the front of list
    void pop_front( );

    class Iterator
    {
      public:
        Iterator( Node * = 0 );               
        const string &operator *( ) const;
        void operator ++( );
        bool operator !=( const Iterator & ) const;

      private:
        Node *current;
    };

    Iterator begin( ) const;        // pointer to beginning of the list
    Iterator end( )  const;        // pointer to end      of the list

  private:

    Node    *head;
    Node    *tail;

    void copy_list( const List &  );// copy a linked list
    void delete_list( );            // delete a linked list
                                    // do NOT allow copy assign. operator
    List &operator =( const List & );
};

And finally my main, something else I can't change. I commented everything out except cout statement.
Code:

#include    "List.h"

// implement operator <<( ) using Iterators
ostream &operator <<( ostream &, const List & );


int main( )
{
    List la;                    // create list la
       
        la.push_front( "mom" );
    la.push_back( "please" );
    la.push_back( "send" );
    la.push_back( "money" );
    la.push_front( "hi" );
       
    cout << "\nla contains:\n" << la << '\n';
        /*
    List lb( la );              // copy list la to lb
        /*
    cout << "lb contains:\n" << lb << '\n';
       
    lb.pop_front( );
    lb.pop_front( );
    lb.push_front( "mother" );
    lb.push_front( "dear" );
    lb.push_back( "Bubba" );
        /*
    cout << "lb contains:\n" << lb << '\n';
        /*
    List lc;                    // create list lc
    lc.push_back( "money" );
    lc.push_front( "send" );

    cout << "\nlc contains:\n" << lc << '\n';

    List ld;                    // create list ld
    cout << "\nld contains nothing:\n" << ld << '\n';

    ld.push_front( "hi" );
    cout << "ld contains:\n" << ld << '\n';

    ld.pop_front( );
    cout << "ld contains nothing:\n" << ld << '\n';

    ld.push_back( "hello" );
    ld.push_back( "Bubba" );
    cout << "ld contains:\n" << ld << '\n';

    ld.pop_front( );
    cout << "ld contains:\n" << ld << '\n';

    ld.pop_front( );
    cout << "ld contains nothing:\n" << ld << '\n';

    List le( ld );
    cout << "le contains nothing:\n" << le << '\n';

    le.push_back( "last" );
    cout << "le contains:\n" << le << '\n';
        */
        system("pause");
    return 0;
}

decrypt exe file maked in Visual C++

$
0
0
Hi!
i have an executable that is encrypted; it is made in Visual C++.
Can someone to help me to decrypt it? what i must to look for?
I have some kind of files (.req extention) that have the content encoded by password type.
thanks!

LCT File To BMP Image

$
0
0
Hi,

I have an *.lct file. I like to read *.lct file and save an bmp image.

I can not read this file using usual file read.

Code:

void CLCTtoBMPDlg::OnBnClickedReadlctfile()
{
        CFileException CFileEx;
        CStdioFile ReadFile;
        CString OpenlctfilePath;
        TCHAR szFilters[]= _T("LCT Files (*.lct)");
 
        CFileDialog fileDlg(TRUE, _T("bmp"), _T("*.lct"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
   
  fileDlg.m_ofn.lpstrTitle = _T("lct Files");
  fileDlg.m_pOFN->lpstrInitialDir=_T("D:\\"); 

  if(fileDlg.DoModal() == IDOK)
  {
      OpenlctfilePath = fileDlg.GetPathName();
          MessageBox(OpenImageFilePath);
         
          CFileException CfileEx;       
          CStdioFile ReadFile;                   
          if(!ReadFile.Open(OpenlctfilePath, CFile::modeNoTruncate | CFile::modeRead, &CfileEx))
          {
                CFileEx.ReportError();
                MessageBox(_T("Setting File Was Not Found"));
                return ;
          }

                TRY
                {
                        CString sLine;
                        int iLineCount = 0;
                                       
                        while(ReadFile.ReadString(sLine))
                        {                       
                                ::AfxMessageBox(sLine);                                       
                        }                               
                        ReadFile.Close();
                }
                CATCH (CFileException, e)
                {
                        AfxMessageBox(_T("File could not be opened %d"),e->m_cause);
                        return ;
                }
                END_CATCH 
        }
}

Find the attachment. change the file extension *.lct instead of *.txt. I like to read ASCII Data into Hex,
Example : Data "A" as "41" (Refer the jpeg image). How is possible?
Attached Images
 
Attached Files

Help with a really simple program

$
0
0
This is what i need(I made a short video):
http://screencast.com/t/UsPjDW4Y




Code:

#pragma once

namespace FirewareEvolution {

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

        /// <summary>
        /// Summary for Form1
        /// </summary>
        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
                Form1(void)
                {
                        InitializeComponent();
                        //
                        //TODO: Add the constructor code here
                        //
                }

        protected:
                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                ~Form1()
                {
                        if (components)
                        {
                                delete components;
                        }
                }
        private: System::Windows::Forms::Label^  label1;
        protected:
        private: System::Windows::Forms::Label^  label2;
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Button^  button2;
        private: System::Windows::Forms::Label^  label3;
        private: System::Windows::Forms::TextBox^  textBox1;
        private: System::Windows::Forms::TextBox^  textBox2;
        private: System::Windows::Forms::TextBox^  textBox3;
        private: System::Windows::Forms::TextBox^  textBox4;
        private: System::Windows::Forms::TextBox^  textBox5;









        protected:






        private:
                /// <summary>
                /// Required designer variable.
                /// </summary>
                System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                void InitializeComponent(void)
                {
                        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
                        this->label1 = (gcnew System::Windows::Forms::Label());
                        this->label2 = (gcnew System::Windows::Forms::Label());
                        this->button1 = (gcnew System::Windows::Forms::Button());
                        this->button2 = (gcnew System::Windows::Forms::Button());
                        this->label3 = (gcnew System::Windows::Forms::Label());
                        this->textBox1 = (gcnew System::Windows::Forms::TextBox());
                        this->textBox2 = (gcnew System::Windows::Forms::TextBox());
                        this->textBox3 = (gcnew System::Windows::Forms::TextBox());
                        this->textBox4 = (gcnew System::Windows::Forms::TextBox());
                        this->textBox5 = (gcnew System::Windows::Forms::TextBox());
                        this->SuspendLayout();
                        //
                        // label1
                        //
                        this->label1->AutoSize = true;
                        this->label1->Location = System::Drawing::Point(691, 89);
                        this->label1->Name = L"label1";
                        this->label1->Size = System::Drawing::Size(53, 13);
                        this->label1->TabIndex = 0;
                        this->label1->Text = L"Decryptor";
                        //
                        // label2
                        //
                        this->label2->AutoSize = true;
                        this->label2->Location = System::Drawing::Point(335, 16);
                        this->label2->Name = L"label2";
                        this->label2->Size = System::Drawing::Size(87, 13);
                        this->label2->TabIndex = 1;
                        this->label2->Text = L"Translation Code";
                        //
                        // button1
                        //
                        this->button1->Location = System::Drawing::Point(167, 84);
                        this->button1->Name = L"button1";
                        this->button1->Size = System::Drawing::Size(75, 23);
                        this->button1->TabIndex = 2;
                        this->button1->Text = L"Encrypt";
                        this->button1->UseVisualStyleBackColor = true;
                        //
                        // button2
                        //
                        this->button2->Location = System::Drawing::Point(511, 84);
                        this->button2->Name = L"button2";
                        this->button2->Size = System::Drawing::Size(75, 23);
                        this->button2->TabIndex = 3;
                        this->button2->Text = L"Decrypt";
                        this->button2->UseVisualStyleBackColor = true;
                        //
                        // label3
                        //
                        this->label3->AutoSize = true;
                        this->label3->Location = System::Drawing::Point(12, 89);
                        this->label3->Name = L"label3";
                        this->label3->Size = System::Drawing::Size(52, 13);
                        this->label3->TabIndex = 4;
                        this->label3->Text = L"Encryptor";
                        //
                        // textBox1
                        //
                        this->textBox1->Location = System::Drawing::Point(12, 241);
                        this->textBox1->MaxLength = 400;
                        this->textBox1->Multiline = true;
                        this->textBox1->Name = L"textBox1";
                        this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
                        this->textBox1->Size = System::Drawing::Size(266, 130);
                        this->textBox1->TabIndex = 5;
                        //
                        // textBox2
                        //
                        this->textBox2->Location = System::Drawing::Point(478, 241);
                        this->textBox2->MaxLength = 400;
                        this->textBox2->Multiline = true;
                        this->textBox2->Name = L"textBox2";
                        this->textBox2->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
                        this->textBox2->Size = System::Drawing::Size(266, 130);
                        this->textBox2->TabIndex = 6;
                        //
                        // textBox3
                        //
                        this->textBox3->Location = System::Drawing::Point(278, 32);
                        this->textBox3->MaxLength = 25;
                        this->textBox3->Name = L"textBox3";
                        this->textBox3->Size = System::Drawing::Size(200, 20);
                        this->textBox3->TabIndex = 7;
                        this->textBox3->UseSystemPasswordChar = true;
                        //
                        // textBox4
                        //
                        this->textBox4->Location = System::Drawing::Point(12, 113);
                        this->textBox4->MaxLength = 400;
                        this->textBox4->Multiline = true;
                        this->textBox4->Name = L"textBox4";
                        this->textBox4->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
                        this->textBox4->Size = System::Drawing::Size(266, 122);
                        this->textBox4->TabIndex = 8;
                        //
                        // textBox5
                        //
                        this->textBox5->Location = System::Drawing::Point(478, 113);
                        this->textBox5->MaxLength = 400;
                        this->textBox5->Multiline = true;
                        this->textBox5->Name = L"textBox5";
                        this->textBox5->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
                        this->textBox5->Size = System::Drawing::Size(266, 122);
                        this->textBox5->TabIndex = 9;
                        this->textBox5->TextChanged += gcnew System::EventHandler(this, &Form1::textBox5_TextChanged);
                        //
                        // Form1
                        //
                        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                        this->ClientSize = System::Drawing::Size(756, 383);
                        this->Controls->Add(this->textBox5);
                        this->Controls->Add(this->textBox4);
                        this->Controls->Add(this->textBox3);
                        this->Controls->Add(this->textBox2);
                        this->Controls->Add(this->textBox1);
                        this->Controls->Add(this->label3);
                        this->Controls->Add(this->button2);
                        this->Controls->Add(this->button1);
                        this->Controls->Add(this->label2);
                        this->Controls->Add(this->label1);
                        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
                        this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
                        this->MaximizeBox = false;
                        this->Name = L"Form1";
                        this->Text = L"Fireware";
                        this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
                        this->ResumeLayout(false);
                        this->PerformLayout();

                }
#pragma endregion
        private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                        }
private: System::Void textBox5_TextChanged(System::Object^  sender, System::EventArgs^  e) {
                }
};
}

Help C programming Homework

$
0
0
Name:  1416415196073.jpg
Views: 114
Size:  42.7 KB please help my homework i just little understand about my homework
Create a C program that read two sentence

1.For the second sentence, calculate how many
a.Alphabet
b.digits
c.hexadigit
2.Reverse the first sentence with converting its character
a.From lower to upper
B.From upper to lower
3.Print string that consist of ten character from the first sentence and 8 character from the second sentence
Attached Images
 

static class member in multithreaded environment

$
0
0
HI Guys,
I have a class having static member.I have get and set methods which will Get and Set Values to this variable. In a multithreaded application does it have any thread safety issues.

Class a
{

static int b;

void Set (int c);
int Get();
};

help with classes pls

$
0
0
Can someone send me a tutorial where I can learn about classes, objects and constructors?
The professor will talk about about these topics this upcoming week but I just want to learn this now :)
In this hw I'm only allowed to write in the class section only I can't touch the main.
Any help will be appreaciated! thanks
Code:

#include <iostream>
#include <string>
using namespace std;

class Animals
{
};

  int main()
  {
          string type, a1;

          cout << "\nwhat's your favorite animal #1? ";
          getline(cin, type);
          cout << "Why do you like that animal? (ENTER for none): ";
          getline(cin, a1);
          Animals f1(type, a1);

          cout << "\nwhat's your favorite animal #2? ";
          getline(cin, type);
          cout << "Why do you like that animal? (ENTER for none): ";
          getline(cin, a1;
          Animals f2(type, a1);

          cout << "\nwhat's your favorite animal #3? ";
          getline(cin, type);
          cout << "Why do you like that animal? (ENTER for none): ";
          getline(cin, a1);
          Animals f3(type, a1);

          cout << "\nwhat'bts your favorite animal #4? ";
          getline(cin, type);
          cout << "Why do you like that animal?(ENTER for none): ";
          getline(cin, a1);
          Animals f4(type, a1);

         

          cout << "\nData 1:" << endl;
          f1.showInfo();
          cout << "\nData 2:" << endl;
          f2.showInfo();
          cout << "\nData 3:" << endl;
          f3.showInfo();
          cout << "\nData 4:" << endl;
          f4.showInfo();
         
          system ("pause");
        return 0;
}

Getting Free Disk Space of certain directory

$
0
0
Code:

_int64 free_space_64bit;
PULARGE_INTEGER lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes;
//char currentPath[MAX_PATH];
//GetCurrentDirectoryA(MAX_PATH, currentPath);
GetDiskFreeSpaceExA("H:\\C", lpFreeBytesAvailable, lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
free_space_64bit = lpFreeBytesAvailable->HighPart << 32 | lpFreeBytesAvailable->LowPart;

This directory "H:\\C" does exist, if I comment out the GetDiskFreeSpaceExA line, the program doesn't crash, but it leads to some peculiar results (some uninitialized and random value, but at least it doesn't crash)
Any ideas?
Thanks
Jack

How to tell if Windows partition is active?

$
0
0
My goal is to know if Windows is installed on an active disk partition. Any ideas?

Dbstatus_e_cantcreate

$
0
0
Please go through the following code. I am using OLEDB Cunsumer Templates.
I am getting DBSTATUS_E_CANTCREATE for the status of picture field.

Looks like OLEDB Provider is incapable of giving 2 ISequentialStream Objetcs.
Then What is the solution?

ALso tell me whether OLEDB Cunsumer Templates relaiable?Some times it corrupts my
Database itself.

I am trying Categories table from Northwind database from mdb file.
using VS2008,Windows7 64 bit
///////////////////////////////////////////////////////////////////////



class CXCategoriesAccessor
{
public:
LONG m_CategoryID; // Number automatically assigned to a new category.
TCHAR m_CategoryName[16]; // Name of food category.
ISequentialStream* m_Description;//Description Memo
ISequentialStream* m_Picture; // A picture representing the food category.
DBSTATUS m_dwCategoryIDStatus;
DBSTATUS m_dwCategoryNameStatus;
DBSTATUS m_dwDescriptionStatus;
DBSTATUS m_dwPictureStatus;
DBLENGTH m_dwCategoryIDLength;
DBLENGTH m_dwCategoryNameLength;
DBLENGTH m_dwDescriptionLength;
DBLENGTH m_dwPictureLength;
void GetRowsetProperties(CDBPropSet* pPropSet)
{
pPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
pPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
pPropSet->AddProperty(DBPROP_ISequentialStream, true);
pPropSet->AddProperty(DBPROP_IRowsetChange, true, DBPROPOPTIONS_OPTIONAL);
pPropSet->AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
}
public:
BEGIN_ACCESSOR_MAP(CXCategoriesAccessor,3)
BEGIN_ACCESSOR(0,true)
COLUMN_ENTRY_LENGTH_STATUS(1, m_CategoryID, m_dwCategoryIDLength, m_dwCategoryIDStatus)
COLUMN_ENTRY_LENGTH_STATUS(2, m_CategoryName, m_dwCategoryNameLength, m_dwCategoryNameStatus)
END_ACCESSOR()
BEGIN_ACCESSOR(1,true)
BLOB_ENTRY_LENGTH_STATUS(3, IID_ISequentialStream, STGM_READ, m_Description, m_dwDescriptionLength, m_dwDescriptionStatus)
END_ACCESSOR()
BEGIN_ACCESSOR(2,true)
BLOB_ENTRY_LENGTH_STATUS(4, IID_ISequentialStream, STGM_READ, m_Picture, m_dwPictureLength, m_dwPictureStatus)
END_ACCESSOR()
END_ACCESSOR_MAP()

};

//////////////////////////////////////
HRESULT hr = S_OK;
CDataSource ds;
ds.OpenFromInitializationString(L"My Connection String");
CSession sn;
hr = sn.Open(ds);
CDBPropSet propset(DBPROPSET_ROWSET);
CTable<CAccessor<CXCategoriesAccessor> > table;
table.GetRowsetProperties(&propset);
hr = table.Open(sn,L"Categories",&propset);
hr = table.MoveFirst();//hr = DB_E_ERRORSOCCURED, m_dwPictureStatus = DBSTATUS_E_CANTCREATE
ATLTRACE(table.m_CategoryName);
ATLTRACE(L"\n");
table.Close();
sn.Close();
ds.Close();

C++ circular buffer

$
0
0
I'm having some issues with my code. For the produce function i am getting an error saying 'no instance of overload function produce() matches the argument list' and also for the lines buffer[head].data = message; buffer[head].time = current_time i get an error saying 'expression must have pointer to object type.

In the code i'm not sure if i passed the variabes to the function correctly. I'm new to C++ and trying to learn as much as i can. I have attached the code

Any help would be appreciated.

Kind Regards

code produce.txt
Attached Files

Class of String Collections

$
0
0
Is it legal in VC++ to create a class composed only of string colections. If it is how can I create it in VC++ and add it to my project? It has great value if it can be done

Change text and bkg color of CComboBox

$
0
0
I have a derived CComboBox class, where I tried to change text and background of edit from CComboBox, just like this:
Code:

HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
        HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);

        // TODO: Change any attributes of the DC here

//        if(CTLCOLOR_EDIT == nCtlColor || CTLCOLOR_MSGBOX == nCtlColor)
        {
                pDC->SetTextColor(RGB(255, 255, 0));
                pDC->SetBkColor(RGB(255, 0, 0));
                pDC->SetBkMode(TRANSPARENT);
                hbr = m_hBrush;
        }

        // TODO: Return a different brush if the default is not desired
        return hbr;
}

but is not working if CComboBox has CBS_DROPDOWNLIST style ... is working only for CBS_DROPDOWN style ... why ?
I attached a test app ...

WinInet, accesing HTTPS server with optional certificate

$
0
0
I'm trying to use WinInet (via the MFC wrappers) to read pages off a HTTPS server that is set to accept but not require certificates. It either authorizes via a certificate or uses basic user/password authentication. I'm trying to get that basic authentication to work.

The CHttpFile::SendRequest() (::HttpSendRequest() raw api) fails and returns error 12044 ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED

So apparentely the server expects a certificate even though I don't want to use one. Supposedly I can solve this by retrying the request, but this doesn't help, the retry still fails.

- I have done HTTPS before, though on a server that didn't handle certificates
- I do not have a certificate to return, none is installed in the certificate store that would make much sense to the server.

So either there's a setting somewhere that I'm not finding that instructs WinInet to tell the server that it shouldn't use or expect a certificate but use the basic authentication instead
Or I somehow need to craft a "dummy" yet valid certificate the server will find adequate to fall back to basic authentication.

The server is accessible with cURL and with a simple C# app (neither of which use WinInet). But I need this in C++ with WinInet.

Help: Release build hangs during linking

$
0
0
It compiles fine but hangs during linking. The last message I got is

Code generation.

Sometime when I cancel it, I got

LNK1257 code generation failed

Can anyone advise on what can be possible reasons and how to diagnose?

Thanks,

CR

How long is your build?

$
0
0
Developers are spending more and more time of their days compiling.
How long is your build?

Code works only on computer, when it was compiled

$
0
0
Hello.
For some reason this code dont work on other computers, but work on computer, where it was compiled. Any idea why?
Code:

#include <windows.h>
 

 

 
int WINAPI DllThread()

{
        for (;;)

        {
                HMODULE hModule = NULL;
                while (!hModule)


                {
                        hModule = LoadLibraryA("scripter.dll");
                        Sleep(100);
                }
               

                if (GetAsyncKeyState(VK_INSERT))
                {
                        hModule = LoadLibraryA("Proxy.dll");
                        return 0;
                }


        }

        }


BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
                CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)DllThread, NULL, NULL, NULL);
                break;
        case DLL_THREAD_ATTACH:
                break;
        case DLL_THREAD_DETACH:
                break;
        case DLL_PROCESS_DETACH:
                break;
        }
        return TRUE;
}

Viewing all 3017 articles
Browse latest View live