Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAFEARRAY problems

Status
Not open for further replies.

johnstv4

Programmer
Aug 20, 2002
7
0
0
GB
Hi Everyone,

I'm having some major problems using SAFEARRAYS. I have an MFC client which communicates with DLL server within the context of a bank system. One of the functions it has is that when a customer's name is selected from a listbox the client communicates with the server to see which account objects are associated with the specific customer object and displays them in a seperate list box. The function that does is:


void CClientDlg::OnSelchangeListCustomer()
{
// Clear the list box
m_lstAccount.ResetContent();

UpdateData(TRUE);

//HRESULT hr;
ICustomerPtr pCustomer;
IAccountPtr pAccount;
BSTR account_number = NULL;
BSTR name = NULL;
CString str = _T("");

// Get the customer object
m_lstCustomer.GetText(m_lstCustomer.GetCurSel(),str);
name = str.AllocSysString();
pCustomer = (IDispatchPtr) pBankSystem->find_customer(name);
if (FAILED(pCustomer))
{
AfxMessageBox("Error");
}
::SysFreeString(name);

_variant_t var = pCustomer->retrieve_account_list();

SAFEARRAY *psa = NULL;
psa = var.parray;
LPDISPATCH * dispatchArray;
SafeArrayAccessData(psa,reinterpret_cast<void **>(&dispatchArray));

for (long i = 0; i < psa->rgsabound->cElements; i++)
{
pAccount = (IDispatchPtr) dispatchArray;
pAccount->get_account_number(&account_number);
CString an(account_number == NULL ? L&quot;&quot; : account_number);
m_lstAccount.AddString(an);
::SysFreeString(account_number);
an = _T(&quot;&quot;);
}

SafeArrayUnaccessData(psa);

UpdateData(FALSE);
}


No matter how many customers are in the customer listbox, whenever a name is selected the correct number of account names are displayed in the account listbox. The problem is, however, that when you select different customer names after the 5th or 6th selection the client crashes? The following is displayed:


First-chance exception in client.exe (OLEAUT32.DLL): 0xC0000005: Access Violation.


Does anyone know whats going on? Help is very much appreciated.


Thanks

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top