I have an issue with my WinForms project which was created in VS2005 .NET Framework 2.0, which I just upgraded to VS2012 .NET Framework 4.5. In my project, I used a third-party DLL by DllImport
and used its functions as I had all documentation for them.
The problem is one of the functions in the imported DLL which works fine in VS2005 .NET Framework 2.0 is not working in VS2012 .NET 4.5.
Following are my code snippets from my project:
[DllImport("W5EditLD.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "K5GetClassName")]
public static extern string GetClassName();//Dll import definition
public string _GetClassName()
{
return GetClassName();//wrapper function to DLL import function
}
string sClassName = _GetClassName();//where i call API via wrapper method,**
Above code snippet works fine in VS2005 .NET Framework 2.0 But when I upgraded my project to VS2012 .NET Framework 4.5 I have to do it in the following way:
[DllImport("W5EditLD.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "K5GetClassName")]
public static extern IntPtr GetClassName();//Dll import definition
public IntPtr _GetClassName()
{
return GetClassName();//wrapper function to DLL import function
}
IntPtr ptr = _GetClassName();//where i call API via wrapper method,
string sClassName = System.Runtime.InteropServices.Marshal. PtrToStringAnsi(ptr);
Why this is? Is automatic string marshalling not supported in VS2012 .NET Framework 4.5?