Link to home
Start Free TrialLog in
Avatar of softbee
softbeeFlag for South Africa

asked on

ATL COM dll refuses to implicitly link with MFC dll

None of the implicit linking methods work in this situation.
I have assembled a small sample solution that I desperately need an expert to look at.
The projects are Device, DevWrap and TestBench and are compiled under VC6.
The header file BioDevice declares the links.
The DevWrapper.cpp file requires the linking.
See CDevWrapper::CloseDevice() where the problem has been commented out.
 Urgent attention to this problem would be most appreciated.
I am expert at MFC but raw on ATL.
The object of the exercise was originally to wrap a MFC dll with a ATL COM wrapper so that the COM result could be used universally.
This site does not alow my zip components. Could I email this to a willing expert?
#include "stdafx.h"
#include "BioDevice.h"
#include "DevWrap.h"
#include "DevWrapper.h"
 
/////////////////////////////////////////////////////////////////////////////
// CDevWrapper
 
STDMETHODIMP CDevWrapper::CloseDevice(LONG* lngRetVal)
{
	int iRet = -1;
//	CDeviceApp * pDev;
//	pDev = new CDeviceApp();
//	iRet = dllClose();
	*lngRetVal = (long)iRet;
	return S_OK;
}

Open in new window

Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Upload the file to http://www.yousendit.com/ (enter bogus mail addresses, that doesn't matter) and post the link it gives you here.
Few technical issues first:

Are you still working with VC2003? It's not clear from your post.

To the best of my knowledge, you can "Attach files" of up to 5MB, including ZIP (other extensions are bmp doc gif jpeg jpg log mdb pdf png txt xls). You seem to need "scripts enabled" in your browser to upload files.

It is hard to understand what problem you have with the attached code: LNK2019 again?
Avatar of softbee

ASKER

I built a complete sample in VC6 since the original mfc dll was built using vc6 and it will not migrate to VS2003.
And yes, the problem stays the same, but is now easier to see, since all the other clutter has been removed.
I get the feeling that the ATL wrapper needs MFC support, but for the life of me, I also dont see why?
Avatar of softbee

ASKER

Further comment:
The files inside the zip are apparently also looked at on upload, so wrap.cpp is illegal. Can you pick up the file the same as mrwad99. Sorry guys, I usually do my own thing and I am not into the whole internet collaboration deal.
I need this piece of work as part of a POC contract.
Your interest is much appreciated.
Avatar of softbee

ASKER

Sorry, for a while I did not understand
The link is:
http://www.yousendit.com/download/Y2o5SXQwNXZubVZFQlE9PQ 
If you go to the Properties of the project and switch from "Use MFC in a Shared DLL" to "Use MFC in a Static Library" does it make a difference?
Your projects compile and run in VisualStudio 2005. The only glitch is that you cannot call CoUninitialize() while a CComPtr<> is in scope. Attached find the fixed version of CTestBenchDlg::OnCloseDevice() function. But this is not for real, you should rather call CoInitialize(NULL) and CoUninitialize() in your WinMain().
void CTestBenchDlg::OnCloseDevice() 
{
    CoInitialize(NULL);
    {
        CComPtr<IUnknown> spUnknown;
        HRESULT hr = spUnknown.CoCreateInstance( __uuidof( DevWrapper ));
        CComPtr<IDevWrapper> pI;
        spUnknown.QueryInterface(&pI);
        long res = 0;
        pI->CloseDevice( &res );
    }
    CoUninitialize();
}

Open in new window

Avatar of softbee

ASKER

to alexcohn:
I know about that, but I needed this to stay as simple as possible.
Are you telling me that you used my solution 'as is' in VS2005?
If true, then I must attempt to run this in VS2003 EE. Unfortunately i dont have 2005 available.
Please let me know if there was anything else that needed doing.
I will rebuild in the morning and let you know what happened.
I am very relieved that it is possible. There are lots of other dll's that require the same treatment.

to LordOfPorts:
I will have a look at this as well.
Visual Studio converted all three projects for me automatically, and displayed some warnings about obsolete features (like the ordinal numbers for functions exported from the wrapper). But after that, I could simply open the dialog app and press the button.
ASKER CERTIFIED SOLUTION
Avatar of alexcohn
alexcohn
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softbee

ASKER

All is like you predicted. And funnily enough, every comment you made is within my grasp. I was misled by expecting some hocus-pocus to be present in the ATL component.
My sincere thanks.