Click here to Skip to main content
15,910,603 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Disable pasting in EditBox Pin
Neville Franks7-May-03 1:54
Neville Franks7-May-03 1:54 
Generalcreating controls at runtime Pin
r i s h a b h s6-May-03 23:27
r i s h a b h s6-May-03 23:27 
GeneralRe: creating controls at runtime Pin
jmkhael7-May-03 0:13
jmkhael7-May-03 0:13 
GeneralVC++ 6.0 with C# dll Pin
NHM6-May-03 22:58
NHM6-May-03 22:58 
GeneralRe: VC++ 6.0 with C# dll Pin
VizOne7-May-03 7:22
VizOne7-May-03 7:22 
Generalget null when use GetFont in CView Pin
novachen6-May-03 22:08
novachen6-May-03 22:08 
GeneralRe: get null when use GetFont in CView Pin
Neville Franks7-May-03 1:57
Neville Franks7-May-03 1:57 
GeneralDll memroy allocation problem Pin
Cedric Moonen6-May-03 21:43
Cedric Moonen6-May-03 21:43 
Hi everybody !

I have a dll that 'produces' some objects (through the use of a function). Something that looks like:
HRESULT __declspec( dllexport ) DllGetFactoryObject(CToolFactoryIntfce *& ppObject) 
{
	ppObject = (CToolFactoryIntfce*) new CToolFactory;
	return NO_ERROR;
}


This object (the CToolFactoryIntfce) has his own Release method to destroy itself (delete this). So I when I call Release, the memory allocated by the dll is destroyed by the Dll. So, till now everything works perfectly.

Now, in this object, I have a method that returns a structure containing some data. The structure looks like:

struct TOOL_CONFIG_STRUCT
{
	BYTE* pConfigData;
	int ConfigSize;

	void Clear()
	{
		pConfigData = NULL;
		ConfigSize = 0;
	}
	void Release()
	{
		if (pConfigData)
		{
			delete[] pConfigData;
			pConfigData = NULL;
		}
		delete this;
	}
	void SetData(void* pData, int Size)
	{
		if (pConfigData)
		{
			delete[] pConfigData;
			pConfigData = NULL;
		}
		pConfigData = new BYTE[Size];
		memcpy(pConfigData,pData,Size);
		ConfigSize = Size;
	}
};


The method from the CToolFactory object looks like:
virtual void GetData(TOOL_CONFIG_STRUCT** ppToolData)  
	{ 
		*ppToolData = new TOOL_CONFIG_STRUCT;
		(*ppToolData)->Clear();
                //Then put some data in the structure
                (*ppToolData)->SetData(pData,nSize);
	}; 


So, that's for the Dll part. Now, in my main application, I retrieve a CToolFatory object and I call the GetData member function:
TOOL_CONFIG_STRUCT* pNewData = NULL;<br />
pToolFactory->GetData(pNewData);


(pToolFactory is a CToolFactoryIntfce object obtained throug the DllGetFactoryObject function)

That works correctly also! But the problem come when I call the Release function:
pNewData->Release();


It says that the memory was not allocated from the same heap !!!!
Anybody has any idea of what's happening here ??
Thanks a lot
GeneralRe: Dll memroy allocation problem Pin
Joaquín M López Muñoz6-May-03 22:08
Joaquín M López Muñoz6-May-03 22:08 
GeneralRe: Dll memroy allocation problem Pin
Cedric Moonen6-May-03 22:15
Cedric Moonen6-May-03 22:15 
GeneralI want to hide command line window Pin
Cheickna6-May-03 21:07
Cheickna6-May-03 21:07 
GeneralRe: I want to hide command line window Pin
imsniper6-May-03 21:25
imsniper6-May-03 21:25 
QuestionHow to get the size of a physical disk? Pin
Maxwell Chen6-May-03 20:06
Maxwell Chen6-May-03 20:06 
AnswerRe: How to get the size of a physical disk? Pin
Xander807-May-03 1:03
Xander807-May-03 1:03 
GeneralRe: How to get the size of a physical disk? Pin
Maxwell Chen8-May-03 15:56
Maxwell Chen8-May-03 15:56 
AnswerRe: How to get the size of a physical disk? Pin
Rage7-May-03 1:06
professionalRage7-May-03 1:06 
GeneralRe: How to get the size of a physical disk? Pin
Maxwell Chen8-May-03 16:00
Maxwell Chen8-May-03 16:00 
AnswerRe: How to get the size of a physical disk? Pin
David Crow7-May-03 4:17
David Crow7-May-03 4:17 
GeneralRe: How to get the size of a physical disk? Pin
Maxwell Chen8-May-03 16:10
Maxwell Chen8-May-03 16:10 
GeneralPrinting a graph Pin
summo6-May-03 20:02
summo6-May-03 20:02 
QuestionReclaim memory...? Pin
Ph@ntom6-May-03 19:40
Ph@ntom6-May-03 19:40 
AnswerRe: Reclaim memory...? Pin
David Crow7-May-03 4:19
David Crow7-May-03 4:19 
GeneralRe: Reclaim memory...? Pin
Ph@ntom7-May-03 18:58
Ph@ntom7-May-03 18:58 
GeneralRe: Reclaim memory...? Pin
David Crow8-May-03 2:18
David Crow8-May-03 2:18 
QuestionCDialog automatically deletion --- safe? Pin
lauch26-May-03 15:17
lauch26-May-03 15:17 

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.