473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
Apr 21 '06 #1
1 2523
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.
"Scott McFadden" <no**************@criticaltech.com> wrote in message
news:Ov**************@TK2MSFTNGP05.phx.gbl...
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

Apr 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
7
by: TJ | last post by:
In C# how do you achieve pass-by-reference property declarations in the Type Library? I am writing a COM Class Library that must mimick an existing library for which the only information is the...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
17
by: Peter Oliphant | last post by:
In the 'old days', we could create a pointer to an instance of a variable like so: int i = 58 ; int* i_ptr = &i ; int j = *i_ptr ; // j = 58 Now, in /clr how do we do the same? That is,...
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
2
by: gnassar | last post by:
I've been trying to learn dotnet myself though a bit of a basterdized know-how of dotnet 2003 and previous straight unix C++ programming. For some reason I have been able to get most of the...
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
11
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type...
9
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
0
BarryA
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.