aF.
aF.

Reputation: 66707

How to use environment variable in #import c++ command?

nowadays I have this piece of code:

#import "C:\Users\Public\SoundLog\DLLs\ForPython\SoundLogDLL.tlb" named_guids

but I want to substitute the C:\Users\Public part by the %PUBLIC% environment variable.

How can I do this ?

Upvotes: 1

Views: 2023

Answers (4)

Aaron Klotz
Aaron Klotz

Reputation: 11585

I think that your best option is to write #import "SoundLogDLL.tlb" named_guids in your code, and then use either the INCLUDE environment variable, the /I command-line switch to the compiler, or the Additional Include Directories IDE option to point the compiler in the right direction.

Upvotes: 2

Zamboni
Zamboni

Reputation: 8043

Using a hard coded path in your code is never a good idea.
I recommend using a relative path and keeping your type library under the same folder structure as your code.

Then doing something like this:
#import <SoundLogDLL.tlb> named_guids

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 942000

It would be wise to store your projects in a common folder so that you can use relative paths. The #import directive also searches files in the same folders where it looks for #include files. In the IDE, you can add them with Project + Properties, C/C++, General, Additional Include Directories.

Upvotes: 1

NG.
NG.

Reputation: 22914

Not sure you can do that. You may either generate the file during a pre compile build step, or you can use the angle include #import <filename> <attrs> and have the location of it in your PATH. See MSDN for more info, specifically Search Order for filename.

Upvotes: 1

Related Questions