Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
O

o m n i

@o m n i
About
Posts
69
Topics
37
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Comma operator considered harmful
    O o m n i

    From a console tic-tac-toe game: (drawing function)

    for (int x = 0, y = 0; y < 3; y+=((x==2)?1:0),x+=((x==2)?-2:1) ) {
    cout << boardStrings[board[x][y]] << ((x == 2) ? "\n" : "");
    }

    :((

    The Weird and The Wonderful graphics game-dev question

  • Secure enrcyption function
    O o m n i

    Found this great code for encryption in our codebase. All of the client's extremely sensitive information is being stored locally using this.

    string Encryption::EncryptString(string dat) {
    string n = "qwertyuiopasdfghjklzxcvbnm"
    n += n + n + n + n; //keeps the full string from appearing in string table
    for (size_t i = 0; i < dat.size(); i++) {
    dat[i] ^= n[i];
    }
    return dat;
    }

    And it gets even better when you see the decrypt function:

    string Encryption::DecryptString(string dat) {
    return EncryptString(dat); //xor is reversible
    }

    The Weird and The Wonderful security

  • Marshalling a structure to contain an array whose length is an earlier struct member?
    O o m n i

    For loading a file that was originally written by an application written in C++, I have been declaring each part of the file as a struct, and converting the data into a struct using this function:

    public static TStruct GetStruct<TStruct>(byte[] data,Type t)
    where TStruct : new()
    {
    int structSize = Marshal.SizeOf(typeof(TStruct));
    TStruct outstruct = new TStruct();
    GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
    outstruct = (TStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),t);
    handle.Free();
    return outstruct;
    }

    This works fine for structs that do not contain arrays or that contain only arrays that can be defined using fixed (eg fixed int someVariable[10]; works fine) ,but I run into a problem when I want to do this to a struct such as:

    struct Foobar
    {
    int count;
    customStructType someStruct[count];
    }

    I've tried using [MarshalAs(UnmanagedType.<tried all these>, <parameters specified type takes here>)] but it either requires me to specify a fixed number upfront or causes my GetStruct method to give me an error that it "could not meaningfully obtain the size of the struct". LPArray allowed me to specify a particular element in the struct that acts as the number of elements in the array but that gave me the aforementioned lack of meaningful size error. Is there any way to make this work?

    C# help c++ data-structures question

  • Office 2010 style in Windows Ribbon Framework?
    O o m n i

    Is there anyway to create an Office 2010 style ribbon (Aero tabs and Backstage) with Microsoft's Windows Ribbon Framework?

    C / C++ / MFC question

  • Windows Explorer extension
    O o m n i

    Problem is, I can't see any way to put something on the title bar of explorer using this.

    C / C++ / MFC question

  • Windows Explorer extension
    O o m n i

    Is there any built-in interface to allow me to make an extension for explorer that sits in explorer's title bar? If not, what is the best way to hook explorer so I can put something in the titlebar?

    C / C++ / MFC question

  • Need to read big-endian file (Windows)
    O o m n i

    Yes it is just a byte

    C / C++ / MFC help tutorial

  • Need to read big-endian file (Windows)
    O o m n i

    I have a bunch of DXT5 DDS files, but information on the format is so sparse I have no idea how to write something to convert them. I have the following code as part of a library and this converts it to a format I can use, but I can't understand what I need to change to make it read the files as big endian. If anyone could at least explain how the the *src variable is being used so I could determine where I need to convert stuff that would help, I currently don't get how values are being derived from it.

    //-----------------------------------------------------------------------------------------------------
    // DecompressDXT5(vlByte *src, vlByte *dst, vlUInt uiWidth, vlUInt uiHeight)
    //
    // Converts data from the DXT5 to RGBA8888 format. Data is read from *src
    // and written to *dst. Width and height are needed to it knows how much data to process
    //-----------------------------------------------------------------------------------------------------
    vlBool CVTFFile::DecompressDXT5(vlByte *src, vlByte *dst, vlUInt uiWidth, vlUInt uiHeight)
    {
    vlUInt x, y, i, j, k, Select;
    vlByte *Temp;
    Colour565 *color_0, *color_1;
    Colour8888 colours[4], *col;
    vlUInt bitmask, Offset;
    vlByte alphas[8], *alphamask;
    vlUInt bits;

    vlByte nBpp = 4;						// bytes per pixel (4 channels (RGBA))
    vlByte nBpc = 1;						// bytes per channel (1 byte per channel)
    vlUInt iBps = nBpp \* nBpc \* uiWidth;		// bytes per scanline
    
    Temp = src;
    
    for (y = 0; y < uiHeight; y += 4)
    {
    	for (x = 0; x < uiWidth; x += 4)
    	{
    		//if (y >= uiHeight || x >= uiWidth)
    		//		break;
    
    		alphas\[0\] = Temp\[0\];
    		alphas\[1\] = Temp\[1\];
    		alphamask = Temp + 2;
    		Temp += 8;
    		color\_0 = ((Colour565\*)Temp);
    		color\_1 = ((Colour565\*)(Temp+2));
    		bitmask = ((vlUInt\*)Temp)\[1\];
    		Temp += 8;
    
    		colours\[0\].r = color\_0->nRed << 3;
    		colours\[0\].g = color\_0->nGreen << 2;
    		colours\[0\].b = color\_0->nBlue << 3;
    		colours\[0\].a = 0xFF;
    
    		colours\[1\].r = color\_1->nRed << 3;
    		colours\[1\].g = color\_1->nGreen << 2;
    		colours\[1\].b = color\_1->nBlue << 3;
    		colours\[1\].a = 0xFF;
    
    		// Four-color block: derive the other two colors.    
    		// 00 = color\_0, 01 = color\_1, 10 = color\_2, 11 = color\_3
    		// These 2-bit codes correspond to the 2-bit fields 
    		// stored in the 64-bit block.
    		colours\[2\].b = (2 \* colours\[0\].b + colours\[1\].b + 1) / 3;
    		colours\[2\].g = (2 \* colours\[0\].g + colours\[1\].g + 1) / 3;
    		colours\[2\].r = (2 \* colours\[0\].r + c
    
    C / C++ / MFC help tutorial

  • Detect theme?
    O o m n i

    Is there a way to detect what theme someone is using? eg. Windows Classic, Aero, Luna etc

    C# question

  • Planes, Faces, Problems
    O o m n i

    Hey I have problem here, more math related than directly code related. I have a bunch of planes that define a shape, but I need to get the actual faces of the shape (ie. have points where they connect and end rather then extending on forever). I haven't found any math libraries that have functions to do this so I was wondering if I could get some help here. I think I need to find, for each face, where it intersects with other faces, and somehow position a point there, but I'm not really sure, not very good with 3d math.

    C# help

  • Byte Array
    O o m n i

    I have an array of bytes. I need to remove the first 16 bytes of the array, then append another byte array onto it. What do you suggest is the best way to do this?

    C# data-structures question

  • Drawing "on screen"?
    O o m n i

    I'm trying to draw a PNG (with transparency) onto the screen above everything else but finding it difficult as I can only draw on forms and they are limited to a single transparent color... is there any way to draw directly on the screen's device above everything else or to make the window use a mask or something?

    C# graphics question

  • Condense a list
    O o m n i

    Thanks got it working.

    C# question tutorial lounge

  • Condense a list
    O o m n i

    I have a list of a custom type that contains 2 variables. One is name, the other is count. What is the general idea of what I need to do in order to condense this into a list with no duplicates where the counts of duplicate names are added together? (eg. A list with 3 carls, 2 carls, 1 eric, 1 alex and 1 eric should condense to 5 carls, 2 ercis, 1 alex) An example of the class the list would be populated with:

    public class Person
    {
    private string _name;

        public string PersonName
        {
            get {return \_name;}
            set { \_name = value;}
        }
    
        private int \_count;
    
        public int PersonCount
        {
            get { return \_count; }
            set { \_count = value; }
        }
    
        public Person(string name, int count)
        {
            \_count = count;
            \_name = name;
        }
    
    }
    
    C# question tutorial lounge

  • display (render) html in forms
    O o m n i

    The WebBrowser control is the only reasonable way to do it.

    C# csharp html sysadmin question

  • Disable resize cursor when on window border
    O o m n i

    Only resizable window types have glass borders when the titlebar is disabled.

    C# question

  • Disable resize cursor when on window border
    O o m n i

    Is there any way to prevent the cursor changing to the resize cursor when the mouse is over the window border?

    C# question

  • Translating pixel postion?
    O o m n i

    One thing to consider would be figuring out what percentage into the image the position is horizontally and vertically and then placing the point at the same percentage in on the larger image. not 100% sure it will work but it works in my head at least.

    C# graphics question

  • convert wav
    O o m n i

    http://www.codeplex.com/naudio[^] would be a good start.

    C# tutorial question

  • Translating pixel postion?
    O o m n i

    You can't, if the image is being displayed smaller then it really is as a background, it has only has as many pixels as the form does. A pixel is a uniform size. See this if you don't get what I'm saying.

    modified on Saturday, December 19, 2009 8:46 PM

    C# graphics question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups