11-15-2016 07:29 AM
Hello,
I would like to create a .txt data in in the user folder on a computer.
Now I would like to create these data on every system I install the application. When I write the normal path in englisch C:\\Users\\Public\\Documents\\..... I can create the .txt on an english system but I would like to create these data also on a german system. But on these system the path would be in german. Is there a way that I must not translate the path and this works automatic. At the moment I write the path direct into the braces of the variable. I hope I could explane the problem good enought.
Best regards
Solved! Go to Solution.
11-15-2016 08:33 AM
Read this discussion:
A better way to get AppData location?
11-15-2016 08:46 AM
I read that article already. I am a little bit lost to this topic.
Where do I get the shell32.lib and how do I add it? (I think it is easy but at the moment I do not know the answer)
Best regards
11-15-2016 10:40 AM
You must install the interface to Win32API (formerly Win SDK): see the discussion linked to understand how to install it (basically you must perform a custom install and select the appropriate module). Be warned that SHGetFolderPath is available in CVI Full release only: if you are running in CVI Base version you cannot access that function. As per the library, depending on the release of CVI you are using it is located in a different folder: see Windows SDK topic in the help (Programmer Reference >> Compiler/Linker Issues >> Calling Windows SDK Functions in LabWindows/CVI)
11-17-2016 07:56 AM
Now I have some more questions.
I do not understand the installation you mentioned. Is the Win32API already on my system?
So I must install this data, then I have the library and I can integrate it into my project or do you mean that I must integrade it in my project like .fp data?
Is there a easier way to built my path to the user folder for different systems?
I read about some option for microsoft batch programing that they use something like this in the path %%User%% and so it finds alway the user folder.
Best regards
11-17-2016 10:22 AM
Windows SDK is not installed by default together with CVI: you must explicitly perform a custom setup and add it to the features to install. See this post from Luis G.
In the Help menu there is a 'Windows SDK' item: I suppose it is grayed out if the SDK is not installed or you receive an error in that case.
Once you have the SDK installed, simply add the library to the project, #include windows.h and set the version marcro as explained some post after the one I linked.
11-21-2016 02:51 AM - edited 11-21-2016 02:52 AM
Thank you your help. I have found a easier method to solve the problem. In C there is the command getenv. With this command you can also search für the APPDATA and then return the path. You can use the parameter (ALLUSERSPROFILE, APPDATA,.....) like in the section "Default Values" on this side "https://en.wikipedia.org/wiki/Environment_variable" and get always the path you want without the Windows SDK. The rest of the program is to create a directory and copy the strings, create the .txt or what else....and so on. You get always the correct path on various windows systems.
#include "stdafx.h"
#include <stdio.h> /* printf */
#include <stdlib.h> /* getenv */
int _tmain(int argc, _TCHAR* argv[])
{
char* pPath;
pPath = getenv ("APPDATA");
printf("Current Path: %s\n", pPath);
return 0;
}
Best regards