How to use TARGETDIR in visual c++? - visual-c++

Currently the path inside my code is hardcoded. I want to make it dynamic, base on the users selected installation path.
How can I use TARGETDIR inside my code here:
SHELLEXECUTEINFO info = {0};
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.lpFile = _T("C:\\PROGRA~1\\APPY\\IECapt.exe");
info.lpParameters = full;
info.nShow = SW_HIDE;

TARGETDIR is the path to the directory where you .EXE file is linked. And it's only available at compile time. You want to get the installation directory, so TARGETDIR is not useful.
GetModuleFileName() gives you the path, where your .EXE has been loaded.

This is just a suggestion......
You can use one button and in the OnButonClick() function add the below codes with your other codes..........
CFileDialog m_IDFile(TRUE);
m_IDFile1.m_ofn.lpstrInitialDir=L"C:\\PROGRA~1\\APPY\\";
if(m_IDFile1.DoModal()==IDOK)
m_cFileName=m_IDFile1.GetPathName();
info.lpFile = _T(m_cFileName);

Related

FolderBrowserDialog last Folder Name

I'm new to C++/CLI and have a Question about the FolderBrowserDialog function.
Using ->SelectedPath gives me "C:\Folder\Subfolder\Selected Folder"
How can I save JUST "Selected Folder" to a string?
FolderBrowserDialog^ DestinationFolderDialog;
DestinationFolderDialog = gcnew System::Windows::Forms::FolderBrowserDialog;
System::Windows::Forms::DialogResult result = DestinationFolderDialog->ShowDialog();
if (result == System::Windows::Forms::DialogResult::OK)
{
String^ path = DestinationFolderDialog->SelectedPath;
SetDestinationPath(path);
lblDestinationPath->Text = path;
}
The way I set my Destination Path
And now I want to work with it
String^ pathSource = GetSourcePath();
String^ pathDest = GetDestinationPath();
Im trying to generate Symlinks.
So im Selecting "Y:\Movies\Movie_a" as Source
And im Selecting "X:\" as Destination for my Symlink Folder
To Create it I need to add "Movie_a" to "X:\"
Can someone help me?
If what you want is to extract the last dir name from C:\Folder\Subfolder\Selected Folder then you can:
use Path.GetFileName method to acquire the last part from the path
call String.Split with the Path.PathSeparator and take the last array element
Updated in respect to #LucasTrzesniewski comment

How can I create a setup that installed from command line in install shield 2012

I want to disable the screens in dialog tab, but I also want that the installer doesn't show any screen.
From commandline and install silently.
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "/s /v /qn /min";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.FileName = desktopPath + "\\" + "Tabcontrol.exe";
psi.UseShellExecute = false;
Process.Start(psi);
If you run an installshield setup in silentmode it requires a record file that contains the information the setups needs. It is not really initially silent it's more like unattended and silent.
Here you can find the information how to create this recordfile: http://helpnet.installshield.com/installshield16helplib/CreatetheResponseFile.htm
Here you will find everything you need to know about any unattended/silent setup: http://unattended.sourceforge.net/installers.php

Find path of excel file in dll

I have a dll that needs to open an excel file but i cannot seem to create the path to the file. The excel file is a template that must be used to compare with an excel file that the user will browse for and open.
I have used this code previously when using an exe file for my application:
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Data\\BulkMaintenanceExample.xls");
but with a dll it does not seem to work. Any Ideas?
Try following to get the assembly path:
var dir = AppDomain.CurrentDomain.BaseDirectory;
or
//get the full location of the assembly with DaoTests in it
string fullPath = System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;
string theDirectory = Path.GetDirectoryName( fullPath );
or
string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
return Path.GetDirectoryName(filePath);

How to check a proper file in android phone's memory?

I need a method that downloads a picture and save it in SD card for later use. I got it finally, i just need an operation that checks if the file in already exists or not.
If not, the app will download it. If it is exitsts, my image view will use it.
So my question is just simple:
How to check a file in SD?
If i got this place for example:
String imageInSD = "/sdcard/1.png";
You can use the following code
String sdcardState = android.os.Environment.getExternalStorageState();
String fileName = "yourfilename" + ".png";
if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED))
{
String destPath = android.os.Environment.getExternalStorageDirectory().toString()+ File.separator +fileName;
File output =new File(destPath);
if(output.exists())
\\it exists-use Imageview
else
\\Download the file accordingly
}
else
\\SDCARD not mounted

Setup Project Custom Action in C++ "[TARGETDIR]"

I am trying to copy file into the setup target directory.
I am using this:
TCHAR destPath[ MAX_PATH ] = &L"[TARGETDIR]";
wcscat_s(destPath, L"LiveFo#nextjmp.com\\Capture.png");
CopyFile(L"C:\\Users\\waldek\\Desktop\\Capture.png", destPath, 0);
if I use this:
CopyFile(L"C:\\Users\\waldek\\Desktop\\Capture.png", L"C:\\Program Files (x86)\\Microsoft\\Setup1\\LiveFo#nextjmp.com\\Capture.png", 0);
it works, which is basically what destPath should evaluate to, I can see that it evaluates when I use PMSIHANDLE, it alerts the correct path...
How do I force CopyFile to evalue "[TARGETDIR]";
WCHAR vbuff [MAX_PATH] = {0};
DWORD vlen = MAX_PATH;
UINT gp = MsiGetPropertyW(hInstall, L"CustomActionData", vbuff, &vlen);
in the Install Custom Action in property CustomactionData, I just put [TARGETDIR]
vbuff is the target directory
then of course the concatenation and the FileCopy executed as expected...
this worked for me... but I still would like to know why, it didn't in the original question I posted, the strangest thing was that the PMSIHANDLE wrote out the correct path, but I guess there "translation" step was missing in passing it in the FileCopy function...
I am sure I am missing some theory on this.
Assuming this is part of a custom action, you can use MsiFormatRecord. Error handling omitted, it would look something like this:
PMSIHANDLE hRec = MsiCreateRecord(1);
MsiRecordSetString(hRec, 0, _T("[TARGETDIR]LiveFo#nextjmp.com"));
TCHAR szPath[MAX_PATH] = {0};
DWORD cchPath = MAX_PATH;
MsiFormatRecord(hInstall, hRec, szPath, &cchPath);

Resources