Hi!
Quote:
> First, make sure that you are not in the following situations:
> - VB Activex is in one process, the ATL activeX in another
Not, they are in one process. The process calls for ATL activeX that itself
creates instance of VB ActiveX.
Quote:
> - the callback is not class member pointer (and you do not
> have the 'this' pointer)
The callback is just function
Quote:
> - your objects live long enough to complete the call
I hope :-). At least I do not destroys them explicitly
Quote:
> - are you passing a pointer to the VB object or the pointer to an
> interface that you defined ?
I'm creating a class wrapper for VB activeX from a type library and passing
pointer to it.
Quote:
> More information needed for a better newsgroup debugging !
Now some pieces of code:
DLL: =====================================================
BOOL _stdcall InitCB(PCBStruct pCB)
{
HANDLE hThread;
g_bTerminate=FALSE;
hThread=CreateThread(NULL,0,MyThreadProc,(LPVOID)pCB,0,NULL);
if(!hThread)
return FALSE;
return TRUE;
Quote:
}
DWORD WINAPI MyThreadProc(LPVOID lpvParam)
{
PCBStruct pCB;
VB* pVB;// pointer to class that is wrapper of VB ActiveX
TCBFunction fCB;
pCB=(PCBStruct)lpvParam;
pVB=pCB->pVB; //pointer to VB ActiveX instance
fCB=pCB->fCB; //callback function located in ATL ActiveX
do {
fCB(pVB);
Sleep(1000);
}
while(!g_bTerminate);
return 1;
Quote:
}
End of DLL =======================================================
ATL ActiveX====================================================
//ATL ActiveX class definition
class CATL_MFC_AX {
...
public VB m_VB //instance of VB activeX
Quote:
}
typedef int (_stdcall *TInitCB)(PCBStruct pCB);
//Callback function
void _stdcall MyCB(VB* pVB)
{
pVB->Foo(); //CRASH!!!! Pointer to Foo is corrupted!
Quote:
}
STDMETHODIMP CATL_MFC_AX::Initialize()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
g_hLib=LoadLibrary("MyDLL.dll");
if(g_hLib){
g_fInitCB=(TInitCB)GetProcAddress(g_hLib,"InitCB");
if(!g_fInitCB)
MessageBox(NULL,"Failed to GetProcAddress.
InitCB","ATL_AX",MB_OK);
else {
COleException e;
CLSID clsid;
if (CLSIDFromProgID(OLESTR("VBObj.A"), &clsid) != NOERROR)
{
AfxMessageBox("UNABLE 2 CLSIDFromProgID");
return S_FALSE;
}
// try to get the active VB activeX before creating a new one
LPUNKNOWN lpUnk;
LPDISPATCH lpDispatch;
if (GetActiveObject(clsid, NULL, &lpUnk) == NOERROR)
{
HRESULT hr = lpUnk->QueryInterface(IID_IDispatch,(LPVOID*)&lpDispatch);
lpUnk->Release();
if (hr == NOERROR)
m_VB.AttachDispatch(lpDispatch, TRUE);
}
// if not dispatch ptr attached yet, need to create one
if (m_VB.m_lpDispatch == NULL &&
!m_VB.CreateDispatch(clsid, &e))
{
AfxMessageBox("UNABLE_TO_CREATE");
return S_FALSE;
}
AfxMessageBox("Inside Initialize");
m_VB.Foo();//WORKING HERE!
TCBStruct cb;
cb.fCB=MyCB;
cb.pVB=&m_VB;
g_fInitCB(&cb);
}
}
else
MessageBox(NULL,"Failed to LoadLibrary","ATL_AX",MB_OK);
return S_OK;
Quote:
}
End of ATL ActiveX =======================================================
Main VB process ====================================================
.......
Dim MyATL As Object
Set MyATL = CreateObject("ATLObject.A")
MyATL.Initialize
'Crash
MyAtl.SomeFunction
...........
End of Main VB process ====================================================
Comment :
As I just said, I tried to pass pVB using many ways - global variable,
Memory mapped files etc.
Quote:
> > Hi, ALL!
> > Please help me with solving the following problem:
> > I have :
> > - Some DLL written on plain C
> > - VB ActiveX that is intended to work with database
> > - ATL ActiveX that should wrap the DLL and provide him some
> > callbacks.
> > ATL ActiveX has a special method Initialize, that makes some specific
> > work and passes to the DLL pointer to a callback.
> > The callback should call some VB ActiveX method.
> > I can successfuly create instance of VB ActiveX in Initialize function
> > of ATL ActiveX by wrapping VB type library and using appropriate
> methods
> > of COleDispatchDriver (such as AttachDispatch, CreateDispatch etc.).
> > But when I'm trying to pass a pointer to VB ActiveX instance to
> > callback (through call to DLL, global variable, memory mapped file or
> > whatever)- it is arriving in a non-consistent form. (i.e., calls to
> > methods cause page faults).
> > When I tried to create VB ActiveX instance in callback function "on
> > place", I succeeded to make it 3-4 time and after that I get error
> > messages.
> > Thanks in advance.
> > Your help will be very appreciated!
> Sent via Deja.com http://www.deja.com/
> Before you buy.