473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

is there a bug in mfc71d.dll?

this is the function that the problem lies in. it is in MFC file ctlpset.cpp

BOOL COleControl::GetPropsetData(LPFORMATETC lpFormatEtc,
LPSTGMEDIUM lpStgMedium, REFCLSID fmtid)
{
ASSERT_VALID(this);
ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE));
ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

BOOL bGetDataHere = (lpStgMedium->tymed != TYMED_NULL);

// Allow IStream or IStorage as the storage medium.

if (!(lpFormatEtc->tymed & (TYMED_ISTREAM|TYMED_ISTORAGE)))
{
TRACE(traceAppMsg, 0, "Propset only supported for stream or storage.\n");
return FALSE;
}

LPSTORAGE lpStorage = NULL; // here they initialize the lpStorage,
lpStream to NULL
LPSTREAM lpStream = NULL;
//then they test whether the output file is a stream or storage.

if (lpFormatEtc->tymed & TYMED_ISTORAGE)
{

//if it is storage,then the lpStorage is assigned a new value
//but lpStream keep the NULL value.

// Caller wants propset data in a storage object.

if (bGetDataHere)
{
// Use the caller-supplied storage object.
lpStorage = lpStgMedium->pstg;
}
else
{
// Create a storage object on a memory ILockBytes implementation.
LPLOCKBYTES lpLockBytes = NULL;

if (FAILED(CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
{
TRACE(traceAppMsg, 0, "CreateILockBytesOnHGlobal failed.\n");
return FALSE;
}

ASSERT_POINTER(lpLockBytes, ILockBytes);

if (FAILED(StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0,
&lpStorage)))
{
TRACE(traceAppMsg, 0, "StgCreateDocfileOnILockBytes failed.\n");
lpLockBytes->Release();
return FALSE;
}

// Docfile now has reference to ILockBytes, so release ours.
lpLockBytes->Release();
}

ASSERT_POINTER(lpStorage, IStorage);

// Create a stream within the storage.
if (FAILED(lpStorage->CreateStream(OLESTR("Contents"),
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, 0,
&lpStream)))
{
TRACE(traceAppMsg, 0, "IStorage::CreateStream failed.\n");
if (!bGetDataHere)
lpStorage->Release();
return FALSE;
}
}
else
{
//if it is stream ,then the lpStream is assigned a new value
//but lpStorage keep the NULL value.
// Caller wants propset data in a stream object.

if (bGetDataHere)
{
// Use the caller-supplied stream object
lpStream = lpStgMedium->pstm;
}
else
{
lpStream = _AfxCreateMemoryStream();
if (lpStream == NULL)
return FALSE;
}
}

//but in later program, we can find that, if there is a fail in the
process, they always release lpStream,lpStorage togetgher. so we can tell,
if our ocx control adhere to MS's rule, it runs fluently, if not, it may have
problem.
ASSERT_POINTER(lpStream, IStream);

// Create the property set.

CLSID clsid;
GetClassID(&clsid);
CPropertySet pset(clsid);
pset.SetOSVersion(MAKELONG(LOWORD(GetVersion()), OSTYPE));
CPropertySection* ppsec = pset.AddSection(fmtid);
if (ppsec == NULL)
{
TRACE(traceAppMsg, 0, "CPropertySet::AddSection failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Set the name, based on the ambient display name (from the container).
ppsec->SetSectionName(AmbientDisplayName());

CPropsetPropExchange propx(*ppsec, lpStorage, FALSE);

BOOL bPropExchange = FALSE;
TRY
{
DoPropExchange(&propx);
bPropExchange = TRUE;
}
END_TRY

if (!bPropExchange)
{
TRACE(traceAppMsg, 0, "DoPropExchange failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Store the property set in the stream.

if (!pset.WriteToStream(lpStream))
{
TRACE(traceAppMsg, 0, "CPropertySet::WriteToStream failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Return the property set in the requested medium.

if (lpFormatEtc->tymed & TYMED_ISTORAGE)
{
// Return as a storage object.

ASSERT_POINTER(lpStorage, IStorage);
lpStream->Release();
lpStgMedium->pstg = lpStorage;
lpStgMedium->tymed = TYMED_ISTORAGE;
lpStgMedium->pUnkForRelease = NULL;
}
else
{
// Return as a stream.

ASSERT_POINTER(lpStream, IStream);
lpStgMedium->pstm = lpStream;
lpStgMedium->tymed = TYMED_ISTREAM;
lpStgMedium->pUnkForRelease = NULL;
}

return TRUE;
}
Jul 21 '05 #1
1 2026
I have also met this problem.

I use wizard to create a ocx, and without add anyting in it. when I plug it
in my form, and use it's Idataobject->getdatahere to save it's properties to
a stream.
it exposes a crash. I have found MS has done some modification in the MFC
class.
but I don't know why?
"Reed Cao" wrote:
this is the function that the problem lies in. it is in MFC file ctlpset.cpp

BOOL COleControl::GetPropsetData(LPFORMATETC lpFormatEtc,
LPSTGMEDIUM lpStgMedium, REFCLSID fmtid)
{
ASSERT_VALID(this);
ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE));
ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

BOOL bGetDataHere = (lpStgMedium->tymed != TYMED_NULL);

// Allow IStream or IStorage as the storage medium.

if (!(lpFormatEtc->tymed & (TYMED_ISTREAM|TYMED_ISTORAGE)))
{
TRACE(traceAppMsg, 0, "Propset only supported for stream or storage.\n");
return FALSE;
}

LPSTORAGE lpStorage = NULL; // here they initialize the lpStorage,
lpStream to NULL
LPSTREAM lpStream = NULL;
//then they test whether the output file is a stream or storage.

if (lpFormatEtc->tymed & TYMED_ISTORAGE)
{

//if it is storage,then the lpStorage is assigned a new value
//but lpStream keep the NULL value.

// Caller wants propset data in a storage object.

if (bGetDataHere)
{
// Use the caller-supplied storage object.
lpStorage = lpStgMedium->pstg;
}
else
{
// Create a storage object on a memory ILockBytes implementation.
LPLOCKBYTES lpLockBytes = NULL;

if (FAILED(CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
{
TRACE(traceAppMsg, 0, "CreateILockBytesOnHGlobal failed.\n");
return FALSE;
}

ASSERT_POINTER(lpLockBytes, ILockBytes);

if (FAILED(StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0,
&lpStorage)))
{
TRACE(traceAppMsg, 0, "StgCreateDocfileOnILockBytes failed.\n");
lpLockBytes->Release();
return FALSE;
}

// Docfile now has reference to ILockBytes, so release ours.
lpLockBytes->Release();
}

ASSERT_POINTER(lpStorage, IStorage);

// Create a stream within the storage.
if (FAILED(lpStorage->CreateStream(OLESTR("Contents"),
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, 0,
&lpStream)))
{
TRACE(traceAppMsg, 0, "IStorage::CreateStream failed.\n");
if (!bGetDataHere)
lpStorage->Release();
return FALSE;
}
}
else
{
//if it is stream ,then the lpStream is assigned a new value
//but lpStorage keep the NULL value.
// Caller wants propset data in a stream object.

if (bGetDataHere)
{
// Use the caller-supplied stream object
lpStream = lpStgMedium->pstm;
}
else
{
lpStream = _AfxCreateMemoryStream();
if (lpStream == NULL)
return FALSE;
}
}

//but in later program, we can find that, if there is a fail in the
process, they always release lpStream,lpStorage togetgher. so we can tell,
if our ocx control adhere to MS's rule, it runs fluently, if not, it may have
problem.
ASSERT_POINTER(lpStream, IStream);

// Create the property set.

CLSID clsid;
GetClassID(&clsid);
CPropertySet pset(clsid);
pset.SetOSVersion(MAKELONG(LOWORD(GetVersion()), OSTYPE));
CPropertySection* ppsec = pset.AddSection(fmtid);
if (ppsec == NULL)
{
TRACE(traceAppMsg, 0, "CPropertySet::AddSection failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Set the name, based on the ambient display name (from the container).
ppsec->SetSectionName(AmbientDisplayName());

CPropsetPropExchange propx(*ppsec, lpStorage, FALSE);

BOOL bPropExchange = FALSE;
TRY
{
DoPropExchange(&propx);
bPropExchange = TRUE;
}
END_TRY

if (!bPropExchange)
{
TRACE(traceAppMsg, 0, "DoPropExchange failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Store the property set in the stream.

if (!pset.WriteToStream(lpStream))
{
TRACE(traceAppMsg, 0, "CPropertySet::WriteToStream failed.\n");
lpStream->Release();
lpStorage->Release();
return FALSE;
}

// Return the property set in the requested medium.

if (lpFormatEtc->tymed & TYMED_ISTORAGE)
{
// Return as a storage object.

ASSERT_POINTER(lpStorage, IStorage);
lpStream->Release();
lpStgMedium->pstg = lpStorage;
lpStgMedium->tymed = TYMED_ISTORAGE;
lpStgMedium->pUnkForRelease = NULL;
}
else
{
// Return as a stream.

ASSERT_POINTER(lpStream, IStream);
lpStgMedium->pstm = lpStream;
lpStgMedium->tymed = TYMED_ISTREAM;
lpStgMedium->pUnkForRelease = NULL;
}

return TRUE;
}

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: R Tamilarasan | last post by:
Curiosity made me to install VC - 7 (.net) in my machine which had VC - 6 already installed. I tried to compile my workspace in VC - 7 but failed due to several compile time errors. ok no...
0
by: ziv | last post by:
I am encountering a very strange error Openning a Visual C++/Win32 Console project with mfc support, writing a simple Sleep(5000) function in the main and running the app in Debug mode (default...
0
by: Droopy | last post by:
Hi, I am working for a few month on a C# project (mixed dll for calling C++ legacy code with a C# wrapper). Since this morning, I can't start my application anymore ! I got a...
2
by: Craig Klementowski | last post by:
Pardon the cross post, but I'm not sure where exactly to post this question. We have MFC application using many MFC extention DLL's. We started using a new MFC extention DLL that is mixed mode so...
5
by: Dave | last post by:
I am trying to compile my C++ programs in debug mode in Visual NET 2003 and keep getting the following message fatal error LNK1104: cannot open file 'mfc70d.lib I cannot find this program anywhere...
2
by: Doug Bailey | last post by:
I have an application in which some unmanaged classes are being pulled into a Managed Windows Form application. The umanaged class has a number of CString variables. When I link the program, I...
6
by: William F. Kinsley | last post by:
I am thinking of porting an existing MFC application to MC++ and I have created a simple MFC application to test the environment. My sample MFC application is compilied with the /clr switch. I...
1
by: Reed Cao | last post by:
this is the function that the problem lies in. it is in MFC file ctlpset.cpp BOOL COleControl::GetPropsetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium, REFCLSID fmtid) {...
6
by: nscbabu | last post by:
Hi, We are migrating a product from vc6 to vs.net 2003, when we run the app it crashes pointing to a c++ class destructor, we didnot make any code changes during the migration. Can anybody help...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.