Assigning address of a variable in VC# to one in VC++


I have a VC#.NET DLL (Visual Studio 2005), which runs a simple UDP server. It receives position updates from the client, and sends images from a folder in real-time accordingly. I have added this DLL to a virtual 3D enviornment, written in VC++.NET (Visual Studio 2005).

This images being sent to the client are created,rendered and stored by the VC++ application. Hence, when the DLL receives the updates from the client, it has to inform the VC++ application to render and save the required image at the required position.

Initially I had a public variable in the DLL, which was set to true when an update was received. I was creating an instance of the DLL class in VC++ application and checking the DLL variable in a while(true) loop (within a thread). Even though this operation was taking place in a thread, it really slowed the server down (I have no idea why this was happening).

So, I decided to remove the thread. I wrote the following function in VC#, which returns the address of the variable.

[code] public unsafe int* ReturnAddressPositionUpdate()
fixed(int* ReturnValue = &ReceivedPositionUpdate)
return ReturnValue;


I am calling this function from the VC++ code as:

[code]NewPosition =c->ReturnAddressPositionUpdate();[/code]

(where c is the instance of the VC# class, and NewPosition is the local VC++ variable, both are declared as int)

When I debug the code, I get the same address for both the variables( that is, the one in VC# and the one in VC++), yet when the variable is updated by VC# client, the if(*NewPosition != 0) statement in VC++ does not detect the update (The if () statement is being called recursively, so it keeps on checking, yet it never detects the updated variable value, yet during debug the value does get updated in VC#).

Kindly help me out here.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!