Re: Calling FreeLibrary in destructor
Well, I am not doing nothing special between WM_CREATE and WM_DESTROY... I
am calling some methods from object... Here is class header code and
corresponding implementation maybe you will find what is wrong...
Here is call stack:
user32.dll!7e41b393()
SomeDrawing.exe!WndProc(HWND__ * hWnd=0xffffffff, unsigned int
message=1242544, unsigned int wParam=2118223668, long lParam=67620) Line
212 + 0x18 bytes C++
SomeDrawing.exe!_VirtualQuery@12() + 0xf1c bytes C++
user32.dll!7e440457()
OK, from CallStack my WndProc is problematic...but I couldn't figure out
why/what?
Once again thanks a lot...
// BELOW IS HEADER
#pragma once
#include <windows.h>
// Typedef for pointer to capCreateCaptureWin function
typedef HWND (CALLBACK* CAPCAPWIN) (LPCWSTR, DWORD, int, int, int, int,
HWND, int);
class Webcam
{
public:
Webcam(const LPCWSTR WindowName, HWND ParentWnd, int left, int top,
int width, int height, DWORD style, int webCamId);
~Webcam();
bool Connect();
bool Disconnect();
private:
CAPCAPWIN fpCapCreateCaptureWin;
HMODULE hModDllAviCap;
HWND CaptureWnd;
};
// BELOW IS CPP
#pragma once
#include "stdafx.h"
#include "Webcam.h"
Webcam::Webcam(const LPCWSTR WindowName = L"", HWND ParentWnd = 0, int left
= 0, int top = 0,
int width = 0, int height = 0, DWORD style = WS_CHILD | WS_VISIBLE, int
webCamId = 0)
{
hModDllAviCap = NULL;
hModDllAviCap = LoadLibrary(L"AVICAP32.DLL");
if (hModDllAviCap)
{ // Here I am getting pointer to function I need "capCreateCaptureWindowW"
fpCapCreateCaptureWin = (CAPCAPWIN)GetProcAddress(hModDllAviCap,
"capCreateCaptureWindowW");
if (fpCapCreateCaptureWin)
{
CaptureWnd = (*fpCapCreateCaptureWin)(
WindowName, style, left, top, width, height, ParentWnd, webCamId);
}
}
}
Webcam::~Webcam()
{
CloseWindow(CaptureWnd);
CaptureWnd = NULL;
fpCapCreateCaptureWin = NULL;
FreeLibrary(hModDllAviCap);
hModDllAviCap = NULL;
}
bool Webcam::Connect()
{
LRESULT result = SendMessage(CaptureWnd, WM_CAP_DRIVER_CONNECT, 0, 0);
return (bool)result;
}
bool Webcam::Disconnect()
{
LRESULT result = SendMessage(CaptureWnd, WM_CAP_DRIVER_DISCONNECT, 0, 0);
return (bool)result;
}