0

I tried many codes in internet for this but it says Access violation. Can somebody provide me the code snippets in C++ and C# for this?

2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by ddanbe
0

I have the c++ code in a dll file. Function in C++ is given below.

extern "C" __declspec(dllexport) string getString()
 {
	 string test;
	 test = "Hello";
	 return(test);
}

In C#

public class NativeMethods
{
 [DllImport("C++dll.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern string getString();

public static void Main()
    {
        
        Console.WriteLine("o/p{0}", getString());
        Console.ReadLine();

    }
}

Iam getting the error System.AccessViolationException:Attempted to read or write protected memory

Edited by meensatwork: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.