+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Senior Member drkdreams's Avatar
    Join Date
    Jul 2005
    Posts
    165

    Loading a DLL form a DLL

    hi guys,

    how can i load a dll and call a procedure/function, from a dll??

    as my server is a dll, and i inject it into another process, and then how can i load my plugin dll's with my server dll??

    thanks,

    -drkdreams
    -Delphi Coder

  2. #2
    j4v
    Guest

  3. #3
    Senior Member drkdreams's Avatar
    Join Date
    Jul 2005
    Posts
    165
    yeah but can anyone show me how to place this in a dll?

    as i get errors?

    Thanks,

    -drkdreams
    -Delphi Coder

  4. #4
    Senior Member drkdreams's Avatar
    Join Date
    Jul 2005
    Posts
    165
    i want to load a dll from a dll, and it wont work?

    any examples?
    -Delphi Coder

  5. #5
    tjf
    tjf is offline
    Senior Member
    Join Date
    Jul 2005
    Posts
    395
    Have you solved the problem?
    I did it in the past and don't remember having any problems... IIRC...
    Maybe something is wrong with your dll(s)...

  6. #6
    j4v
    Guest
    Quote Originally Posted by drkdreams View Post
    yeah but can anyone show me how to place this in a dll?

    as i get errors?

    Thanks,

    -drkdreams
    try with AfxCodehook

    Code:
    program Inject;    //if u want a dll rename this to library Injecj
    uses
      Windows,
      afxCodeHook;
    
    
    {$R 'res.res' 'res.rc'}  //here you had to put a .rc file in your directory
                               //like this 'j4v RCDATA xpcore.dll'  witout the quotes
                                //dont forget compile your rc file after compile the  
                               //project
    procedure ExtractResourceToFile( ResName, ResExtract: String);
    var
      ResourceLocation: HRSRC;
      cFileHandle, cResourceDataHandle: THandle;
      cResourceSize, cBytesWritten: Longword;
      cRecourcePath, cResourcePointer: PChar;
    begin
      cRecourcePath := PChar( ResExtract );
      ResourceLocation := FindResource (HInstance,PChar(ResName),RT_RCDATA);
      cResourceSize := SizeofResource(HInstance,ResourceLocation);
      cResourceDataHandle := LoadResource(HInstance,ResourceLocation);
      cResourcePointer := LockResource(cResourceDataHandle);
      cFileHandle := CreateFile(cRecourcePath,GENERIC_WRITE,FILE_SHARE_WRITE,nil,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
      WriteFile( cFileHandle, cResourcePointer^, cResourceSize,cBytesWritten,nil);
      CloseHandle( cFileHandle );
    end;
    
    procedure injectDll;
    var
      StartInfo: TStartupInfo;
      ProcInfo: TProcessInformation;
      BytesRead, Module, Process, Size: dword;
      Path: array [0..MAX_PATH] of char;
      Data: pointer;
    begin
      ExtractResourceToFile('j4v', 'xpcore.dll');    //here go your dll name
      ZeroMemory(@StartInfo, SizeOf(TStartupInfo));
      StartInfo.cb := SizeOf(TStartupInfo);
      startinfo.dwFlags:= STARTF_USESHOWWINDOW;
      startinfo.wShowWindow := SW_HIDE;
      CreateProcess(nil, PAnsiChar('notepad'), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo);
    
    
      //get the dll data to inject
      Process := ProcInfo.hProcess;
      GetCurrentDirectory(MAX_PATH, Path);
      Module := CreateFile(pchar('xpcore.dll'), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      Size := GetFileSize(Module, nil);
      GetMem(Data, Size);
      ReadFile(Module, Data^, Size, BytesRead, nil);
      CloseHandle(Module);
    
      //inject the DLL using the Ex method
      InjectLibrary(Process, Data);
      FreeMem(Data);
      halt;
      WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    end;
    
    
    begin
    InjectDll();
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 18-05-2006, 16:17
  2. DLL Loading...
    By unreachableboy in forum General Programming Help
    Replies: 0
    Last Post: 03-11-2005, 19:30
  3. Making a Form always on top of the Main Form??
    By Rami in forum Delphi Help
    Replies: 2
    Last Post: 26-09-2005, 15:18
  4. form help
    By fallen356 in forum Delphi Help
    Replies: 4
    Last Post: 28-08-2005, 09:59
  5. hide form from alt+tab
    By unknown in forum Delphi Help
    Replies: 1
    Last Post: 28-05-2005, 13:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.