I'm attempting to access a function in a DLL in C# and C++.
C++ is working fine, as is C# on WinXP. However I'm getting the following error when attempting to access the function on a Win2k8 system:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory
is corrupt.
at Router.GetAddress()
The declaration in C# is:
[DllImport("Constants.dll")]
static extern String GetAddress();
Usage in C# (at the moment) is just outputting it:
Console.WriteLine(GetAddress());
And the contents of the DLL's function are just:
const static WCHAR* szAddress= L"net.tcp://localhost:4502/TestAddress";
extern "C" __declspec(dllexport) const WCHAR* GetAddress()
{
return szAddress;
}
I really didn't think there was anything controversial here. The only thing I can think of is the const return from GetAddress, but I'm not sure how to apply the corresponding keyword to C# as I'm not as familiar with that language yet.
Any suggestions would be greatly appreciated.