Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubles in using the MapWinGIS activeX in C++ program. #190

Open
haquocviet opened this issue Mar 19, 2020 · 6 comments
Open

Troubles in using the MapWinGIS activeX in C++ program. #190

haquocviet opened this issue Mar 19, 2020 · 6 comments
Assignees

Comments

@haquocviet
Copy link

MapWinGIS-5.1.1-win32/x64-VS2017.
My Dev tool: VS2019 16.5 + WTL.

Though I the activeX works well in a C# program, I could not make it working in a C++ program.
The program always crashes when it tries to load the activeX at the function below.

// atlhost.h file
       // IOleInPlaceSiteEx
	STDMETHOD(OnInPlaceActivateEx)(
		_In_opt_ BOOL* /*pfNoRedraw*/,
		DWORD dwFlags) {
	
		...	
		
	if (m_spInPlaceObjectWindowless)
		m_spInPlaceObjectWindowless->SetObjectRects(&m_rcPos, &m_rcPos); <-- crashes at this point.
		return S_OK;
	}

I want someone to confirm that if the activeX supports integration with ATL/WTL C++ programs.

@jerryfaust
Copy link
Contributor

Hello @haquocviet

I'm guessing you might be the same person who commented in the MapWinGIS Discourse group?

Either way, I will add comments there. I have done an MFC dialog-based application in the past, and it worked well. I don't know anything about WTL, so I can't speak to that. But I will try to document the process I went through to create the app.

Regards,
Jerry.

@haquocviet
Copy link
Author

Hi @jerryfaust

Thank you for the reply. Yes I was the one posted on that group. I asked again here just because I thought that forum may be less active than here.

From your confirmation, I have tried to use the MapWinGIS in an MFC app and I could see the ActiveX is loaded successfully. However, I am still fail to make WTL/ATL works.
For more detail, I have the snapshot of the stack when the crash occurred.

CrashStack
CrashAt-SetObjectRects()

Regarding the WTL, it is just a very light layer based on ATL to help developers to develop Windows GUI without using MFC, in addition, WTL is more favor to COM than MFC.

(Forgive me not to answer you on the Discourse group, if I do, it should be duplicated).

@jerryfaust
Copy link
Contributor

jerryfaust commented Mar 20, 2020

Hello @haquocviet

I'm sorry, but at the moment I have no meaningful feedback for you. I would probably have to create a WTL application it in order to step through myself, and try to see what is happening with the OCX.

If you are able, you could build a debug version of the OCX so that you could step through and catch any errors inside the OCX. I think more likely, though, it is an issue in how the ATL/WTL framework is handling the OCX rather than the OCX itself, but I can't tell from the exception.

Is your current build 64-bit? I've not used VS2019, but it looks like the addresses shown are perhaps 64-bit addresses. But you said that you tried a 32-bit application with the 32-bit OCX, is that right? I don't know about VS2019, but prior to VS2019, you cannot debug a 64-bit OCX inside Visual Studio. You have to code/debug in 32-bit, then you can compile in 64-bit for the final executable.

Until this is figured out, I would encourage you to work strictly with the 32-bit OCX within a 32-bit application.

Kind Regards,
Jerry.

P.S. We have been encouraging people to move toward the Discourse website for questions and discussion, rather than using GitHub. Perhaps GitHub would be used strictly for bugs and code submissions.

@haquocviet
Copy link
Author

Hi @jerryfaust
Thanks for your detail.

Here are more things I realized after trying some ways.

  1. MapWinGIS-5.x-x32-VS2017 must be installed in order to see
    "MapControl" in the control list which opened by clicking to "Insert ActiveX Control...".
    If I install just x64 version, MSVC can't show "MapControl". But this is for only adding ActiveX into the dialog for both WTL and MFC types, at runtime MapWinGIS.ocx ( x64 version) is still loaded correctly.

  2. MFC app (x32 & x64) always loads ActiveX successfully.

  3. I make WTL app (x32 & x64) to load activeX by two methods: insert activeX to a dialog and by CreateControl() at runtime. Totally, there are 4 different ways to load the activeX.
    By any way the failure ends up at the same point below, one more level deeper than the previous report.

// MFC: ctlinplc.cpp. I have it after adding MFC package to current MSVC 2019.

BOOL COleControl::OnSetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
{
	...
	
	// Move outer window first. then inner window

    if (!m_bInPlaceSiteWndless)
    {
        CWnd* pWndOuter = GetOuterWindow();
        if (pWndOuter != NULL)
	{
		// Compute the clip rectangle in coordinates relative to the 
		// position rectangle
		CRect rectClipLocal(
			CPoint( rectClip.left-rectPos.left, rectClip.top-rectPos.top ),
			CSize( rectClip.Size() ) );
		// Clip the outer window to the clipping rectangle
		HRGN hRegion = ::CreateRectRgnIndirect(&rectClipLocal);
		pWndOuter->SetWindowRgn(hRegion, TRUE);

		CRect rectOuter;
		pWndOuter->GetWindowRect(&rectOuter);
		pWndOuter->GetParent()->ScreenToClient(&rectOuter); <-- crashed here.
		...
	  }
   }
}

Looking at the stack's memory, the "pWndOuter" has NULL window handle, therefore
pWndOuter->GetParent() returns NULL also.
Though I know the crash point but I do not know the root cause. ActiveX/OLE is complicated.

  1. Compiling MapWinGIS
    I have ever tried to remove MFC from MapWinGIS, but I soon realized
    MFC's components are wildly involved in the library, not to mention there are a lot
    of incompatibility between C++ compilers in VS2019 and VS2017/2015.

I attach the WTL sample here. If you have WTL installed, you can try the sample.
ATLMapApp2.zip

@dhuantes
Copy link

It's been years since I've done anything with WTL but I found this article.
It's old but appears to demo what you're trying to accomplish albeit not with MapWinGIS but thought it might help in the event you haven't already read it.
Good luck. Cheers!

https://www.codeproject.com/Articles/4174/WTL-for-MFC-Programmers-Part-VI-Hosting-ActiveX-Co

@haquocviet
Copy link
Author

Thanks @dhuantes.
I know the article you given. The methods I am using to add ActiveX/COM to an WTL project are not different from what the article described: by embedding to a dialog resource and by loading at runtime.
The issue I have with the MapWinGIS ActiveX may be because MapWinGIS is written in MFC and WTL does not understand MFC's components.
Note that, using the same project, I could load some other ActiveX(s) successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants