| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
String as function result type?
Hello I am new here, and I am mainly a Borland Delphi developer though quite a few projects have required or by preference caused me to make my Dynamic Link Library's in C/C++.
I am attempting to put the functionality of Delphi's TOpneDialog and TSaveDialog in a DLL for smaller exe and less memory usage( No matter what Open/Save dialogs seem to use a few mb's of RAM and even when free'd up no matter how the memory seems to stay). Anyway basically I need to call this dll in my Delphi application like so: MyString = MyOpenDialogFunc(); But this requires the function in my dll to be able to return a string, however including string.h and using: string MyFunc() Or std:string MyFunc() Seems to be no good, especially for the .h file with the exports listed. I must use Strings, not chars or char arrays. Any help is appreciated. EDIT: Here is a short version of my cpp and h file: Code:
#include "SMP3.h"
#include <windows.h>
#include <stdlib.h>
#include <string>
using namespace std;
char* __stdcall OpenSaveDialog(bool Open)
{
switch(Open)
{
case true:
{
string FData("");
// This is where the OPENFILENAME struct will be filled
// and GetOpenFileName API will be called.
// After that, if multiple files are selected the return
// value for filename needs to be parsed in a loop and
// added to the already existing data of FData.
return FData;
}
case false:
{
}
}
}
And SMP3.h: Code:
#ifndef _SMP3_H_ #define _SMP3_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else # define DLLIMPORT __declspec (dllimport) #endif extern "C" __declspec(dllexport) char* __stdcall OpenSaveDialog(bool Open); #endif You'll noticed I have char* for a char array but this was when trying to typecast a string to char* which I couldn't get to work either( Like Result = FData.c_str(); ). |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > String as function result type? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|