proper way to pass pointers by reference from managed c++ methods to native c++ methods

S

Scott McFadden

What is the proper way to pass pointers by reference from managed c++ calls
to native c++ calls?

In managed C++, I have a pointer to an array of structures, that I pass to a
native c++ method by reference:

//Managed c++
QueryResult* qr = NULL;
ExecuteQuery(1, "abc", qr); //invoke native c++ method passing qr by
reference



//Native c++
void ExecuteQuery(int queryId, string queryParams, QueryResult*& results)
{
results = (QueryResult*)calloc(1000, sizeof(QueryResults));

//execute query against file system and populate results
}

My problem is that QueryResults is valid / populated in the context of
Native code dll (ExecuteQuery) but upon the return of that call into Managed
C++, the qr / QueryResults param is NULL. Anyone else have this prob?

thanks

sm
 
S

Scott McFadden

Here is a follow up of what I found. My original test was on Visual Studio
2003 with a mixed mode assembly calling into a native dll. The function in
the native dll allocated the memory to an array of structures as a reference
pointer param. The marshalling of the reference pointer param did not work
on Visual Studio 2003. I tried the same code on Visual Studio 2005 and it
worked flawlessly. So apparently, Visual Studio 2005 has corrected some
marshalling issues found in Visual Studio 2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top