Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

dll error, probally operator error

i keep getting:
96ax7b.jpg


here is my rgss code:

@dll = Win32API.new('encORdec.dll', 'encORdec', ['p','p'], 'p')

here is the c++ method if you need it, im keeping it simple for now just to get it working

header
Code:
#include <string>

using namespace std;

namespace test

{

    class crypto

    {

    public:

        static __declspec(dllexport) string encORdec(string text, string key);

    };

}
cpp
Code:
#include "encORdec.h"

#include <string>

#include <stdexcept>

 

using namespace std;

 

namespace test

{

    string crypto::encORdec(string text, string key)

    {

        string result = "";

        for (int c = 0; c < text.size(); c++)

        {

            char character = text[c];

            unsigned int charcode = (unsigned int)character;

            int keypos = c % key.size();

            char keychar = key[keypos];

            unsigned int keycode = (unsigned int)keychar;

            unsigned int combinedcode = charcode ^ keycode;

            char combinedchar = (char)combinedcode;

            result.append(combinedchar, 1);

        }   

        return result;

    }

 

  

}

if this is all very bad, please keep in mind this is my first attempt to use c++ lol

Thanks for any help
 
Looks to me that it's partly a few problems. First off, you're in C++, which mangles names, so "test::crypto.encORdec()" doesn't exactly translate what you'd expect. Next, you're defining the encORdec function as an instance function, and never making an instance for it to be called from. Finally, Ruby is sending pointers called VALUE (a slightly modified 32-bit longword) that correspond to each Ruby object, not a "string" C++ primitive.

To fix these, you should...
1) use export "C" { /*code */ } to tell the compiler to not mangle namespaces
2) Just use a namespace instead of a class for your functions.
3) Use Ruby's VALUE type to pass and return Ruby objects
 
thanks for the reply.

1) im using Microsoft visual c++ 2010, i tried finding anything irt messing with namespaces in the property's and couldn't find anything, do you know where i could find it?

2) easy enough

3) im not 100% sure what you mean, i mean logically it makes sense, but code wise im kinda not sure what to change.

thanks for your help thus far, ill keep playing with it. but any additional help would be much appreciated.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top