How to use environment variable in #import c++ command?
nowadays I have this piece of code:
#import "C:\Users\Public\SoundLog\DLLs\ForP开发者_如何学Cython\SoundLogDLL.tlb" named_guids
but I want to substitute the C:\Users\Public part by the %PUBLIC% environment variable.
How can I do this ?
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.
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.
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.
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
精彩评论