By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Why c++ string can't be used in a dll?

P: n/a
cai
Hi ,everyone, I come up with a problem, and I struggle with it for time ,
but I can't find the answer out.
I got a dll file like this:

/////////dll file////////
typedef struct tagIEPROXY
{
DWORD dwProxyEnable;
#ifdef UNICODE
wstring strProxyOverride;
wstring strProxyServer;
#else
string strProxyOverride;
string strProxyServer;
#endif
}IEPROXY,*PIEPROXY;

BOOL GetIEProxy(OUT IEPROXY& IEProxy)
{
IEProxy.strProxyServer = _T("Test");
return TRUE;
}

/////// the EXE file /////////
VOID main()
{
IEPROXY IeProxy;
if(!GetIEProxy(IeProxy))
return;
IeProxy.strProxyServer = _T("");
printf("%s","OK\n");
}

In debug mode, when I run up, it shows up an error:
_crtIsValidHeapPointer(pUserData). Why?

Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"cai" <al********@asus.com.cn> wrote in message
news:br*************@ID-147672.news.uni-berlin.de...
Hi ,everyone, I come up with a problem, and I struggle with it for time ,
but I can't find the answer out.
I got a dll file like this:

/////////dll file////////
typedef struct tagIEPROXY
{
DWORD dwProxyEnable;
#ifdef UNICODE
wstring strProxyOverride;
wstring strProxyServer;
#else
string strProxyOverride;
string strProxyServer;
#endif
}IEPROXY,*PIEPROXY;

BOOL GetIEProxy(OUT IEPROXY& IEProxy)
{
IEProxy.strProxyServer = _T("Test");
return TRUE;
}

/////// the EXE file /////////
VOID main()
{
IEPROXY IeProxy;
if(!GetIEProxy(IeProxy))
return;
IeProxy.strProxyServer = _T("");
printf("%s","OK\n");
}


This newsgroup is for discussion of standard C++ only. No one here knows
what a dll file is, or can tell you why you can't use a string in one. This
might direct you to the right place: http://www.slack.net/~shiva/welcome.txt

DW

Jul 22 '05 #2

P: n/a

"cai" <al********@asus.com.cn> wrote in message news:br*************@ID-147672.news.uni-berlin.de...
Hi ,everyone, I come up with a problem, and I struggle with it for time ,
but I can't find the answer out.


Ask in a microsoft.public.vc.language. The short answer is that your DLL and
your application are using a different C++ runtime library so the string in one is
NOT the same as the string in the other.
Jul 22 '05 #3

P: n/a

"David White" <no@email.provided> wrote in message
news:%f******************@nasal.pacific.net.au...

This newsgroup is for discussion of standard C++ only. No one here knows
what a dll file is...


Now that would be astounding.
Jul 22 '05 #4

P: n/a
> typedef struct tagIEPROXY
{
DWORD dwProxyEnable;
#ifdef UNICODE
wstring strProxyOverride;
wstring strProxyServer;
#else
string strProxyOverride;
string strProxyServer;
#endif
}IEPROXY,*PIEPROXY;

<snip>
This is a VC++ template issue when passing STL containers by reference to a
DLL. The workaround is to wrapper an instance of your struct in a simple
class and pass that class by reference, having your struct publicly
available.

Pseudo code (untested): -
// DLL Code
class ProxyWrapper
{
public:
tagIEPROXY m_prox;
};

void MyDllFunction(ProxyWrapper& rProx)
{
rProx.m_prox.strProxyOveride = "wibble";
}

// Calling code
ProxyWrapper prox;
MyDllFunction(prox);
std::string szRes(prox.m_prox.strProxyOveride);

HTH,
Great Orange Hunter
Jul 22 '05 #5

P: n/a
<snip>
Apologies, this work around does not work for all STL containers. It works
for vector, but not string.
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.