473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
5 1232
"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

"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

"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
> 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
<snip>
Apologies, this work around does not work for all STL containers. It works
for vector, but not string.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
15
by: Andrew Brampton | last post by:
Hi, I'm new to using std classes, but I was wondering how I could do the following efficiently with the string class: Say I had a string with delimited values such as:...
1
by: Neil Schemenauer | last post by:
The title is perhaps a little too grandiose but it's the best I could think of. The change is really not large. Personally, I would be happy enough if only %s was changed and the built-in was...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
11
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
9
by: Neal Barney | last post by:
I have a C program which runs on a device using a Zilog Z180 microprocessor. While it can address 1MB of RAM, it can only address 64KB at any given time. And of that only 16KB can be used for...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.