Closed Giacomo-dev-78 closed 4 years ago
Hello @Giacomo-dev-78,
can you show me a sample of your code?
Kind regards
Hello @Giacomo-dev-78,
can you show me a sample of your code?
Kind regards
Hi zalintyre,
thank you for your reply.
let me put a foreword. Im working on a UWP project on 64bit (and windows 10 64bit) and i'm facing an issue with a driver that seems to be 32bit only. When i try to exploit dll methods with dllimport i get a BadImageFormatException. I already tried a lot of workarounds but no luck. that said, i'm attaching that chuck of code. I already found a wrapper for that driver, but works if you are on x86. So my aim is to follow along what the wrapper does, and use LegacyWrapper to get the result.
Unfortunately i get that file not found exception.
Hello @Giacomo-dev-78,
I'm glad your usecase is exactly what LegacyWrapper was built for! :)
You're importing the custom dll uuirtdrv.dll
. Everything that is not located in C:\Windows\system32
has to be imported using an absolute path or a path relative to your application executable.
Kind regards
Hello @Giacomo-dev-78,
I'm glad your usecase is exactly what LegacyWrapper was built for! :)
You're importing the custom dll
uuirtdrv.dll
. Everything that is not located inC:\Windows\system32
has to be imported using an absolute path or a path relative to your application executable.Kind regards
Hi zalintyre,
thanks. Can you please explain what you mean for imported in absolute/relative. Maybe i misunderstood but uuirtdrv.dll is in my C:\Windows\System32 , so i don't understand why it can't be imported.. I also thought it was an administrator matter, but even starting visual studio in admin mode, that dll is not found.
Thank you for your time. Kind Regards
Hello @Giacomo-dev-78,
it could be possible that only Windows system dll's can be found without the path. Can you try adding the C:\Windows\system32
path anyways?
As I suspected, Windows only loads known DLLs from the system32 folder. Please refer to this documentation: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications
As I suspected, Windows only loads known DLLs from the system32 folder. Please refer to this documentation: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications
Hello @zalintyre
yes, i saw that article. Anyway, with "usual" DllImport the driver dll is found. DllImport attribute seems not to be reserved to system dlls only. I'm starting to think there's something else. Trying with LegacyWrapper instead no dll is found, even those like User32 or other system libraries.
I'll follow your suggestion and try with some specific path.. fingers crossed. Keep you posted.
ah..if something else comes up in your mind about this issue, please let me know.
Thank you
hi @zalintyre ,
kein Glück, i always end in file not found. I copied the dll in bin I added the dll in project with content and always copy I specified [LegacyDllImport("C:\Windows\System32\uuirtdrv.dll")]
i'm running out of ideas..
Ok, some news.
I tried the same thing in another machine. Now it's all ok. Console app -> AnyCPU on 64bit OS
LegacyWrapper working like a charm. I can call driver functions as expected.
anyway, i found what is going wrong. I turned the console app project into a library. I created a new console app and referenced the library. When i call the same driver function, WrapperProxyFactory returns the famous exception for file not found (System.Component.Win32Exception).
Now i got figure out how to kill this new monster.
Thank you @zalintyre
update nr 2.. filenotfoundexception happens when nuget package is not installed on both projects. i.e. once i built the library and i reference it from a test console app, that test console app must have legacywrapper nuget package too...otherwise the filenotfoundexception is raised.
now struggling with other issues that are driving me mad...but that's another story.
bye @zalintyre
Glad that it works now! Feel free to open another issue if you have questions.
Hi,
maybe it's a stupid question but i can't figure this out.
i'm getting file not found exception when i try to call WrapperProxyFactory. From your samples i see that you specify User32.dll that is located in C:\Windows\System32.
My dll is placed there too since it's a driver.
What am i doing wrong?
thank you