Pelles C forum

C language => Expert questions => Topic started by: TimoVJL on August 28, 2021, 04:02:18 PM

Title: Net interface from C
Post by: TimoVJL 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
Title: Re: Net interface from C
Post by: frankie 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.
Title: Re: Net interface from C
Post by: frankie 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.  ;)
Title: Re: Net interface from C
Post by: John Z 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
Title: Re: Net interface from C
Post by: TimoVJL 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.
Title: Re: Net interface from C
Post by: bitcoin 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?