Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have written JvmConnector to launch JVM to execute codes in some jar packages.
Here is my project on SourceForge.
However I don't know how to transport variable pointer directly to unmanaged functions.
I try the code:
[DllImport("xxx")]
public static extern void yyy(ref int addr, object x);

And in xxx.dll:
void yyy(int* addr, int* x) {*addr=(int)x;}

But it works strangely.
Though I know there is a dynamic memory world in C#, I think it must have a way to get address of variable, because it is really stored in memory.
And could you help me?
Thank you.
Posted

Checkout references to pinned memory and unsafe mode in C#. There is probably a CodeProject article on the subject.
 
Share this answer
 
You may already know Marshal Class[^] and Interop services for C#. Also try to take a look at http://pinvoke.net/[^] - Perhaps you can find you can finde inspiration ?

Have look at Pointer types (C# Programming Guide)[^] ?
 
Share this answer
 
v3
Comments
dna2codeproject 1-May-11 3:11am    
Thank you for your answer. However Marshal just helps me to copy all data to memory and then I get an IntPtr to handle them. But I really want to know how to get a pointer to my data(not the duplicated one) in IL virtual machine directly...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900