I got Issues when I call unmanaged resource functions from C#.net core DLL into VB.net core windows application. The program execution just stops suddenly when the function is hit.
Please below is my code
DLL Unmanaged function
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace TestLibrary1
{
public class Class1
{
[UnmanagedCallersOnlyAttribute]
public static IntPtr AddNE(IntPtr a)
{
try
{
IntPtr add = a;
return add;
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
return (IntPtr)0;
}
}
}
VB.netcore windows code below to call dll
Imports System.Runtime.InteropServices
Imports Google.Apis.Calendar.v3.Data
Public Class Form1
Private Const DllName As String = "TestLibrary1NE.dll"
<DllImport(DllName)>
Private Shared Function AddNE(ByVal a As IntPtr) As IntPtr
End Function
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Try
Dim ptrAddress As IntPtr = Marshal.StringToHGlobalAnsi(txtAddress.Text.Trim())
Dim ptrResponse As IntPtr = AddNE(ptrAddress)
Dim strResponse As String = Marshal.PtrToStringAnsi(ptrResponse)
MessageBox.Show(strResponse)
Catch ex As EntryPointNotFoundException
Console.WriteLine(e.ToString())
End Try
End
End Sub
End Class
When the function AddNE (from the C# DLL) above is hit it suddenly stops the execution from nowhere.
May I know what is the solution to fix this and how to find out the error?