Using C# (and .NET) from FWH not working(?)

User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by vilian »

But, Is it really working with harbour ?
The test of Ricardo didn't work until now "
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by AntoninoP »

hello,
I tryed the dotnet sample, what I get is:

Code: Select all

┌────────────────────────────────────────────────────────────────────────────┐
?FiveWin for Harbour 19.09 (MSVC++) Sep. 2019     Harbour development power │▄
?(c) FiveTech 1993-2019 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘?
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀?
Compiling...
Harbour 3.2.0dev (r1711221033)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'dotnet.prg' and generating preprocessed output to 'dotnet.ppo'...
Lines 4947, Functions/Procedures 1
Generating C source output to 'dotnet.c'... Done.
Microsoft (R) C/C++ Optimizing Compiler versione 19.16.27034 per x86
Copyright (C) Microsoft Corporation. Tutti i diritti  sono riservati.

dotnet.c
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLSID_CLRMETAHOST non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_IID_ICLRMETAHOST non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRMETAHOSTGETRUNTIME non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEINFOGETINTERFACE non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEHOSTSTART non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEHOSTEXECUTE non risolto
dotnet.exe : fatal error LNK1120: 6 esterni non risolti
* Linking errors *
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by vilian »

I Think it's not working yet.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using C# (and .NET) from FWH not working(?)

Post by cnavarro »

vilian wrote:But, Is it really working with harbour ?
The test of Ricardo didn't work until now "
I used Borland 7 Compiler
Antonino, with VS you are right, not run now. I'm investigating why.
DotNet run OK for Harbour? YES
Can any function or method defined in a C # DLL be used? Yes, if all the requirements are met
What limitations do you currently have? It does not yet allow you to return values to Fivewin. He needs a little more work and I haven't had time to devote.
So how can I return a value? You can create a txt file with the value to return from C # and read it later from Fivewin. It is not the best but it is a possibility.

Let's see an example of usability
We create a .CS file that we will call for example datagrid0.cs

Code: Select all

using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;
using System.Data;
using System.Data.OleDb;

namespace conexion
{
    public class myGrid
    {
        public static int connectar( string a )
        {
             MessageBox.Show( a );
            string connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\fwh\\fwhteam\\samples\\xbrtest.mdb;";
            string sql = "SELECT * FROM Customer";
             MessageBox.Show( "String of connection and command sql" );

            OleDbConnection connection = new OleDbConnection(connetionString);
             MessageBox.Show( "Connection OK" );

            OleDbCommand command = new OleDbCommand(sql, connection);
            connection.Open();
             MessageBox.Show( "Open connection" );

            OleDbDataAdapter da = new OleDbDataAdapter(command);
            DataSet ds = new DataSet();
            da.Fill( ds, "Customers_table");
            MessageBox.Show( "Customer" );

            MessageBox.Show( ds.Tables[0].Rows[0]["First"].ToString() );
            connection.Close();
            return 0;

        }
    }
}
 
Now we execute the following command en un fichero .bat ( buildcs0.bat ).
I have commented on the first line because I use the link to the compiler console that you install when you install any version of Visual Studio
This way we don't depend on the compiler version of Visual Studio

Code: Select all

rem call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
csc /out:datagrid.dll /target:library datagrid0.cs
 
It's time to create our prg

Code: Select all

#include "FiveWin.ch"

Static cDll       := "datagrid.dll"
Static cWorkSpace := "conexion.myGrid"
Static cMethod    := "connectar"

//----------------------------------------------------------------------------//

function Main()

   local oNet

   oNet   := TDotNet():New()
   oNet:Execute( cDll, cWorkSpace, cMethod, "Conectar" )
   //? oNet:GetResult(), oNet:GetReturnValue(), oNet:GetValueReturn()

   ? oNet:GetNetError()
   oNet:End()

return nil

//----------------------------------------------------------------------------//
 
If everything went well, you should not return any errors.
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by AntoninoP »

I am doing it me own, I think on MSVC it is not possible include the support on the onnicomprensive FiveWin library, because the library needs to be linked with CLR support.
So I am creating a DLL that exposes the .NET interface, in a similar way to OLE support.
I still have some issue with pcode support, but current result are cheering
User avatar
Jimmy
Posts: 165
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Using C# (and .NET) from FWH not working(?)

Post by Jimmy »

hi,

i have a DotNet DLL as AktiveX with IDispatch Interface using with Xbase++
perhaps this Concept help your with you DotNet DLL

Code: Select all

