Click here to Skip to main content
15,887,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: ClassView Missing Pin
John M. Drescher27-Oct-05 20:27
John M. Drescher27-Oct-05 20:27 
Questionclw seems to be allright Pin
shivditya27-Oct-05 20:52
shivditya27-Oct-05 20:52 
AnswerRe: clw seems to be allright Pin
kakan27-Oct-05 21:21
professionalkakan27-Oct-05 21:21 
AnswerRe: ClassView Missing Pin
Steve Mayfield27-Oct-05 21:44
Steve Mayfield27-Oct-05 21:44 
GeneralRe: ClassView Missing Pin
shivditya27-Oct-05 21:50
shivditya27-Oct-05 21:50 
AnswerRe: ClassView Missing Pin
Trollslayer28-Oct-05 3:25
mentorTrollslayer28-Oct-05 3:25 
QuestionMy problem is still unsolved Pin
shivditya28-Oct-05 17:33
shivditya28-Oct-05 17:33 
Questionhow to pass std::string from dll Pin
compoundeye27-Oct-05 19:09
compoundeye27-Oct-05 19:09 
Hello,

I have a problem I don't know how to fix

I've got some code that works perfectly in the main executable, but falls over if moved to a dll

Heres some code written to highlight the problem:

The first example works perfectly:

The method setString sets sMyString to “happy string” and everything works just dandy

#include "LocalStringRefTest.h"

#include <string>
#include <stdio.h>		// Needed for printf.

using namespace std ;

int main(int argc, char* argv[])
{
	//FCGI_Accept();
	{
		string sMyString;
		sMyString = "";
	
		{
			LocalStringRefTest tester;
			tester.setString(sMyString);
		}

		printf (sMyString.c_str());
	}


	return 0; }


But if I move my class to a dll and try again,
Everything works just fine until sMyString goes out of scope

#include "myDll/StringRefTest.h"

#include <string>
#include <stdio.h>		// Needed for printf.

using namespace std ;

int main(int argc, char* argv[])
{
	{
		string sMyString;
		sMyString = "";
	
		{
			StringRefTest tester;
			tester.setString(sMyString);
		}

		printf (sMyString.c_str());
	}

	return 0; }

In same executable
LocalStringRefTest.h
#ifndef LocalStringRefTest_CLASS_H
#define LocalStringRefTest_CLASS_H

#include <string>

using namespace std ;

class LocalStringRefTest
{
	public:
		LocalStringRefTest();

		bool setString(string& sString);

	protected:
		string m_sString;
};

#endif

LocalStringRefTest.cpp
#include "LocalStringRefTest.h"
using namespace std ;

//constructors:
LocalStringRefTest::LocalStringRefTest()
:m_sString("Happy String")
{

}

bool LocalStringRefTest::setString(string& sString)
{
	sString = m_sString;
	return true;
}

In dll
StringRefTest.h
#ifndef StringRefTest_CLASS_H
#define StringRefTest_CLASS_H

#include <string>

using namespace std ;

class __declspec(dllexport) StringRefTest
{
	public:
		StringRefTest();

		bool setString(string& sString);

	protected:
		string m_sString;
};

#endif

StringRefTest.cpp
#include "myDll/StringRefTest.h"
using namespace std ;

//constructors:
StringRefTest::StringRefTest()
:m_sString("Happy String")
{

}

bool StringRefTest::setString(string& sString)
{
	sString = m_sString;
	return true;
}



As i debug through my code, everything works fine until the string goes out of scope

when that happens i get:
NTDLL! 7c96cd80()
NTDLL! 7c960af8()
KERNEL32! 7c85e7af()
_CrtIsValidHeapPointer(const void * 0x00961a00) line 1606
_free_dbg_lk(void * 0x00961a00, int 1) line 1011 + 9 bytes
_free_dbg(void * 0x00961a00, int 1) line 970 + 13 bytes
free(void * 0x00961a00) line 926 + 11 bytes
operator delete(void * 0x00961a00) line 7 + 9 bytes
std::allocator<char>::deallocate(void * 0x00961a00, unsigned int 33) line 64 + 38 bytes
std::basic_string<char,std::char_traits<char>,std::allocator<char> 
::_Tidy(unsigned char 1) line 592
std::basic_string<char,std::char_traits<char>,std::allocator<char> 
::~basic_string<char,std::char_traits<char>,std::allocator<char> >() 
line 59 + 39 bytes
main(int 1, char * * 0x00a70eb0) line 26
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 7c816d4f()

Invalid Address specified to RtlValidateHeap( 00A60000, 009619E0 )


from looking around on the net it seems this is a fairly commonly encountered problem.
I've found a lot of useful information but not a specific answer i was able to use to resolve my problem
i've found the related article on http://support.microsoft.com/kb/168958/

but i just don't understand what i need to do to be able to make it work,


thanks for you help,
mat
AnswerRe: how to pass std::string from dll Pin
kakan27-Oct-05 20:12
professionalkakan27-Oct-05 20:12 
GeneralRe: how to pass std::string from dll Pin
compoundeye27-Oct-05 20:19
compoundeye27-Oct-05 20:19 
GeneralRe: how to pass std::string from dll Pin
kakan27-Oct-05 20:26
professionalkakan27-Oct-05 20:26 
AnswerRe: how to pass std::string from dll Pin
S. Senthil Kumar27-Oct-05 21:12
S. Senthil Kumar27-Oct-05 21:12 
GeneralRe: how to pass std::string from dll Pin
compoundeye27-Oct-05 21:52
compoundeye27-Oct-05 21:52 
QuestionHow to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 17:18
LaHaHa27-Oct-05 17:18 
AnswerRe: How to make the mfc button as press &amp; lock Pin
Christian Graus27-Oct-05 17:20
protectorChristian Graus27-Oct-05 17:20 
GeneralRe: How to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 17:46
LaHaHa27-Oct-05 17:46 
GeneralRe: How to make the mfc button as press &amp; lock Pin
Christian Graus27-Oct-05 17:52
protectorChristian Graus27-Oct-05 17:52 
GeneralRe: How to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 18:54
LaHaHa27-Oct-05 18:54 
GeneralRe: How to make the mfc button as press &amp; lock Pin
Christian Graus27-Oct-05 19:06
protectorChristian Graus27-Oct-05 19:06 
AnswerRe: How to make the mfc button as press &amp; lock Pin
P-Rex27-Oct-05 20:05
P-Rex27-Oct-05 20:05 
GeneralRe: How to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 21:38
LaHaHa27-Oct-05 21:38 
GeneralRe: How to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 21:50
LaHaHa27-Oct-05 21:50 
AnswerRe: How to make the mfc button as press &amp; lock Pin
BadKarma27-Oct-05 21:06
BadKarma27-Oct-05 21:06 
GeneralRe: How to make the mfc button as press &amp; lock Pin
LaHaHa27-Oct-05 21:51
LaHaHa27-Oct-05 21:51 
QuestionThread ending problem in CFormView Pin
ledallam27-Oct-05 16:34
ledallam27-Oct-05 16:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.