NO

Author Topic: Net interface from C  (Read 9383 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Net interface from C
« on: August 28, 2021, 04:02:18 PM »
We have to test this:
https://codingvision.net/calling-a-c-method-from-c-c-native-process

It's also an example to test poide debugging.

EDIT:
Example with MetaHostMin.h and libs and test_dll
« Last Edit: August 29, 2021, 09:02:59 AM by TimoVJL »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Net interface from C
« Reply #1 on: August 28, 2021, 06:45:23 PM »
Hello Timo, this seems interesting.
I have compiled and run it. I got an error 0x80070002 ==> "File not found". I think this refers to the random.dll with the managed code.
I'm too annoyed to compile also the managed right now, but when in mood I'll look for useful codes to run.

Ok I was too curious to see, so I created the DLL and ... it works. That's all.
Now I'll relax, then I'll think to something useful...  ;)

For those who want test it I attach a version compatible with PellesC V11.
« Last Edit: August 28, 2021, 11:12:09 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Net interface from C
« Reply #2 on: August 29, 2021, 01:29:38 PM »
A hint: replace
Code: [Select]
       if (pMetaHost->lpVtbl->GetRuntime(pMetaHost, L"v4.0.30319", &IID_ICLRRuntimeInfo, (LPVOID*)&pRuntimeInfo) == S_OK) {
with:
Code: [Select]
wchar_t pwszVersion[256];
DWORD   pcchVersion = 256;
if (pMetaHost->lpVtbl->GetVersionFromFile(pMetaHost, DLL_TO_RUN, pwszVersion, &pcchVersion) != S_OK)
{
printf("error: .NET version unavailable.\n");
return (1);
}
printf("Managed code will be run under .NET %ls.\n", pwszVersion);
       if (pMetaHost->lpVtbl->GetRuntime(pMetaHost, pwszVersion, &IID_ICLRRuntimeInfo, (LPVOID*)&pRuntimeInfo) == S_OK) {
This to assure to use the correct runtime version for the assembly.  ;)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Net interface from C
« Reply #3 on: August 29, 2021, 03:35:21 PM »
Checking for understanding  - Is this providing a similar capability to Frankie's fGdiPlusFlat.h for C to use C++ GDI features, in that this allows standard C calls to access system capabilities built for .NET programing ?  So having .NET becomes a little less worthless consumer of my bandwidth and hard disk space  :)

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Net interface from C
« Reply #4 on: August 29, 2021, 04:20:20 PM »
fSDK gives those include / lib for building those examples.

For example, oracle have Oracle.ManagedDataAccess.dll for database connections, dll size is less that 4 Mb and with it is possible to connect to database.
An native oracle libs are from hell, size is horrible, worst database client in the world.
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: Net interface from C
« Reply #5 on: September 02, 2021, 10:04:23 PM »
TimoVJL, thank you, this is very interesting.
But I can't understand - can I use powershell from C ? Or what? C# programs?