using System; 
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyForm.AX
{
    [ProgId("MyForm.AX.Form1")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public partial class Form1x : System.Windows.Forms.UserControl
    {
        public Form1x()
        {
            InitializeComponent();
        }

        #region field definitions
        ...
        #region get-set Com-Controls

        public string text1
        {
            get { return this.textBox1.Text; }
            set { this.textBox1.Text = value; }
        }
        public string text2
        {
            get { return this.textBox2.Text; }
            set { this.textBox2.Text = value; }
        }
        public string text3
        {
            get { return this.textBox3.Text; }
            set { this.textBox3.Text = value; }
        }
        public string text4
        {
            get { return this.textBox4.Text; }
            set { this.textBox4.Text = value; }
        }
        public string text5
        {
            get { return this.textBox5.Text; }
            set { this.textBox5.Text = value; }
        }
        public bool check1
        {
            get { return this.checkBox1.Checked; }
            set { this.checkBox1.Checked = value; }
        }
        public string combo1
        {
            get { return this.comboBox1.Text; }
            set { this.comboBox1.Text = value; }
        }

        public string addItemCombo1
        {
            set { this.comboBox1.Items.Add(value);}
        }

        #endregion
        ...
 
greeting,
Jimmy
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Using C# (and .NET) from FWH not working(?)

Post by Horizon »

+1
AntoninoP wrote:hello,
I tryed the dotnet sample, what I get is:

Code: Select all

┌────────────────────────────────────────────────────────────────────────────┐
?FiveWin for Harbour 19.09 (MSVC++) Sep. 2019     Harbour development power │▄
?(c) FiveTech 1993-2019 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘?
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀?
Compiling...
Harbour 3.2.0dev (r1711221033)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'dotnet.prg' and generating preprocessed output to 'dotnet.ppo'...
Lines 4947, Functions/Procedures 1
Generating C source output to 'dotnet.c'... Done.
Microsoft (R) C/C++ Optimizing Compiler versione 19.16.27034 per x86
Copyright (C) Microsoft Corporation. Tutti i diritti  sono riservati.

dotnet.c
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLSID_CLRMETAHOST non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_IID_ICLRMETAHOST non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRMETAHOSTGETRUNTIME non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEINFOGETINTERFACE non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEHOSTSTART non risolto
FiveH32.lib(DOTNET_.obj) : error LNK2001: simbolo esterno _HB_FUN_CLRRUNTIMEHOSTEXECUTE non risolto
dotnet.exe : fatal error LNK1120: 6 esterni non risolti
* Linking errors *
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Using C# (and .NET) from FWH not working(?)

Post by Horizon »

Hi,

Where is TDotNet class?
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using C# (and .NET) from FWH not working(?)

Post by cnavarro »

Not published. Is in libs of Fwh
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Using C# (and .NET) from FWH not working(?)

Post by Horizon »

cnavarro wrote:Not published. Is in libs of Fwh
Hi Mr. Navarro,
Can you help me to compile with msvc?
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using C# (and .NET) from FWH not working(?)

Post by cnavarro »

What do you need?
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by AntoninoP »

I was able to call .net code from harbour using Visual studio compiler, creating a C++ CLR project with managed code using HB_FUNC

Code: Select all

#define WIN32_LEAN_AND_MEAN             // Escludere gli elementi usati raramente dalle intestazioni di Windows
// File di intestazione di Windows
#include <windows.h>
#include <objbase.h>

#include <hbapi.h>
#include <hbapierr.h>
#include <hbapiitm.h>
#include <hbinit.h>
#include <hbstack.h>
#include <hbvmpub.h>

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
using namespace System::IO;

// convert a .NET string to a C by using the Harbor memory manager
static char* FromString(String^ src);
// spawns a harbor error starting from a .NET one
static void HandleError(Exception^ e);

HB_FUNC(SHOWDIALOG) {
    try { //I did not check if the calls are successful, everything is taken from the catch and brought to harbor.
        CoInitializeEx(0, COINIT_APARTMENTTHREADED);
        // get the absolute path to the dll
        String^ dllPath = Path::GetFullPath(gcnew String(hb_parc(1)));
        // load it
        Assembly^ pDll = Assembly::LoadFile(dllPath);
        //Console::WriteLine(pDll ? "dll loaded" : "dll not loaded");
        // get the type 
        String ^typeName = gcnew String(hb_parc(2));
        Type^ objType = pDll->GetType(typeName);
        //Console::WriteLine(objType ? "type found" : "type not found");
        // instance it
        //Console::WriteLine(System::Threading::Thread::CurrentThread->ApartmentState);
        Object^ tmp = pDll->CreateInstance(typeName);
        //Console::WriteLine(tmp? "object created" : "object not object");
        // get the method
        MethodInfo^ showDlg = objType->GetMethod("ShowDialog");
        //Console::WriteLine(showDlg  ? "method found" : "method not found");
        // call it
        array<Object^>^ params = nullptr;
        //if (showDlg->GetParameters()->Length > 0) { TODO
        //  array<ParameterInfo^>^ pInfo = showDlg->GetParameters();
        //  int n = hb_pcount()-2;
        //  for (int i = 0; i < n; i++) {
        //
        //  }
        //}
        showDlg->Invoke(tmp, params);
        //Console::WriteLine("method called");
    }
    catch (Exception^ e) {
        // if all goes well it does not arrive here
        HandleError(e);
    }
    hb_ret();
}

static char* FromString(String^ src) {
    Text::Encoding^ ascii = Text::Encoding::ASCII;
    cli::array<unsigned char>^ bytes = ascii->GetBytes(src);
    char* dest = (char*)hb_xgrab(bytes->Length);
    Marshal::Copy(bytes, 0, IntPtr(dest), bytes->Length);
    return dest;
}

static void HandleError(Exception^ e) {
    if (e->InnerException)
        e = e->InnerException;
    PHB_ITEM pError = hb_errRT_New(ES_ERROR, "Net2HB", e->HResult, 0,
        FromString(e->Message),FromString(e->Source), 0, EF_NONE);
    if (hb_pcount() != 0) {
        /* HB_ERR_ARGS_BASEPARAMS */
        PHB_ITEM pArray = hb_arrayBaseParams();
        hb_errPutArgsArray(pError, pArray);
        hb_itemRelease(pArray);
    }
    hb_errPutFileName(e, FromString(e->StackTrace));
    hb_errLaunch(pError);
    hb_errRelease(pError);
}

#pragma unmanaged

// HB_FS_FIRST solo alla prima :)
HB_INIT_SYMBOLS_BEGIN(hb_vm_SymbolInit_Net2HB)
{ "SHOWDIALOG", { HB_FS_PUBLIC | HB_FS_FIRST | HB_FS_LOCAL }, { HB_FUNCNAME(SHOWDIALOG) }, NULL }
};
static PHB_SYMB symbols;
//HB_INIT_SYMBOLS_END(hb_vm_SymbolInit_Net2HB)


BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // handle to DLL module
    DWORD fdwReason,     // reason for calling function
    LPVOID lpReserved)  // reserved
{
    // Perform actions based on the reason for calling.
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        // in CLR static initialization does not work
        symbols = hb_vmProcessSymbols(symbols_table, (HB_USHORT)HB_INIT_SYMBOLS_COUNT, "", 0L, 0x0000);
        break;

        // case DLL_THREAD_ATTACH: // Do thread-specific initialization.
        //  break;
        // case DLL_THREAD_DETACH: // Do thread-specific cleanup.
        //  break;
        // case DLL_PROCESS_DETACH: // Perform any necessary cleanup.
        //  break;
    }
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}
this code calls a dll I made with a class and a method "ShowDialog"
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by Antonio Linares »

