Hi All,

I have a function contained in a DLL and one of its parameters is a pointer to a struct that will be filled in with some information.

// struct definition
struct SomeStruct
{
char *one;
char *two;
}

//function in DLL
// DLL Headers go here
int GetInfo(int a, int b, SomeStruct *myS)
{
// some code goes here

for(int i = 0; <some condition>; i++)
{
myS[i].one = new char[100];
myS[i].two = new char [100];

//fill myS[i].one and myS[i].two with some data
}
} //end of DLL function


//Main Function
//Some variables are declared here and main()

SomeStruct *myInfo;
myInfo = new SomeStruct[100]; // Create 100 instances

// Function returns how many myInfo were filled in
int nRet = GetInfo(1, 2, myInfo);

for(int j = 0; j < nRet; j++)
{
cout << myInfo[j].one << " and " << myInfo[j].two;
}

delete myInfo;

//exit main function and the app as well...



The Problem:

I don't know how to delete the instances of char created in the DLL.
myS[i].one = new char[100];
myS[i].two = new char [100];

I cannot delete them in the DLL function as I need them in the EXE, however when I try to delete them in EXE, cannot do that as these pointers were created by the DLL module.

So how can I prevent this memory leak? Is there any way to delete these pointers? If so how? Or is this a bad design overall? any suggestions?

I appreciate your help!

Venet.