Access violation trying to use ActiveX dll
-
Hi! I'm trying to use an ActiveX dll in my C++ program. The dll is written in VB (not by me), so I generated a h-file from the idl. Everything compiles, but when I run the test program I get an error at the line with a :confused: below. The code is really simple, but I don't know what is causing the error. Anyone familiar with what might be wrong here? Thanks...
void TestDlg::OnOK() { HRESULT hRes; _cTheObj *pTheObj = NULL; UpdateData(TRUE); // Init COM hRes = CoInitialize(0); if (SUCCEEDED(hRes)) { // Create object hRes = CoCreateInstance(CLSID_cTheObj, NULL, CLSCTX_INPROC_SERVER, IID__cTheObj, (LPVOID *)&pTheObj); if (SUCCEEDED(hRes)) { SHORT ret; VARIANT l1; VariantInit(&l1); l1.vt = VT_BSTR; l1.bstrVal = m_logon1.AllocSysString(); hRes = pTheObj->Logon(l1, &ret); :confused:
The definition of the Logon funcition in the h-file for the dll looks like:virtual /* [id] */ HRESULT STDMETHODCALLTYPE Logon( /* [in] */ VARIANT arg1, /* [in] */ VARIANT arg2, /* [in] */ VARIANT arg3, /* [retval][out] */ VARIANT_BOOL __RPC_FAR *__MIDL_0014) = 0;
Thanks for any help! -
Hi! I'm trying to use an ActiveX dll in my C++ program. The dll is written in VB (not by me), so I generated a h-file from the idl. Everything compiles, but when I run the test program I get an error at the line with a :confused: below. The code is really simple, but I don't know what is causing the error. Anyone familiar with what might be wrong here? Thanks...
void TestDlg::OnOK() { HRESULT hRes; _cTheObj *pTheObj = NULL; UpdateData(TRUE); // Init COM hRes = CoInitialize(0); if (SUCCEEDED(hRes)) { // Create object hRes = CoCreateInstance(CLSID_cTheObj, NULL, CLSCTX_INPROC_SERVER, IID__cTheObj, (LPVOID *)&pTheObj); if (SUCCEEDED(hRes)) { SHORT ret; VARIANT l1; VariantInit(&l1); l1.vt = VT_BSTR; l1.bstrVal = m_logon1.AllocSysString(); hRes = pTheObj->Logon(l1, &ret); :confused:
The definition of the Logon funcition in the h-file for the dll looks like:virtual /* [id] */ HRESULT STDMETHODCALLTYPE Logon( /* [in] */ VARIANT arg1, /* [in] */ VARIANT arg2, /* [in] */ VARIANT arg3, /* [retval][out] */ VARIANT_BOOL __RPC_FAR *__MIDL_0014) = 0;
Thanks for any help! -
Looks like you are only passing one argument where it is expecting 3, and looks like it might not be initialized, at that.