Loading dlls

I'm pretty new to RPG Maker and Ruby but here is what I have so far:

A dll made in cpp with this code:

#include <string>using namespace std;extern "C" __declspec(dllexport) string HelloWorld(string name){ return "Hello " + name;}And a script with this code:

GetText = Win32API.new('CPPHelloWorld', 'HelloWorld', 'p', 'p')def DisplayText text = GetText.call('Bob') #$game_message.add(text) #$game_actors[$game_variables[4]].tp = text;endIf i could get either of those last two commented lines to work that would be great, I'm just trying to get text from the dll to display. However, the game crashes without an error message on the the line for GetText.call... (works fine when I comment it out). My event just runs DisplayText() then displays the the fourth variable.

I was wondering if anyone new why it was crashing or what i was doing wrong? I am trying to learn how to load dlls into ruby/rpgmaker. Also, I have tried using char arrays/pointers instead of strings in the cpp code as well.
I've moved this thread to Learning RGSS. Please be sure to post your threads in the correct forum next time. Thank you.
You simply can't use std::string directly. This should work but returning a pointer to characters is a bad idea. See asctime() vs. asctime_s() / asctime_r().

Code:
#include <string>static std::string hello;extern "C" __declspec(dllexport) char const *HelloWorld(char const * const name){  hello = "Hello ";  hello += name;  return hello.c_str();}
Ah, okay. Thanks that helps a bunch. With the asctime example you gave me, you where refering to the race condition caused by returning a char pointer and how they avoided it by how they used the buffer? Guess I should have read up on some best practices for c++ before I just jumped into it.

Original thread: https://forums.rpgmakerweb.com/threads/loading-dlls.40414/