0

I am quite new in visual studio c++ and im trying to import a file from a different directory using:

#import "*file directory*\filename"

I didnt have any problem during my first build check. But after I added a blank header file in the project, the error suddenly occured.

The error was "cannot open source file" and it was pointing on the wrong directory. It is now pointing to the directory of the solution folder completely ignoring the path I defined inside the quotation of the #import.

does anyone know now why it suddenly points on the wrong directory even if I defined the exact directory and filename inside the #import?

I tried creating a new solution but i still encounter the same problem. I am using visual studio 2019. Tried using the 2017 version and i still have the same problem.

[Edit] Additional info: the exe that i am trying to import is located at system32.

VVicera
  • 21
  • 5
  • There is no #import directive in C++. [C++ include and import difference](https://stackoverflow.com/questions/172262/c-include-and-import-difference) – 273K Jul 10 '20 at 03:41
  • it is included here in the microsoft documentation https://learn.microsoft.com/en-us/cpp/preprocessor/hash-import-directive-cpp?view=vs-2019 I am using VS 2019 – VVicera Jul 10 '20 at 03:50
  • 1
    @S.M.: Hence the `visual-studio` tag, I would imagine (see https://learn.microsoft.com/en-us/cpp/preprocessor/hash-import-directive-cpp?view=vs-2019). It's still C++ even if you're discussing extensions, otherwise all those lovely `gcc` extras would be similarly off-topic for the `c++` tag :-) – paxdiablo Jul 10 '20 at 03:50
  • @VVicera What are you trying to "#import"? If it's a C++ (or even C) header file, then it is not `#import` you should be using -- it should be `#include`. That's where the confusion comes in, as you did not specify neither the file name, file type, nor what exactly you need to accomplish using the Microsoft-specific `#import` keyword. – PaulMcKenzie Jul 10 '20 at 04:10
  • Hi @PaulMcKenzie! Im trying to import an exe file. – VVicera Jul 10 '20 at 04:19

1 Answers1

0

From the official documentation, it's clearly written that:

#import "filename" [attributes]

Specifies the type library to import. The filename can be one of the following kinds:

The name of a file that contains a type library, such as an .olb, .tlb, or .dll file. The keyword, file:, can precede each filename.

It doesn't seems you could import an EXE file and the C++ libraries must be included followed by #include:

#include "library/library_file1.h" // access from the current local folder
#include <iostream> // access from the compiler path
Rohan Bari
  • 7,482
  • 3
  • 14
  • 34
  • I was actually able to use the namespace included in the exe. it just suddenly was not able to read the #import. No changes was made on the code. – VVicera Jul 10 '20 at 05:59
  • @VVicera If you had used any source control (like GitHub) the last time, try reverting the changes (save the current changes somewhere else as a backup) and retry. – Rohan Bari Jul 10 '20 at 06:05
  • I tried creating a new solution file with only the #import line, i am still experiencing some error. I am currenlty installing VS to another PC – VVicera Jul 10 '20 at 06:17
  • I suggest you could check the file path is correct. And then you may try to add the complete file path. – Jeaninez - MSFT Jul 10 '20 at 07:18
  • @Jeaninez-MSFT The OP has said [in the comment](https://stackoverflow.com/questions/62826948/import-does-not-follow-the-intended-path-written-inside-the-quotation/62827489?noredirect=1#comment111103980_62827489) that it suddenly happened. – Rohan Bari Jul 10 '20 at 07:23