how to copy file to another path in dll?
<p>I am trying to copy a file from a specific path to another.</p>

<p>The path that I targeted is <code>CSIDL_COMMON_APPDATA</code>, which is Program Data, so I tried:</p>

<pre><code>CopyFile(PChar(AppFolder +'\needed.dll'), PChar(anotherfolder+'\needed.dll'), False);
</code></pre>

<p>but it doesn't copy anything to the target path.</p>

<p>So I deiced to test the code inside an EXE application and it copies the file normally. What could be the problem? Why I am unable to copy files from a DLL?</p>

<p>Here is my <code>Appfolder</code> path:</p>

<pre><code>function GetSpecialFolder(const CSIDL : integer) : String;
var
  RecPath : PWideChar;
begin
  RecPath := StrAlloc(MAX_PATH);
  try
    FillChar(RecPath^,MAX_PATH,0);
    if SHGetSpecialFolderPath(0,RecPath,CSIDL,false) then begin
      Result := RecPath;
    end else Result := '';
  finally
    StrDispose(RecPath);
  end;
end;

function AnotherFolder: string;
begin
  if IsWindowsVistaOrGreater then
  begin
    Result := GetSpecialFolder(CSIDL_COMMON_APPDATA)+'\applocation';
  end;
end;

function AppFolder: string;
begin
  if IsWindowsVistaOrGreater then
  begin
    Result := GetSpecialFolder(CSIDL_INTERNET_CACHE)+'\Low\applocation';
  end else
    Result := GetSpecialFolder(CSIDL_COMMON_APPDATA)+'\application';
    //Result := ExtractFilePath(Application.ExeName);
end;
</code></pre>

<p>Adding Actual code </p>

<pre><code>// dll form

function GetSpecialFolder(const CSIDL: integer): String;
var
  RecPath: PWideChar;
begin
  RecPath := StrAlloc(MAX_PATH);
  try
    FillChar(RecPath^, MAX_PATH, 0);
    if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) then
    begin
      Result := RecPath;
    end
    else
      Result := '';
  finally
    StrDispose(RecPath);
  end;
end;

function AnotherFolder: string;
begin
  // Vista check removed
  Result := GetSpecialFolder(CSIDL_COMMON_APPDATA) + '\applocation';
end;

function AppFolder: string;
begin
  if IsWindowsVistaOrGreater then
  begin
    Result := GetSpecialFolder(CSIDL_INTERNET_CACHE) + '\Low\applocation';
  end
  else
    Result := GetSpecialFolder(CSIDL_COMMON_APPDATA) + '\application';
  // Result := ExtractFilePath(Application.ExeName);
end;

procedure Tform1.FormShow(Sender: TObject);
begin
  if IsWindowsVistaOrGreater then
  begin
    CopyFile(PChar(AppFolder + '\needed.dll'), PChar(AnotherFolder + '\needed.dll'), false);
    memo1.Lines.Add('Value : ' + IntTostr(GetLastError()));
  end;
end;
</code></pre>

<p>my dll only have  1 form that when its shows it show  copy file from location to another .</p>

<p>manifest file </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;

&lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt;
  &lt;assemblyIdentity
    type="win32"
    name="DelphiApplication"
    version="1.0.0.0" 
    processorArchitecture="*"/&gt;
  &lt;dependency&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/&gt;
    &lt;/dependentAssembly&gt;
  &lt;/dependency&gt;
&lt;/assembly&gt;
</code></pre>

<p>project dll source </p>

<pre><code>{$R apploadform.res' apploadform.rc'}
</code></pre>