196 Topics
I've created: #include <streambuf> #include <iostream> #include <windows.h> template<typename T> class BufferedStream : T { private: T &stream; std::streambuf* buffer; //planning to use this to create other "IO" functions. public: BufferedStream(T &stream) : stream(stream), buffer(stream.rdbuf()) {} ~BufferedStream() {stream.rdbuf(this->buffer);}; std::ostream& operator << (const char* data); std::ostream& operator << (const std::string &data); … | |
I have the following code for 2D dimensional arrays being flattened as 1D C-style arrays: #include <iostream> int main() { int width = 4, height = 10; int arr[width * height]; for (int i = 0, k = 0; i < height; ++i) { for (int j = 0; j … | |
Creating WinAPI windows and controls can be a pain and quite difficult/annoying at times. Most of the time, I find myself searching MSDN, DaniWeb, and StackOverflow. I hate having to use external libraries unless I absolutely have no other choice. Below contains code for creating WinAPI windows, Controls, Sub-Classing, and … | |
Why is accessing data in an uninitialised array undefined behaviour? I ask because I was doing some benchmarking on `vector<int>` vs. `int*` vs. `int**`. My results were: http://stackoverflow.com/questions/20863478/class-using-stdvector-allocation-slower-than-pointer-allocation-by-a-lot Now I'm being told if I use the raw array and try to access an index without initialising it first, it is … | |
In the two for loops below, I want the checksum variable to hold the same value for both even though one loop starts at row 12 and another at row 0. Any ideas how I can combine these loops so that I don't have to iterate the same buffer twice? … | |
Should I be using std::wstring or std::string and wchar_t or char? All this unicode stuff is confusing me. I want my application to work on both windows and linux without too many problems and changes but I'm considering unicode vs. ansi. Any ideas? I ask because I see many applications … | |
I want to use it because it says it supports all the C++11 features and I'm hoping that includes Regex as well since gcc isn't near finishing anytime soon.. However, many other websites are saying that clang requires Mingw/gcc to be used in the first place. It doesn't make any … | |
template<typename T> void Transpose(T** Data, std::size_t Size) { for (int I = 0; I < Size; ++I) { for (int J = 0; J < I; ++J) { std::swap(Data[I][J], Data[J][I]); } } } int main() { int A[4][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, … | |
I have roughly 500 function pointers defined in a header like so for example: void (__stdcall *ptr_glAccum) (GLenum op, GLfloat value); void (__stdcall *ptr_glActiveTextureARB) (GLenum texture); void (__stdcall *ptr_glAlphaFunc) (GLenum func, GLclampf ref); GLboolean (__stdcall *ptr_glAreTexturesResident) (GLsizei n, const GLuint *textures, GLboolean *residences); void (__stdcall *ptr_glArrayElement) (GLint index); void (__stdcall … | |
I'm trying to write a cout formatter that uses the comma operator and insertion operator. I wasn't able to get that to work so I decided to write it similar to std::boolalpha. when you use `std::boolalpha`, it is able to change 0 values to true and false and you can … | |
I wrote a large project dealing with images, files, and WINAPI functions. I decided to add RichTextEdit to it and used the msfedit.dll.. Turns out that it only supports UNICODE style strings and chars and my entire project is std::strings and LPCSTR's, etc.. None of the WINAPI functions are unicode … | |
Assuming a simple class like below and the main like below, will the class variable be stack/heap allocated depending on how the class is instantiated? OR will the class variable be allocated depending on how it is implemented? class Foo { private: std::string Bar; public: Foo() : Bar(std::string()) {} }; … | |
How can I install gcc 4.7.2 for codeblocks that supports both 32 and 64 compilation? If I install the x32 bit compiler: x32-4.7.2-release-win32-sjlj-rev10 it will compile with -m32 compiler switch but give a bunch of linker errors for -m64 If I install the x64 bit compiler: x64-4.7.2-release-win32-sjlj-rev10 it will compile … | |
I have a class called Control. All other "controls" inherit from this class. Some controls need a default constructor so that I can assign or construct them later. The classes look like: class Control { private: //All Members Here.. void Swap(Control &C); public: Control(DWORD dwExStyle, std::string Class, std::string Title, ....); … | |
Why do I need a static class member? What are the advantages and disadvantages of it? Is there any way that I can have non-static member fuction without doing anything outside of the class (such as passing an instance)? class Control { private: HMENU ID; HWND Handle, Parent; std::string Class, … | |
http://i.imgur.com/kWrBizl.png In the above Image, I generator a Sudoku Matrix of 9x9 values. Is there any way I can allow user to enter individual values by moving around the caret and typing? Basically, I want them to just be able to change the values displayed on the screen by moving … | |
How can I calculate CLOCKS_PER_SEC.. It is defined as 1000 in ctime. I don't want it defined. I want to calculate the actual value.. I tried the below code but it seems to be giving me my CPU speed.. on a 2.8 Ghz processor, it prints 2800. On a 2.0 … | |
Can C++11's Mutexes be used for Inter-Process Communication? In other words, can it be used for shared memory and signalling an event? Currently, I'm using CreateEvent and SetEvent from WINAPI and I wanted a cross-platform way of doing so without doing #ifdef windows and ifdef linux, etc.. I use CreateEvent … | |
I'm diving into various Image reading and writing methods and writing my own. I decided to tackle TGA/Targa. I got reading working flawlessly. It reads both compressed and decompressed .TGA files. I got writing decompressed .TGA files working. However, I cannot figure out how to write Compressed .TGA files. I … | |
Why can't I capture the variable Painted and change it? The second that I capture it, it throws a compile time error: > *cannot convert 'Foo()::<lambda(HWND, uint32_t, WPARAM, LPARAM)>' > > to > > 'WNDPROC {aka long long int (*)(HWND__*, unsigned int, long long unsigned int, long long int)}' in … | |
Why can't I capture the variable Painted and change it? The second that I capture it, it throws a compile time error: > *cannot convert 'Foo()::<lambda(HWND, uint32_t, WPARAM, LPARAM)>' > > to > > 'WNDPROC {aka long long int (*)(HWND__*, unsigned int, long long unsigned int, long long int)}' in … | |
This may be a long post but I really need to know how to Convert between the two image formats and amonst themselves as well. Here goes: I have a struct like the one below that holds all pixel information: typedef union RGB { uint32_t Color; struct { unsigned char … | |
I'm in a bit of a dilemma. I want to know what the difference is between Foo and Meh. I wrote both of them and I did not like Foo so I wrote Meh. They both work but is there an overhead to Meh? Is there anything bad about Meh? … | |
Ok I know the difference between delete and delete[] BUT this question just all of a sudden popped in my head since "NOTHING" happens when I use delete[] for all purposes. Now I know when to use one or the other but it still for some odd reason bothers me … | |
I'm trying to flip an image which has its pixels stored in a vector. For some reason, when I try to flip it, the image gets distorted and gray/fuzzy. Any idea why? My code is as follows: void JNIData::FlipBytes(void*& Result, bool TopDown) { unsigned char* Pixels = &BufferPixels[0]; //vector of … | |
I have a void pointer that I casted to a char*. I'm trying to put different data types in that char* without having to cast so much. This includes doubles, floats, int's, etc.. char* Data = static_cast<char*>(GivenPtr); switch(reinterpret_cast<int>(Data)[0]) //Or should it be reinterpret_cast<int>(Data[0]) { case OBJECT: //defined as 301; { … | |
Does anyone have a tutorial for writing Custom Allocators and Memory Pools for std::vectors and Objects? Basically I've looked at placement new and I want to know how I can force vectors to use this with my shared memory pointers. I'm thinking writing a class for it might be much … | |
I had absolutely no clue where to post this but I figured since it crashes on the C++ side, I'd ask here. I have the following code: Java side (Loads My C++ DLL just fine.. Passes it a ByteBuffer so that I can write to that): import java.io.IOException; import java.awt.*; … | |
How can I figure out where words intersect in the following? AAAA#BBBB .#.##C##H .#.##D##I .#...E.#J ##.##F##K ###..G..L '#' represents the black spots in a crossword where you cannot fill in. '.' represents the spots with missing letters that need to be filled in. I've read the puzzle into a vector<string> … | |
What am I doing wrong? In the following templated functions, I'm trying to convert all my CopyMemory functions to std::copy functions. I'm not sure what I'm doing wrong as they don't work as they should with the std::copy but instead, they work with memcpy and CopyMemory. I'm only doing it … | |
Why is C++ on linux basically C? I've tried everything to avoid C on linux but it's simply near impossible. I've tried to stick directly to the standard library but I somehow find myself using dirent.h, types.h, etc.. Is there any other ways to do these other than using C … | |
I'm learning several languages. 5 at once but I took a liking to one specific feature of java. The This keyword. From their tutorial: /*Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You … | |
Is there a way to do the following better? Current I write a set of pixels to a file called "PngFile.bmp". Then I read that file back in as a PNG encoded buffer.. Then I save that buffer back to the harddisk and delete "PngFile.bmp" /*std::fstream PngFile(TempPath, std::fstream::out | std::fstream::app … | |
So I've started learning makefiles today for a project I've been working on. The project uses OpenGL and GDI. I decided to dive right into make files and so far, everything compiles but at the very end, it gives a bunch of undefined references. Thing is, when compiled in codeblocks, … | |
I've been trying to do this for some time. I can do it with a vector but with a const void*, it crashes badly! My bad code: Bitmaps::Bitmaps(const void* Pointer, int Width, int Height, uint32_t BitsPerPixel) { Pixels.clear(); memset(&Info, 0, sizeof(BITMAPINFO)); width = Width; height = Height; size = ((width … | |
How can I get a DLL's Parent Window Title? OR How can I get the PID of the process that loaded my DLL? I need this so I can make a file for each process that loads my DLL but the file has to contain some sort of identifier. Something … | |
Hello everyone. I have a problem with my checksum and logic. I wrote a program that downloads and read bitmaps and try to generate a checksum for each one. The checksum is used as the name to save the bitmap as so that I don't save the same bitmap every … | |
Why does my checksum not work? I use it on my computer with ATI graphics and it works perfectly fine. When I switch to a computer with Intel graphics, it starts doing random values and they aren't the same. I switch back to my comp, the values are still the … | |
I keep getting "None of the 6 overloads could convert all arguments". I only get this problem in visual studio though. When I compile with g++ or codeblocks, it works perfectly fine. The code I'm calling my templates with is: `MemDeSerialize(ListOfItems, SerializedData, size_t(Data[2]));` The definitions: template<typename T> void MemDeSerialize(T& Destination, … | |
What are some safe sized datatypes? Inother words, stuff like size_t, uint32_t. They don't seem to change no matter what machine I use. I'm asking because the confusion comes in here: I'm not sure when to use long vs int. I did a sizeof(int) and sizeof(long) and they are both … | |
I currently use this to serialize data, write it to shared memory so that another program can reconstruct it and use it: template<typename T> void Serialize(unsigned char* &Destination, const T &Source) { CopyMemory(Destination, &Source, sizeof(T)); //Destination += sizeof(T); //Not sure if to add this or not. } template<typename T> void … | |
Hey guys, I have two structs and I have two functions in two DLL's. DLL-A is attached to a process and collects data. When the data is requested by DLLB which is attached to a second process, DLLA maps the data for B to read. The problem is, I cannot … | |
I just started shared memory and I took a big dive into it and got stuck trying to figure out how to share pointers. Well not really pointers: void* pData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, MapSize); Ok so the above holds my view of the file to be shared between … | |
Hey all. I'm having a problem with a DLL being loaded. In codeblocks, if I don't export Main + ALL the functions in my DLL, they cannot be used by an external program! Yet in visual studio, I exported nothing and external programs are able to load the DLL. Example: … | |
How can I iterate a buffer with a stride? For example, I saved the pointer to a vertex buffer for later use. I've got the stride, the pointer, and triangle count for vertices. I want to iterate my pointer using this info to get the vertices. I'm doing it wrong … | |
What are the last 4 values for? (m[0], m[4], m[8], m[12]) (m[1], m[5], m[9], m[13]) (m[2], m[6], m[10], m[14]) (m[3], m[7], m[11], m[15]) I've looked everywhere and cannot figure out what m[3], m[7], m[11], m[16] are for (ModelView Matrix).. It says to ignore them but I can't just ignore them … | |
How can I reverse a GLTranslate. Example: if glTranslate is called before rendering text to the screen, how can I figure out the position of that text if glTranslate weren't used? The text is rendered to the screen like this: glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, 7681) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, 34168) glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, 768) glColor4ub(0, … | |
How can I compare Dimensional arrays using iterators? My attempt is below but I gave up and used indexing instead. I plan to change comparing doubles with == to use epsilon later. Also should I be using vector of vectors? //In my class, Data is defined as std::vector<std::vector<double>> Data; bool … | |
In OpenGL, I'm reading about glVertexPointer which has a parameter: `const void* pointer` and it is a pointer to the coordinates of the first vertex. Thing is, it doesn't have any parameters that tell you the amount of vertices there are. I'm wondering if there is a way to copy … | |
I'm trying to generate Unique ID's for a buffer unless they contain the same content. Inother words if the buffer has the same content as another, the ID should be the same; otherwise different. I've found someone using this algorithm for the same kind of buffer: DWORD CalcChecksum(DWORD *pData, int … |
The End.