Antonino,

thats great! :-)

Are you able to build it using hbmk2 ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Using C# (and .NET) from FWH not working(?)

Post by AntoninoP »

I did not try, I used Visual studio. Maybe it is enough add /clr and some include... on property I see these options:

Code: Select all

/Yu"stdafx.h" /GS /W3 /Zc:wchar_t /I"c:\harbour\include" /Zi /Od /Fd"x64\Debug\vc142.pdb" /Zc:inline /fp:precise /D "HB_DYNLIB" /D "_DEBUG" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /clr /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll" /MDd /FC /Fa"x64\Debug\" /EHa /nologo /Fo"x64\Debug\" /Fp"x64\Debug\DotNetCaller.pch" /diagnostics:column
for C++. and:

Code: Select all

/OUT:"C:\TL\TLPosWin\DotNetCaller\x64\Debug\DotNetCaller.dll" /MANIFEST /NXCOMPAT /PDB:"C:\TL\TLPosWin\DotNetCaller\x64\Debug\DotNetCaller.pdb" /DYNAMICBASE "hbmainstd.lib" "hbmainwin.lib" "hbcplr.lib" "harbour-32.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /FIXED:NO /DEBUG:FULL /DLL /MACHINE:X64 /INCREMENTAL /PGD:"C:\TL\TLPosWin\DotNetCaller\x64\Debug\DotNetCaller.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\DotNetCaller.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Harbour64\lib\win\msvc64" /ASSEMBLYDEBUG /TLBID:1
for linker
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Using C# (and .NET) from FWH not working(?)

Post by Horizon »

cnavarro wrote:Not published. Is in libs of Fwh

Code: Select all

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ FiveWin for Harbour 20.06 (VS32bits) Jun. 2020  Harbour development power  ³Ü
³ (c) FiveTech 1993-2020 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 ³Û
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.3
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
Compiling...
Harbour 3.2.0dev (r1904111533)
Copyright (c) 1999-2019, https://harbour.github.io/
Compiling 'dotnet2.prg' and generating preprocessed output to 'dotnet2.ppo'...

Lines 4957, Functions/Procedures 1
Generating C source output to 'dotnet2.c'... Done.
dotnet2.c
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLSID_CLRMETAHOST
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_IID_ICLRMETAHOST
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRMETAHOSTGETRUNTIME
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEINFOGETINTERFACE
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEHOSTSTART
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEHOSTEXECUTE
dotnet2.exe : fatal error LNK1120: 6 ‡”zmlenmemiŸ dŸlar
* Linking errors *
 
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
Post Reply