Image Control not working properly in MFC application

Hi,

I have started a simple test application with MFC and added an Image and a Display control to it, basically doing what the Getting Started section in CommonVisionBlox.chm recommends.

Loading an image seems to work, but when assigning the image to the display I don’t see any effect. Is this a known issue in the Display control???

Hi,

which version of :cvb: did you install? Win32 or x64? It could be that you compile for Win32 (default) and have an x64 version installed. It might be related to the Prefer 32 bit issue of C# projects:

Hello world cvb

1 Like

Not C#. MFC.
I am writing a 64 bit application. These are the wrapper classes that the MFC class wizard generated for me:

Hi.

The wrapper files that you sent have been generated with a 64 bit installation of :cvb: and are therefore targeting the x64 platform. This is visible from looking e.g. at the GetImage and SetImage methods:

__int64 GetImage()
{
	__int64 result;
	GetProperty(0x1, VT_EMPTY, (void*)&result);
	return result;
}
void SetImage(__int64 propVal)
{
	SetProperty(0x1, VT_EMPTY, propVal);
}

The 32 bit version of :cvb: would have int instead of __int64 here. These two automatically generated wrapper function implementation also directly show the problem: Rather than passing the __int64 value through the IDispatch interface, the code passes an empty variant (VT_EMPTY) - which is exactly the reason why your image won’t show (and I would guess that there is a lot going on in the trace output of Visual Studio whenever SetImage or GetImage is called.

This is a known and very unfortunate flaw of the wizard that builds the ActiveX control wrappers for MFC applications (and it is in fact not limited to this one; the corresponding Delphi wizards are also struggling with __int64 properties - the only tools doing well on this so far to my knowledge are aximp and tlbimp that generate the wrapper DLLs for .Net projects).

My recommendation to circumvent this problem:

  1. When using the MFC class wizard to generate member variables for ActiveX controls on a dialog, remove the trailing “1” from the default settings (i.e. from the class name and from the file names) and let it do its botched job.
  2. Open the source folder of any of the Visual C++ tutorials that ships with :cvb: which contains the ActiveX control that you are after. From there copy the …ctrl.h and the …ctrl.cpp file into your own source folder, overwriting the files that the wizard just generated.
  3. Build your project. If everything worked your source should simply compile. If it doesn’t then redo step 1 and 2 but watch out for (and take into account) any subtle differences in class name and/or file name that your particular Visual Studio version might try to use and the wrapper files shipped with :cvb:.