I understand that the DLL typically has its own heap that it stores variables in. My DLL function takes a pointer to a wchar\_t variable, and whenever I try to put a value in it, it simply exits the function, leaving the pointer pointing to a bad location which I'm assuming is because the heap gets destroyed.

If my DLL function comes up with some sort of data that needs to be passed back, could someone give me an example of how I could get that data in string format back to the original main function?

Using Visual Studio 2010. 

Edit: I can provide some sample code, but I didn't see the point since I'm simply asking for an example/ explanation as to how memory is handled with regards to dll's and their functions. Ask me what information you need and I'll try to deliver. 

Well, to give you guys an idea as to what the application does, it's a COM server DLL. The interface is IProperty, the object is called PropertyObject. The DLL was built separately, by me, with the PropertyObject methods. This method, Getproperty, is the one I'm working on. 

```
STDMETHODIMP PropertyObject::GetProperty(int arg1, wchar_t* arg2)
{
    arg2 = L"Test";
    cout << *arg2 << endl;
    return S_OK;
}

int main()
{

CoInitialize(NULL);

IClassFactory * pClassFactory = NULL;
HRESULT hr;
hr  = CoGetClassObject(
CLSID_PropertyObject,
CLSCTX_SERVER,
NULL,
IID_IClassFactory,
(void **) &pClassFactory);

if (SUCCEEDED(hr))
{
    wchar_t x = NULL;
    IProperty *pProperty = NULL;

    hr = pClassFactory->CreateInstance(NULL, IID_IProperty, (void **) &pProperty);
    hr = pProperty->GetProperty(2, &x);
    cout << x << endl;
}
    return 0;
}

```