Codice della dll:
///dllmain.cpp
#include "dll.h"
#include <iostream>
#include <string>
#include <windows.h>
using std::string;
export string _encrypt(string _in,string _key,int _mode)
{
int _inlen,_keylen,pos;
_inlen = _in.length();
_keylen = _key.length();
char _inchar,_keychar,_outchar;
char _inchararr[_inlen];
char _keychararr[_keylen];
strcpy(_inchararr,_in.c_str());
strcpy(_keychararr,_key.c_str());
int _inval,_keyval,_outval;
std::string _out;
for (int _pos=0;_pos<_inlen;pos+=1)
{
_inchar = _inchararr[_pos+1];
_keychar = _keychararr[(_pos%_keylen)+1];
_inval = (int)_inchar;
_keyval = (int)_keychar;
if (_mode == 1)
{
_outval = (_inval + _keyval) % 256;
} else {
_outval = (256 + _inval - _keyval) % 256;
}
_outchar = (char)_outval;
_out = _out + _outchar;
}
return _out;
}
///dll.h
#ifndef _DLL_H_
#define export extern "C" __declspec (dllexport)
#define _DLL_H_
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
/* class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass();
void HelloWorld();
};
*/
#endif
Di Game Maker per chiamarla:
///obj_controller CREATE EV
n1=get_string("Enter a string","");
n2=get_string("Enter a key","");
message_size(room_width,room_height);
switch(show_message_ext ("Please chose an option ","Encrypt","Decrypt","Exit"))
{
case 1:
{
n3 = 0;
result = external_call(external_define("Arxcrypto.dll","_encrypt",dll_stdcall,ty_string,3,ty_string,ty_string,ty_real),n1,n2,n3);
show_message (result);
clipboard_set_text(result);
show_message ("Result copyied to the clipboard");
}
case 2:
{
n3 = 1;
result =external_call(external_define("Arxcrypto.dll","_encrypt",dll_stdcall,ty_string,3,ty_string,ty_string,ty_real),n1,n2,n3);
show_message (result);
clipboard_set_text(result);
show_message ("Result copyied to the clipboard");
}
case 3:
script_execute (scr_exit);
}