question

StefanoMora-1017 avatar image
0 Votes"
StefanoMora-1017 asked StefanoMora-1017 answered

C# GetProcAddress returns null without explorer process

Hi all,
I'm writing a .NET Core3.1 app that needs to load a native C DLL by LoadLibrary and GetProcAddress functions.
Usually it correctly runs but if I run it on the final machine I need to run it instead of explorer process cause the machine is a Kiosk.
In this configuration the GetProcAddress function returns null for the function pointers. If I launch explorer the application is ok.

Which is the reason of this behavior?
How can I solve on the final machine?

Thanks, regards

dotnet-csharp
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you check if LoadLibrary failed too?


0 Votes 0 ·

Yes, there is a check on return value of LoadLibrary and it is ok.

0 Votes 0 ·

What was the error code (GetLastError) after GetProcAddress failed?

0 Votes 0 ·

1 Answer

StefanoMora-1017 avatar image
0 Votes"
StefanoMora-1017 answered

Hello,
I solved the problem with your helps.

The GetLastError fn returned 127 = ERROR_PROC_NOT_FOUND.
This was caused basically by the hModule (returned by LoadLibrary fn) = 0.
The C# code checked the hModule value against null instead of IntPtr.Zero so it guessed that it was a good value.

The main reason of the null value was that the System.IO.Directory.GetCurrentDirectory() call (I use to build the absolute DLL path) returns:
- the current directory when I directly run the program
- c:\windows\system32\ when the program is run automatically by the registry key
So I substituted it with System.AppDomain.CurrentDomain.BaseDirectory property

Thanks!





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.