Hello All
i have been trying to write a simple DLL in FB but was not successful
the below DLL was working ok in oxygenbasic but not in FB
#include once "windows.bi"
extern "Windows-MS"
'declare Function RetString(stwant as string) as string
'end RetString(null)
'========================================
' Returns a wanted string back to a c# calling program
' Note that do NOT change string to any other type
Function RetString alias "RetString"(stwant as string) as string export
If LCASE(TRIM(stwant)) = "one" then
return "First string (one) was entered"
else
return " Other string was entered"
end if
end function
end extern
Each time C# calling program will return error message "DLL entry point not found"
so i tried using DECLARE statement and again no success
tried using EXTERN also not successful
and lastly tried using ALIAS also not successful
How to resolve this program.
The below is the C# calling program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// need this to run DllImport
using System.Runtime.InteropServices;
namespace GitO2Data
{
public partial class Form1 : Form
{
// Note that this program is compiled to 64 bits while its FB dlls are also compiled to 64 bits
// setup the DLLs
[DllImport("DllFirst.DLL", EntryPoint = "RetString")]
[return: MarshalAs(UnmanagedType.AnsiBStr)]
public static extern string RetString([MarshalAs(UnmanagedType.AnsiBStr)]
ref string Seltxt);
// reference https://stackoverflow.com/questions/16332701/how-to-call-c-dll-in-c-sharp
[DllImport("Greet.dll", EntryPoint = "greet")]
public static extern int greet(string rfst);
public Form1()
{
InitializeComponent();
}
// Button to get Message from an FB DLL
private void button1_Click(object sender, EventArgs e)
{
// display the greeting
string txtmynam = "Good Man";
int dummynum = greet(txtmynam);
MessageBox.Show(" number from FB : " + dummynum.ToString() );
}
// Button to get a string from an FB DLL
private void button2_Click(object sender, EventArgs e)
{
string txtReturn = "";
// Obtain the entered text
string EnterText = textBox1.Text.Trim();
// get the return string
txtReturn = RetString(ref EnterText);
// Display the return string on the screen
MessageBox.Show(" String from FB dll : " + txtReturn);
}
}
}