Closed HowardGu closed 5 years ago
CDMap.h generated by VS2015 has some issues so the function cannot be called correctly
Hello @HowardGu
So just to make sure, is the problem now resolved? or are there just issues with code external to MapWinGIS?
Hi @jerryfaust This problem is resolved now. When referencing mapwingis.ocx in mfc app in VS2017, the definition of SnapShotToDC in CDMap.h is as following
BOOL SnapShotToDC(void * hDC, LPDISPATCH Extents, long Width)
{
BOOL result;
static BYTE parms[] = VTS_UNKNOWN VTS_DISPATCH VTS_I4 ;
InvokeHelper(0x9f, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, hDC, Extents, Width);
return result;
}
We need to use VTS_I4 rather than VTS_UNKNOWN, or exception will be thrown. Seems there's something wrong when VS2017 generating the .h file.
Thank you @HowardGu for the feedback. I just looked at the API and there are at least a dozen methods that take the hDC as a parameter, and only the SnapShotToDC and SnapShotToDC2 use PVOID as the type. All others use either long or int (which is also a little suspicious, and makes me wonder about the behavior on 32 vs 64 bit compiles). I'll look a little further and perhaps create an Issue for this as it seems they should be consistent.
Hello everyone,
I'm using CDMap in a MFC app, when I trying to use SnapShotToDC to draw map to device context, an exception is thrown(no detail information in the exception), here's some sample code
void CMFCApplication1Dlg::OnPaint() { CPaintDC dc(this); // device context for painting try { CDMap mapObject = new CDMap; CRect mapRect(7, 7, 400, 200); if (mapObject->Create(NULL, WS_VISIBLE | WS_CHILD, mapRect, this, IDC_MAP2) == 0) { return; } bool res = mapObject->SnapShotToDC(dc.GetSafeHdc(), mapObject->GetKnownExtents(keWorld), 8000); } catch (CException e) { e->Delete(); } }
Could you please help provide some information on this?
Thanks, Howard