I am making a DLL "Plugin" for a EXE. The EXE calls a function in the DLL with an Object as a parameter, and goes from there.
It all works fine and dandy until I split it to a new thread. This error happens
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
when executing this code on the object in the new thread:
protected object GetPropertyValue(object obj, string PropertyName)
{
return obj.GetType().InvokeMember(PropertyName, BindingFlags.GetProperty, null, obj, new object[] { });
}
The above is trying to access a property on a COM object. Changing the function to 'public' doesn't affect it. The code works just fine however if I'm using just one thread.
What's happening is clear: The new thread does not have access to the variable in the EXE. How can I fix this? Not using a thread is not a viable option.
Appreciate any help