Thank you Chris Tacke, but I didn't call the methods of the activex
class directly using P/Invoke, what I have said that I have developed a
WCE DLL to wrapp the activex then I call its exported methods by
P/Invoke.
Thank you Sergey. As I mentioned before I've already done what you have
asked. The problem now that when I call the DLL to create the control,
it failed causing the exception I mentioned before.
here is the code of the DLL function:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
MyActiveX m_Obiect;
extern "C" __declspec(dllexport) BOOL Initialize(HINSTANCE hInstance,
HWND hWnd, HWND *hWndCtrl, RECT* rectIn, BOOL bVisible)
{
RECT rect = { 0, 254, 240, 268 };
CWnd *wndParent = CWnd::FromHandle(hWnd);
try
{
hInstance = AfxGetInstanceHandle();
m_Obiect.Create(L"", WS_CHILD,rect, wndParent, IDC_PLAYER);
hWndCtrl = &m_Obiect.m_hWnd;
}
catch(...)
{
LPVOID lpMsgBuf;
DWORD err;
err = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK |
MB_ICONINFORMATION );
MessageBox( NULL, str, L"Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
The ActiveX(MyActiveX) Create function :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MyActiveX:CWnd
{
CLSID const& GetClsid()
{
static CLSID const clsid
= { 0x56d6f312, 0xb0f6, 0x11d0, { 0x94, 0xab, 0x0, 0x80, 0xc7, 0x4c,
0x7e, 0x95 } };
return clsid;
}
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect,
pParentWnd, nID,
pPersist, bStorage, bstrLicKey);
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Mangaed Code
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
[DllImport("MyWrapper.dll")]
private static extern int Initialize(IntPtr hInstance, IntPtr hWnd,
ref IntPtr hWndCtrl, IntPtr rect,
bool bVisible);