Using C# (and .NET) from FWH not working(?)
Re: Using C# (and .NET) from FWH not working(?)
But, Is it really working with harbour ?
The test of Ricardo didn't work until now "
The test of Ricardo didn't work until now "
Re: Using C# (and .NET) from FWH not working(?)
hello,
I tryed the dotnet sample, what I get is:
I tryed the dotnet sample, what I get is:
Code: Select all | Expand
┌────────────────────────────────────────────────────────────────────────────┐
?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 *
Re: Using C# (and .NET) from FWH not working(?)
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 | Expand
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 | Expand
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 | Expand
#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.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: Using C# (and .NET) from FWH not working(?)
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
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
Re: Using C# (and .NET) from FWH not working(?)
hi,
i have a DotNet DLL as AktiveX with IDispatch Interface using with Xbase++
perhaps this Concept help your with you DotNet DLL
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 | Expand
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
Jimmy
Re: Using C# (and .NET) from FWH not working(?)
+1
AntoninoP wrote:hello,
I tryed the dotnet sample, what I get is:Code: Select all | Expand
┌────────────────────────────────────────────────────────────────────────────┐
?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 & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Re: Using C# (and .NET) from FWH not working(?)
Hi,
Where is TDotNet class?
Where is TDotNet class?
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Re: Using C# (and .NET) from FWH not working(?)
Not published. Is in libs of Fwh
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: Using C# (and .NET) from FWH not working(?)
cnavarro wrote:Not published. Is in libs of Fwh
Hi Mr. Navarro,
Can you help me to compile with msvc?
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Re: Using C# (and .NET) from FWH not working(?)
What do you need?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: Using C# (and .NET) from FWH not working(?)
I was able to call .net code from harbour using Visual studio compiler, creating a C++ CLR project with managed code using HB_FUNC
this code calls a dll I made with a class and a method "ShowDialog"
Code: Select all | Expand
#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"
- Antonio Linares
- Site Admin
- Posts: 42553
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 80 times
- Contact:
Re: Using C# (and .NET) from FWH not working(?)
Antonino,
thats great!
Are you able to build it using hbmk2 ?
thats great!

Are you able to build it using hbmk2 ?
Re: Using C# (and .NET) from FWH not working(?)
I did not try, I used Visual studio. Maybe it is enough add /clr and some include... on property I see these options:
for C++. and:
for linker
Code: Select all | Expand
/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
Code: Select all | Expand
/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
Re: Using C# (and .NET) from FWH not working(?)
cnavarro wrote:Not published. Is in libs of Fwh
Code: Select all | Expand
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ 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: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLSID_CLRMETAHOST
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_IID_ICLRMETAHOST
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRMETAHOSTGETRUNTIME
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEINFOGETINTERFACE
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEHOSTSTART
FiveH32.lib(DOTNET_.obj) : error LNK2001: ‡”zmlenmemiŸ dŸ sembol _HB_FUN_CLRRUNTIMEHOSTEXECUTE
dotnet2.exe : fatal error LNK1120: 6 ‡”zmlenmemiŸ dŸlar
* Linking errors *
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04