I'm using pure C with Windows SDK in my projects, but now I need to deal with DVR's camera, which the driver was made in MFC 6.0.
I can switch to C++ at any time (I'm already using it in some modules), but in this camera SDK I need CWnd's object.
//Initialize is a function, which initializes the related SDK instance.
Void Initialize(CWnd* pParent)
Can I create a fake CWnd, without loading the MFC stuff into MFC project, but just using my plain CreateWindow开发者_高级运维Ex() ?
Thank you.
CWnd is simply a wrapper around window handle and probably only methods that SDK function is using is obtaining parent window handle. You can try to rip all inheritance branch and dependencies of CWnd to mock the object with all data and methods without using actual MFC but I guess it will be a real hassle. Probably you will have to create some simple MFC layer, like a dll, that will take HWND handle from your code, then wrap it into CWnd and then call the camera SDK. You will probably need same version VC++ 6.0 to create a layer to make it work with the old library that you have.
If the SDK has a Function that takes a CWnd then it has probably been statically linked with MFC. This means that your project is now dependent on the MFC dlls being on your clients machine. Since your now tied to MFC you might as well bite the bullet and create an MFC project that is statically linked to MFC. I suggest just creating a simple console MFC project and work from there.
If any of the classes from MFC library, the application becomes MFC dependent. That is obvious. If the MFC library must be avoided, use HWND instead of CWnd i.e. use Win32 and create window handle and utilize the same.
But, as the camera SDK uses CWnd class, it already depends on MFC. So using MFC dll should not be problem. If the usage of MFC should be avoided, a intermediate wrapper dll can be used which can convert HWND to CWnd and pass it to the SDK Function.
Main Application:
HWND m_hWnd;
Intermediate DLL (resources should be handled properly if used):
void Initialize (HWND hWnd)
//Passing to SDK
Initialize( CWnd::FromHandle(hWnd))
精彩评论