For a few days now i've been investigating how to best send data structures (specifically STL vectors) from a c++ DLL to some indie gamedev software based on Delphi (which i dont have internal access to). I've narrowed it down to two options, either i simply call the DLL multiple times to recieve one number at a time and incur some nasty overhead, or I send an appropiately formatted string (convert 16bit ints to 2x 8bit chars) containing the vector.
The problem is that when it tries to send a number below 256, the string length is apparently only 1 instead of being 2 with a zero character. At first i thought it was the signed 16bit number messing with the bitwise operators.... but beyond that i've really got no idea. Is it possible that im inserting a null character as opposed to a zero? How would i stop this?
As i test i wrote the DLL below:
Code:
#include <windows.h>
#include <string>
#define export extern "C" __declspec(dllexport) __stdcall
using namespace std;
string str = "";
export const char* send_ds(){
str = "";
unsigned __int16 j0 = 1;
__int8 j1 = ((j0<<8)>>8);
__int8 j2 = (j0>>8);
str += char(j1);
str += char(j2);
return (str.c_str());
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
switch (fdwReason){
case DLL_PROCESS_ATTACH: {break;}
case DLL_PROCESS_DETACH: {break;}
case DLL_THREAD_ATTACH: {break;}
case DLL_THREAD_DETACH: {break;}
}
return TRUE;
}
PS: Sorry for the sloppy coding format, i've never had any formal training, so i kinda just made it up as i went along. Also, Im using Dev-C++ and Mingw if thats of any importance....