Hi all,
I've written a COM-Dll (with ATL) that holds a database of marathon
runners. I wrote a function that returns the needed information of all
runners and it works fine in VB but not in VB.NET. I'm using an array
of structs as a return value. Here's the code of the function:
*************************************************
const IID ResultUDT_IID = {... };
STDMETHODIMP CDatabase::ResultAll(SAFEARRAY **pResult)
{
t_Result *Results = NULL;
ResultUDT *pData = NULL;
if (!m_bResult)
{
HRESULT hr = Error( _T("No result available!") );
return hr;
}
IRecordInfo *pUdtRecordInfo = NULL;
HRESULT hr = ::GetRecordInfoFromGuids(LIBID_SOFTLib, 1, 0, 0,
ResultUDT_IID, &pUdtRecordInfo );
if (FAILED(hr))
{
HRESULT hr2 = Error( _T("Can not create RecordInfo interface
for ResultUDT") );
return hr;
}
int RecordsCnt = MyDB->Cnt();
Results = My->Result;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = RecordsCnt ;
*pResult = ::SafeArrayCreateEx( VT_RECORD, 1, rgsabound,
pUdtRecordInfo );
pUdtRecordInfo->Release();
if (*pResult == NULL)
{
HRESULT hr2 = Error( _T("Can not create array of ResultUDT
structures") );
return hr2;
}
hr = ::SafeArrayAccessData(*pResult, (void**)&pData);
if (FAILED(hr))
return( hr );
for (int i=0; i<RecordsCnt; i++, pData++)
{
pData->Pnr = Results[i].pnr;
pData->Score = Results[i].Score;
CComBSTR bstrID = MyDB->PersonInfo[Results[i].tnr].ID;
bstrID.CopyTo(&pData->ID);
CComBSTR bstrFilepath = Results[i].Filepath;
bstrFilepath.CopyTo(&pData->Filepath);
}
hr = ::SafeArrayUnaccessData(*pResult);
return hr;
}
*************************************************
In the idl.-File I defined my struct as:
*************************************************
typedef
[uuid(...),
helpstring("Result Structure")]
struct ResultUDT
{
int Pnr;
int Score;
BSTR ID;
BSTR Filepath;
} ResultUDT;
*************************************************
and my interface looks like that:
*************************************************
interface INet : IDispatch
{
[id(1), helpstring("Result")]
HRESULT Result([out, retval] SAFEARRAY(struct ResultUDT)
*pResult);
}
*************************************************
In VB I can use that function and it works fine:
*************************************************
Dim res() as ResultUDT
....
res = DB.Result(5)
txtName.text = res(0).ID
*************************************************
In VB.NET I have written the following code (which somehow needs the
lib-name SOFTLib in front of the struct):
*************************************************
Dim res() as SOFTLib.ResultUDT
....
res = DB.Result(5)
txtName.text = res(0).ID
*************************************************
and that always brings up "System.IndexOutOfRangeException" because my
array "res" has the length 0.
Any ideas to this problem?
Thanks
Michael 1 1119
In article <2d**************************@posting.google.com >, Michael wrote: Hi all,
I've written a COM-Dll (with ATL) that holds a database of marathon runners. I wrote a function that returns the needed information of all runners and it works fine in VB but not in VB.NET. I'm using an array of structs as a return value. Here's the code of the function:
*************************************************
const IID ResultUDT_IID = {... };
STDMETHODIMP CDatabase::ResultAll(SAFEARRAY **pResult) { t_Result *Results = NULL; ResultUDT *pData = NULL;
if (!m_bResult) { HRESULT hr = Error( _T("No result available!") ); return hr; }
IRecordInfo *pUdtRecordInfo = NULL; HRESULT hr = ::GetRecordInfoFromGuids(LIBID_SOFTLib, 1, 0, 0, ResultUDT_IID, &pUdtRecordInfo ); if (FAILED(hr)) { HRESULT hr2 = Error( _T("Can not create RecordInfo interface for ResultUDT") ); return hr; }
int RecordsCnt = MyDB->Cnt(); Results = My->Result;
SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = RecordsCnt ;
*pResult = ::SafeArrayCreateEx( VT_RECORD, 1, rgsabound, pUdtRecordInfo ); pUdtRecordInfo->Release(); if (*pResult == NULL) { HRESULT hr2 = Error( _T("Can not create array of ResultUDT structures") ); return hr2; }
hr = ::SafeArrayAccessData(*pResult, (void**)&pData); if (FAILED(hr)) return( hr );
for (int i=0; i<RecordsCnt; i++, pData++) { pData->Pnr = Results[i].pnr; pData->Score = Results[i].Score; CComBSTR bstrID = MyDB->PersonInfo[Results[i].tnr].ID; bstrID.CopyTo(&pData->ID); CComBSTR bstrFilepath = Results[i].Filepath; bstrFilepath.CopyTo(&pData->Filepath); }
hr = ::SafeArrayUnaccessData(*pResult); return hr; }
*************************************************
In the idl.-File I defined my struct as:
*************************************************
typedef [uuid(...), helpstring("Result Structure")] struct ResultUDT { int Pnr; int Score; BSTR ID; BSTR Filepath; } ResultUDT;
*************************************************
and my interface looks like that:
*************************************************
interface INet : IDispatch { [id(1), helpstring("Result")] HRESULT Result([out, retval] SAFEARRAY(struct ResultUDT) *pResult); }
*************************************************
In VB I can use that function and it works fine:
*************************************************
Dim res() as ResultUDT
...
res = DB.Result(5)
txtName.text = res(0).ID
*************************************************
In VB.NET I have written the following code (which somehow needs the lib-name SOFTLib in front of the struct):
*************************************************
Dim res() as SOFTLib.ResultUDT
...
res = DB.Result(5)
txtName.text = res(0).ID
*************************************************
and that always brings up "System.IndexOutOfRangeException" because my array "res" has the length 0.
Any ideas to this problem?
Thanks Michael
You might want to post this to the interop group. You might get a
better answer there.
--
Tom Shelton [MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Morten Gulbrandsen |
last post by:
mysql> USE company;
Database changed
mysql>
mysql> DROP TABLE IF EXISTS EMPLOYEE;
--------------
DROP TABLE IF EXISTS EMPLOYEE
--------------
Query OK, 0 rows affected (0.00 sec)
|
by: Sourin |
last post by:
Hi all,
I am trying to write code for my experiments. My work involves huge
datasets, and as such my code needs to be memory efficient. I did some
hand calculations regarding the amount of...
|
by: Bill |
last post by:
I would like to create a static array of classes (or structs) to be used in
populating name/value pairs in various WebForm drop down list boxes, but am
not quite sure of the construct (or rather to...
|
by: mrhicks |
last post by:
Hello all,
I need some advice/help on a particular problem I am having. I have
a basic struct called "indv_rpt_rply" that holds information for a
particular device in our system which I will...
|
by: Paminu |
last post by:
Why make an array of pointers to structs, when it is possible to just make
an array of structs?
I have this struct:
struct test {
int a;
int b;
|
by: Fahad Ashfaque |
last post by:
qaHi,
I am trying to assign value to a member of object of a struct, the object is
treated under foreach.
I got the error : error CS0170: Use of possibly unassigned field 'price'
according...
|
by: Brett |
last post by:
I have created a structure with five fields. I then create an array of this
type of structure and place the structure into an array element. Say index
one. I want to assign a value to field3 of...
|
by: Cliff Martin |
last post by:
Hi,
I am reading a fairly large file a line at a time, doing some
processing, and filtering out bits of the line. I am storing the
interesting information in a struct and then printing it out....
|
by: Ray Dillinger |
last post by:
Hi. I'm having a problem and I really want to understand it.
Here's the situation: I have an array of pointers, and each
pointer is the head of a linked list of structs. The structs
are...
|
by: dev_15 |
last post by:
Hi, I'm going through some code and thought that this allocates an
array of structs but its supposed according to comments to allocate an
array of pointer to structs. What does it actually do
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |