Article View: borland.public.cppbuilder.nativeapi
Article #10649DLL and std::string?
From: nicolasr
Date: Tue, 06 Apr 2004 23:37
Date: Tue, 06 Apr 2004 23:37
66 lines
2731 bytes
2731 bytes
Hi,
not sure if this is the appropriate group. If not please redirect me.
I want to export some code for validating files to a DLL. Since I have
not written many DLLs yet I have some troubles/questions
1) I would like to use the std::string class for parameters of the
exported functions. Are there any issues I should be aware of with this?
The DLL will only be used from C++ code, most likely only from BCB.
2) The DLL .cpp file that BCB generates starts with a long comment
about using string (AnsiString?) parameters in exported functions.
Is anything mentioned there relevant when using std::string?
3) Below is my DLL code. The client code loads the DLL
dynamically and calls the Validate function. The Validate
function accepts the name of an internal function to call
and a std::string parameter specifying a file name that it
passes on to the internal function.
When I run this code the FileType1Test function generates
an exception and brings up the CPU window.
When debugging I can see that the input parameter "fileName"
contains a valid string when entering the function FileType1Test.
After the line "ifstream in..." the "fileName" content is ???? like
something corrupts the stack?
Thanks for any ideas,
Nick
#include <fstream>
using std::ifstream;
#include <string>
using std::string;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst,
unsigned long reason, void* lpReserved)
{
return 1;
}
bool FileType1Test(const string& fileName)
{
ifstream in(fileName.c_str());
char c;
in >> c;
if(c == 'A')
return true;
else
return false;
}
extern "C" __declspec(dllexport) string __stdcall Validate
(const string& funcName, const string& args)
{
if(funcName == "FileType1Test")
return FileType1Test(args) ? "TRUE" : "FALSE";
else
return "FALSE";
}
Technical Details
Message-ID:
<40733f34@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,fd71d18cb19fccaf,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-06 16:39:50 PST From: "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: DLL and std::string? Date: Wed, 7 Apr 2004 01:37:20 +0200 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 80.133.175.214 Message-ID: <40733f34@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1081294644 80.133.175.214 (6 Apr 2004 16:37:24 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail