Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:33:30+00:00 2026-05-22T15:33:30+00:00

I’m actually translating some C++ code (which I know very little about, and have

  • 0

I’m actually translating some C++ code (which I know very little about, and have never really used) to C#. Normally in C# I wouldn’t find myself doing something like this, as it does seem a little odd, but with the way the code in C++ is setup, I find it hard not to do it this way. Admittedly, I’m not very experienced with programming at all, but for the amount of time I’ve been doing it I’ve been able to grasp the concepts fairly well.

Anyway, here’s the C++ code. It’s in a header file, too.

#ifndef _SPRITE_H_
#define _SPRITE_H_

#ifdef __cplusplus
    extern "C" {
#endif /* __cplusplus */


#ifndef NULL
    #define NULL ((void *) 0)
#endif

typedef struct {
    unsigned char *data;
    int len;
    int width;
    int height;
} SpriteImage;


typedef struct {
    unsigned char b;
    unsigned char g;
    unsigned char r;
    unsigned char unused;
} SpritePalette;


typedef struct {
    char *filename;
    unsigned int nimages;
    SpriteImage *images;
    unsigned int palette_size;
    SpritePalette *palette;
} Sprite;


typedef enum {
    /* Developer errors */
    SE_BADARGS,

    /* sprite_new() errors */
    SE_CANTOPEN,
    SE_INVALID,

    /* sprite_to_bmp(), sprite_to_bmp_file() and sprite_to_rgb() errors */
    SE_INDEX,

    /* sprite_to_bmp_file() errors */
    SE_CANTWRITE
} SpriteError;

//Funcion para hacer uso de reverse_palette desde el exterior
SpritePalette * get_pal(SpritePalette *palette,int palette_len);

/* Open sprite file */
Sprite *sprite_open (const char *fname, SpriteError *error);

Sprite *sprite_open_from_data (const unsigned char *data, unsigned int size, SpriteError *error);

/* Change palette of sprite*/
void change_palete(Sprite *sprite, const char *fname, SpriteError *error);

/* Converts a sprite to bitmap file in memory */
void *sprite_to_bmp (Sprite *sprite, int i, int *size, SpriteError *error);

/* Like sprite_to_bmp(), but saves the result to a file */
int sprite_to_bmp_file (Sprite *sprite, int i, const char *writeToFile, SpriteError *error);

/* Converts a sprite to raw RGB data. The rowstride/pitch is 3*width. */
void *sprite_to_rgb (Sprite *sprite, int i, int *size, SpriteError *error);

/* Frees a Sprite* pointer */
void sprite_free (Sprite *sprite);


#ifdef __cplusplus
    }
#endif /* __cplusplus */

#endif /* _SPRITE_H_ */

By the way, does anyone know what the deal is with the ‘#’ reference?

I have no idea what these refer to.

And here’s the C#:

interface Sprite
 {
    public class SpriteImage
    {
        private byte *data;
        private int length;
        private int width;
        private int height;
    }

    public class SpritePalette
    {
        byte b;
        byte g;
        byte r;
        byte unused;
    }

    public class Sprite
    {
        string fileName;
        uint nImages;
        uint palette_size;
        SpriteImage image;
        SpritePalette palette; 
    }

    public enum SpriteErrors
    { 
        None, //--default value
        BadArguments, //--dev errors

        /*--errors derived from any instance/call of the NewSprite() method */
        CantOpen, 
        Invalid,

        /*SpriteToBMP(), SpriteToBMPFile(), and SpriteToRGB() errors*/
        Index,

        CantWrite //--SpriteToBMPFile() errors 
    }

    public interface ISprite
    {
        SpritePalette GetPalette(SpritePalette palette, int paletteLength);

        Sprite SpriteOpen(string firstName, SpriteErrors* error);

        Sprite SpriteOpenFromData(byte* data, uint size, SpriteErrors* error);


    } 

I’m sure you can connect the dots here. Keep in mind that this isn’t my code, obviously, so I don’t really know much about it. If anyone needs anymore material though I’d be happy to provide it if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:33:31+00:00Added an answer on May 22, 2026 at 3:33 pm

    You appear to be trying to port this SourceForge project from C++ to C#:

    • Ragnarok Online Sprite Viewer

    That viewer is not only written in C++ but is also based on the Qt Toolkit.

    I know your question is about this translating this particular header file from C++ to C# and what is the best approach, but my opinion is that unless you are very comfortable with C++ and are willing to learn a lot about Qt, your chances of success at this porting project are not very good. This is a big project even for a programmer seasoned in both C++ and C#.

    However, if you still want to do this thing, then the approach you should take is to create a single large SpriteUtility static class and put all of the free C++ functions you find into that class as static C# methods. Yes, you can also put the C++ structs you see as nested classes. You don’t need any interfaces whatsoever.

    It doesn’t need to be beautiful C# code; you are trying to port it verbatim doing as little damage to it as possible. Once it is working you can refactor it to make it more object-oriented in the traditional C# style.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.