-1

I'm trying to build a 64-bit application using Visual Studio in C++

I need to access Sens.dll in Windows directory. Since Visual Studio is a 32-bit application, I have to use SysNative instead of System32

#import "C:/Windows/SysNative/Sens.dll"

because of File System Redirection.

If I change the path to C:/Windows/System32/Sens.dll, Visual Studio cannot access it since it redirects to SysWOW64 while building. To mitigate this I can use SysNative but then the executable built is a 64-bit application and SysNative is inaccessible.

Is there any way to solve it?

A better explanation of SysNative is given in File System Redirector

phuclv
  • 37,963
  • 15
  • 156
  • 475
Yogesh Kumar
  • 29
  • 1
  • 8
  • Where are the paths used? I don't see how the path in VS config and path in your app related to each other because they must be set separately. And don't link to external resources like that. Link to the [official documentation](https://learn.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector) instead – phuclv Dec 10 '19 at 04:34
  • I'm trying to import Sens.dll These paths are used as `#import "C:/windows/system32/sens.dll"` – Yogesh Kumar Dec 10 '19 at 04:40
  • that still doesn't explain how the paths relate to each other. If you're loading the DLL manually then VS doesn't read the path in your code. If you let Windows load the DLL automatically then your app knows nothing about the DLL path (and it doesn't need to know that). You need to show the real setup – phuclv Dec 10 '19 at 04:43
  • 2
    Using sysnative is just fine, the #import directive only has an affect at compile-time. So your real problem has nothing to do with it, whatever it might be. – Hans Passant Dec 10 '19 at 11:28

2 Answers2

-1

Don't import with absolute paths like this

#import "C:/windows/system32/sens.dll"

You should only use relative paths when using include, using or import. Add the path to the lookup list in project settings instead and then just #import "sens.dll"

In this case the DLL is in System32 so just add $(SystemRoot)\SysNative to Additional Include Directories

phuclv
  • 37,963
  • 15
  • 156
  • 475
-1

Accoreding to the #import directive

Syntax:

#import "filename" [attributes]

#import <filename> [attributes]

We couldn't directly import using absolute paths. I suggest you could try to use the following steps:

  1. Search where sens.dll is present in your code base or c:

    C:\Windows\System32

  2. When you find any path in step 1, and then you should add that path to Additional Library Directories of Your Project.

    Right Click on Project > Configuration Properties > Linker > General > Additional Library Directories. Add the path to Additional Library Directories

phuclv
  • 37,963
  • 15
  • 156
  • 475
Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • I suggest you could try to open the DLL in Visual Studio (simply with File | Open | File, it will open in Resource Editor by default) and see whether or not the TYPELIB resource is present. For more details I suggest you could refer to the link:https://stackoverflow.com/questions/10031875/cant-import-dll-in-c-application – Jeaninez - MSFT Dec 10 '19 at 07:30
  • the issue is not with DLL or import path. The issue is Visual Studio being 32 bit and the application I'm making is 64 bit. Read the question **Since Visual Studio is 32 bit application, I have to use SysNative instead of System32 but SysNative is invisible to 64 bit applications** – Yogesh Kumar Dec 10 '19 at 10:23
  • 2
    "SysNative" isn't a real directory. It gets redirected to the real "System32" directory by the WOW64 emulation system. Only 32-bit applications running on 64-bit Windows via WOW64 can use this virtual directory. If you want to build a 64-bit application using Visual Studio in C++. I suggest you could refer to the link:https://learn.microsoft.com/en-us/cpp/build/how-to-configure-visual-cpp-projects-to-target-64-bit-platforms?view=vs-2019 – Jeaninez - MSFT Dec 12 '19 at 08:06