C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 27th, 2006, 05:31 AM
Chesso Chesso is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 24 Chesso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 57 m 33 sec
Reputation Power: 0
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(); ).

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > String as function result type?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT