Re: setting an instance of an object

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Stephanie Doherty wrote:
[...] It is now giving me the same error message, but it is coming in a later assignment for that same structure. The exact code is:

lpPweParam.lLengthFldr = wcslen(lpPweParam.lptstrFolder);

I had abbreviated the structure declaration in my original message, but the lLengthFldr and lptstrFolder members are in the original structure declaration. (The lptstrFolder member is assigned in an previous line of code without a problem.)

So it seems that you make the same error: you access uninitialized memory by a pointer. Before you can access a content pointed by `lpPweParam.lptstrFolder' member you must ensure that it points to allocated chunk of memory. Also, the name `lpPweParam' suggests that it's a pointer. With pointer you need to use operator `->':

PWEPARAM pweParam = { ... };
pweParam.lptstrFolder = new WCHAR[someNumber];
....
wcscpy(pweParam.lptstrFolder, L"Hello World");
....
LPPWEPARAM lpPweParam = &pweParam;
size_t nLen = wcslen(lpPweParam->lptstrFolder); // OK


Alex
.



Relevant Pages