how to pass a string to a DLL file?

Posted By: pjotr987

how to pass a string to a DLL file? - 08/27/12 11:33

hi i try to write a function in a DLL file that should create a file with a name, that comes as string from Lite-C

here is it:

DLLFUNC int open_file(string datei_name, int status)//////////////opens file with string dateiname
{

int status;
std::string fileName(datei_name);
ifstream fin( fileName.c_str() );

if (fin.fail() )///////////////
{
//File not found

ofstream myfile;
myfile.open (datei_name);
myfile << "Writing this to a file.\n";
myfile.close();
status=1; ////////////////file created
}
else
{
status=2;///////////////file exists
}

return status;
}


now the question how to send the string(file name) from lite-c to the function?

thanks in advance
Posted By: 3dgs_snake

Re: how to pass a string to a DLL file? - 08/27/12 11:36

Hi,

I think you can pass in a char* variable or an engine STRING *

Best regards.
Posted By: pjotr987

Re: how to pass a string to a DLL file? - 08/27/12 11:45

hi i tried the following way in lite-C

STRING* file_name="test.txt"; //filename
int* status;

function open_file(STRING* file_name1,int* file_status); // function declaration

then in main function

open_file(file_name,status);

but it doesnt work out.

someone has any suggestions?



Posted By: 3dgs_snake

Re: how to pass a string to a DLL file? - 08/27/12 12:31

Hi,

It is working well for me.

Code:
DLLFUNC void test_char1(STRING *str)
{
	MessageBox(NULL, _chr(str), "From DLL", MB_OK);
}

DLLFUNC void test_char2(char *str)
{
	MessageBox(NULL, str, "From DLL", MB_OK);
}



Perhaps you should use multibyte character sets in your project, and I think you can't create std::string with STRING *variables wink

Best regards.
Posted By: pjotr987

Re: how to pass a string to a DLL file? - 08/29/12 20:41

thanks very much. it works ! laugh
© 2023 lite-C Forums