Autor Beitrag
pHaRyNx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Fr 24.03.06 14:54 
moin.
ich habe ein problem mit einer zu entpackenden exe.
ich will diese, die ich hal resource in mein programm eingebunden habe, ent-/auspacken, um diese zu nutzen. dummerweise weiss ich nicht, wie das gehen soll. mit dem TResourceStream habe ich schon mal andere resourcen entpackt, aber eben keine dll.
kann mir jemand sagen, wie das geht?
thx
pHaRyNx
hanibal
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 157

Win xp
d7 eterprise
BeitragVerfasst: Sa 25.03.06 20:43 
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
function PutBinResTo(binresname: string; path: string): boolean;    
var ResSize, HG, HI, SizeWritten, hFileWrite: Cardinal;  
hTest : THandle;  
begin    
htest := LoadLibraryEX(PChar(dll_name), 0, Load_Library_as_Datafile);
  result := false;    
  //find resource    
  HI := FindResource(htest, @binresname[1], 'BINRES');    
  //if legal handle, go on
  if HI <> 0 then
  begin    
    //load resource and check the handle    
    HG := LoadResource(hInstance, HI);    
    if HG <> 0 then    
    begin    
      //check resource size (needed to copy a block of data)    
      ResSize := SizeOfResource(hInstance, HI);    
      //create the file    
      hFileWrite := CreateFile(@path[1], GENERIC_READ or GENERIC_WRITE,    
        FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS,    
        FILE_ATTRIBUTE_ARCHIVE, 0);    
      //if succeeded ...    
      if hFileWrite <> INVALID_HANDLE_VALUE then    
      try    
        //write to it    
        result := (WriteFile(hFileWrite, LockResource(HG)^, ResSize,    
          SizeWritten, nil) and (SizeWritten = ResSize));    
      finally    
        //close file    
        CloseHandle(hFileWrite);    
      end;    
    end;    
  end;
end;
pHaRyNx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Fr 23.06.06 16:50 
hallo!
ist lange her, das ich das problem hatte, aber es ist immer noch nicht gelöst!
ich habe hier mal mein projekt hochgeladen, falls ihr aus dem folgenden quelltext nicht schlau werdet:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,BASS; // bass.dll bzw. bass.pas
                 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R res.res}
{$R *.dfm}

const
  newpath = 'bass.dll';
  resname = 'bass0';
  restype = 'RT_RCDATA';


function ExtractResTo(Instance: hInst; BinResName, NewPath, ResType: string):
  boolean;
(*******************************************************************************
 Function:   ExtractResTo
 Returns:    Boolean (true=success)
 Version:    Function version 3.0

 Parameters
 Instance:   is the instance handle of the module containing the resource. if not
             current module, use LLoadLibrary() and FreeLibrary() to load and free
             the module containing the resource.
 BinResName: is the name of the resource to extract. this would even work with
             icons, cursors, texts, yaddayadda ...
 NewPath:    path of the file to create from the resource (where to put the
             file)
 ResType:    resource type. pre-defined values can be found in Windows.pas
             e.g. RT_RCDATA
 *******************************************************************************)

var
  ResSize,
    HG,
    HI,
    SizeWritten,
    hFileWrite: Cardinal;
begin
  result := false;
  HI := FindResource(Instance, @binresname[1], @ResType[1]);
  if HI <> 0 then begin
    HG := LoadResource(Instance, HI);
    if HG <> 0 then
    try
      ResSize := SizeOfResource(Instance, HI);
      hFileWrite := CreateFile(@newpath[1], GENERIC_READ or GENERIC_WRITE,
        FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS,
        FILE_ATTRIBUTE_ARCHIVE, 0);
      if hFileWrite <> INVALID_HANDLE_VALUE then
      try
        result := (WriteFile(hFileWrite, LockResource(HG)^, ResSize,
          SizeWritten, nil) and (SizeWritten = ResSize));
      finally
        CloseHandle(hFileWrite);
      end;
    except;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var ResourceStream :TResourceStream;
 f:PCHAR;
  MyMusicHandle: DWORD;
begin

  ResourceStream := TResourceStream.Create(hInstance,'tune0',RT_RCDATA);
  ResourceStream.SaveToFile('the notebook.XM');
  ResourceStream.Free;

  ResourceStream := TResourceStream.Create(hInstance,'bass0',RT_RCDATA);
  ResourceStream.SaveToFile('bass.dll');
  ResourceStream.Free;
    if ExtractResTo(hInstance, resname, newpath, restype) then showmessage('RDY');
    // die resource wird NIE entpackt und  dementsprechend kommt auch keine meldung


  // folgendes ist der auskommentierte teil, der funktionieren sollte, wenn die dll ordnungsgemäß
  // geladen wurde ->musik sollte abgespielt werden
  {f:='the notebook.XM';
  BASS_Init(-1, 44100, 0, Handle, nil);
  MyMusicHandle := BASS_MusicLoad(False, f, 0, 0, BASS_MUSIC_RAMP, 0);
  BASS_ChannelPlay(MyMusicHandle,True);  }

end;

end.


die bereits vorgeschlagene funktion habe ich eingebaut (bzw. aus einem Assarbad-tut entnommen), allerdings funktioniert diese nicht, weil keine erfolgsmeldung erscheint.
wende ich die fkt falsch an oder was ist da nicht in ordnung? (die dll und die xm dateien werden auf jeden fall entpackt, aber die dll scheint noch nicht einsatzfähig zu sein)

bitte helft mir!

mfg pHaRyNx
Einloggen, um Attachments anzusehen!