Jump to content

[c++] SafeArray Help


Recommended Posts

I am trying to get some data out of a SafeArray using Visual C++ 6.0 and am having some problems.

I found an article on microsoft's website (http://support.microsoft.com/kb/167668/EN-US/) to convert a VARIANT type to a SafeArray and then get the upper and lower bounds to iterate through the array getting each element, which is what I want to do. However it throws and unhandled exception (OLEAUT32.DLL): Access Violation. When debugging through my code this exception happens at the line:

hr = SafeArrayGetLBound(psa, 1, &lLBound);

Here is a larger snippet of surrounding code:

SAFEARRAY FAR* psa = NULL;
BSTR HUGEP *pbstr;
long lLBound, lUBound, cElements;
psa = V_ARRAY(&(IQuery->Response));
hr = SafeArrayGetLBound(psa, 1, &lLBound);
hr = SafeArrayGetUBound(psa, 1, &lUBound);
hr = SafeArrayAccessData(psa, (void HUGEP* FAR*)&pbstr);
cElements = lUBound - lLBound + 1;
for (long i = 0; i < cElements-1; i++) { ... }

Why is this throwing an exception?

Is there a better way to get the data out of the safearray than this?

Thanks

Link to comment
Share on other sites


That is how the data is stored in the IQuery->Response object, as a SafeArray. If there is a better way to get the data out then I'm open to it.

Using C# I know how to get the data out, but that is not an option here. I have to use C++ in Visual Studio 6.0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...